git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] show-ref: Allow --head to work with --verify
@ 2017-01-20 15:50 Vladimir Panteleev
  2017-01-20 19:03 ` Junio C Hamano
  0 siblings, 1 reply; 11+ messages in thread
From: Vladimir Panteleev @ 2017-01-20 15:50 UTC (permalink / raw)
  To: git; +Cc: Vladimir Panteleev

Previously, when --verify was specified, --head was being ignored, and
"show-ref --verify --head HEAD" would always print "fatal: 'HEAD' -
not a valid ref". As such, when using show-ref to look up any
ref (including HEAD) precisely by name, one would have to special-case
looking up the HEAD ref.

This patch adds --head support to show-ref's --verify logic, by
explicitly checking if the "HEAD" ref is specified when --head is
present.

Signed-off-by: Vladimir Panteleev <git@thecybershadow.net>
---
 builtin/show-ref.c  | 2 ++
 t/t1403-show-ref.sh | 8 ++++++++
 2 files changed, 10 insertions(+)

diff --git a/builtin/show-ref.c b/builtin/show-ref.c
index 6d4e66900..ee5078604 100644
--- a/builtin/show-ref.c
+++ b/builtin/show-ref.c
@@ -207,6 +207,8 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
 				if (!quiet)
 					show_one(*pattern, &oid);
 			}
+			else if (show_head && !strcmp(*pattern, "HEAD"))
+				head_ref(show_ref, NULL);
 			else if (!quiet)
 				die("'%s' - not a valid ref", *pattern);
 			else
diff --git a/t/t1403-show-ref.sh b/t/t1403-show-ref.sh
index 7e10bcfe3..de64ebfb7 100755
--- a/t/t1403-show-ref.sh
+++ b/t/t1403-show-ref.sh
@@ -164,4 +164,12 @@ 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 HEAD >actual &&
+	test_cmp expect actual
+'
+
 test_done
-- 
2.11.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2017-01-21  0:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-20 15:50 [PATCH] show-ref: Allow --head to work with --verify Vladimir Panteleev
2017-01-20 19:03 ` Junio C Hamano
2017-01-20 20:26   ` Vladimir Panteleev
2017-01-20 20:51     ` Vladimir Panteleev
2017-01-20 22:22     ` Junio C Hamano
2017-01-20 22:31       ` Junio C Hamano
2017-01-20 23:15       ` Junio C Hamano
2017-01-20 22:55   ` Vladimir Panteleev
2017-01-20 23:20     ` Junio C Hamano
2017-01-20 23:29       ` Junio C Hamano
2017-01-21  0:25         ` Vladimir Panteleev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).