handle refs/remotes/origin/HEAD properly; reported by Matthias aka _xhr_
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
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="$?"