Commit c191ed664f6c437ebc3e0c859c53e48b445401f1

Stefan Sperling 2019-05-13T17:08:16

allow single-component reference names with got_ref_alloc()

diff --git a/lib/reference.c b/lib/reference.c
index c2d7153..240d979 100644
--- a/lib/reference.c
+++ b/lib/reference.c
@@ -290,10 +290,19 @@ const struct got_error *
 got_ref_alloc(struct got_reference **ref, const char *name,
     struct got_object_id *id)
 {
-	if (!is_valid_ref_name(name))
-		return got_error(GOT_ERR_BAD_REF_NAME);
+	const struct got_error *err;
+	char *absname = NULL;
+
+	if (!is_valid_ref_name(name)) {
+		if (strchr(name, '/') != NULL)
+			return got_error(GOT_ERR_BAD_REF_NAME);
+		if (asprintf(&absname, "refs/heads/%s", name) == -1)
+			return got_error_from_errno("asprintf");
+	}
 
-	return alloc_ref(ref, name, id, 0);
+	err = alloc_ref(ref, absname ? absname : name, id, 0);
+	free(absname);
+	return err;
 }
 
 static const struct got_error *