Commit 75236079c0b50ee24defebe1509f537bae91aefe

Stefan Sperling 2020-03-25T14:30:15

handle refs/remotes/origin/HEAD properly; reported by Matthias aka _xhr_

diff --git a/lib/reference.c b/lib/reference.c
index f74cc9e..0355087 100644
--- a/lib/reference.c
+++ b/lib/reference.c
@@ -401,7 +401,7 @@ open_ref(struct got_reference **ref, const char *path_refs, const char *subdir,
 	char *path = NULL;
 	char *absname = NULL;
 	int ref_is_absolute = (strncmp(name, "refs/", 5) == 0);
-	int ref_is_well_known = is_well_known_ref(name);
+	int ref_is_well_known = (subdir[0] == '\0' && is_well_known_ref(name));
 
 	*ref = NULL;
 
diff --git a/regress/cmdline/ref.sh b/regress/cmdline/ref.sh
index 8457642..94ee8da 100755
--- a/regress/cmdline/ref.sh
+++ b/regress/cmdline/ref.sh
@@ -274,12 +274,23 @@ function test_ref_list {
 		return 1
 	fi
 
+	# Create a HEAD ref in the namespace of a remote repository
+	(cd $testroot/repo && got ref -s refs/heads/master \
+		refs/remotes/origin/HEAD)
+	ret="$?"
+	if [ "$ret" != "0" ]; then
+		test_done "$testroot" "$ret"
+		return 1
+	fi
+
 	got ref -r $testroot/repo -l > $testroot/stdout
 
 	echo "HEAD: refs/heads/master" > $testroot/stdout.expected
 	echo "refs/foo/bar/baz: $commit_id" >> $testroot/stdout.expected
 	echo "refs/foo/zoo: $commit_id" >> $testroot/stdout.expected
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/heads/master" \
+		>> $testroot/stdout.expected
 	echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
 	cmp -s $testroot/stdout $testroot/stdout.expected
 	ret="$?"
@@ -294,6 +305,8 @@ function test_ref_list {
 	echo "refs/foo/bar/baz: $commit_id" > $testroot/stdout.expected
 	echo "refs/foo/zoo: $commit_id" >> $testroot/stdout.expected
 	echo "refs/heads/master: $commit_id" >> $testroot/stdout.expected
+	echo "refs/remotes/origin/HEAD: refs/heads/master" \
+		>> $testroot/stdout.expected
 	echo "refs/tags/1.0: $tag_id" >> $testroot/stdout.expected
 	cmp -s $testroot/stdout $testroot/stdout.expected
 	ret="$?"