show-ref: accept HEAD with --verify

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>

Vladimir Panteleev committed Jan 23, 2017 at 18:00 UTC ec7c51bc6bda0a836b4955962becedbb702bbc43
2 files changed +12 -1
builtin/show-ref.c
+1 -1
@@ -202,7 +202,7 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
202 while (*pattern) {
203 struct object_id oid;
204
205 - if (starts_with(*pattern, "refs/") &&
205 + if ((starts_with(*pattern, "refs/") || !strcmp(*pattern, "HEAD")) &&
206 !read_ref(*pattern, oid.hash)) {
207 if (!quiet)
208 show_one(*pattern, &oid);
t/t1403-show-ref.sh
+11
@@ -164,4 +164,15 @@ test_expect_success 'show-ref --heads, --tags, --head, pattern' '
164 test_cmp expect actual
165 '
166
167 +test_expect_success 'show-ref --verify HEAD' '
168 + echo $(git rev-parse HEAD) HEAD >expect &&
169 + git show-ref --verify HEAD >actual &&
170 + test_cmp expect actual &&
171 +
172 + >expect &&
173 +
174 + git show-ref --verify -q HEAD >actual &&
175 + test_cmp expect actual
176 +'
177 +
178 test_done