show-ref: accept HEAD with --verify
authorVladimir Panteleev <git@thecybershadow.net>
Mon, 23 Jan 2017 18:00:55 +0000 (18:00 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 23 Jan 2017 20:06:29 +0000 (12:06 -0800)
Previously, when --verify was specified, show-ref would use a separate
code path which did not handle HEAD and treated it as an invalid
ref. Thus, "git show-ref --verify HEAD" (where "--verify" is used
because the user is not interested in seeing refs/remotes/origin/HEAD)
did not work as expected.

Instead of insisting that the input begins with "refs/", allow "HEAD"
as well in the codepath that handles "--verify", so that all valid
full refnames including HEAD are passed to the same output machinery.

Signed-off-by: Vladimir Panteleev <git@thecybershadow.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/show-ref.c
t/t1403-show-ref.sh
index 6d4e669002b1e58ebf40af5543221d809ffd0427..0e53e3da4f19f0710de9d01d2bcb3e7c1883ee52 100644 (file)
@@ -202,7 +202,7 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
                while (*pattern) {
                        struct object_id oid;
 
-                       if (starts_with(*pattern, "refs/") &&
+                       if ((starts_with(*pattern, "refs/") || !strcmp(*pattern, "HEAD")) &&
                            !read_ref(*pattern, oid.hash)) {
                                if (!quiet)
                                        show_one(*pattern, &oid);
index 7e10bcfe395609cff5edc1f8f6ce95fcf69cf5f6..5932beada145c5f5ee41fac47e72d707e84d6f15 100755 (executable)
@@ -164,4 +164,15 @@ test_expect_success 'show-ref --heads, --tags, --head, pattern' '
        test_cmp expect actual
 '
 
+test_expect_success 'show-ref --verify HEAD' '
+       echo $(git rev-parse HEAD) HEAD >expect &&
+       git show-ref --verify HEAD >actual &&
+       test_cmp expect actual &&
+
+       >expect &&
+
+       git show-ref --verify -q HEAD >actual &&
+       test_cmp expect actual
+'
+
 test_done