git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] show-ref: Allow --head to work with --verify

From
Vladimir Panteleev <git@thecybershadow.net>
Date
Jan 20, 2017, 15:50 UTC
Message-ID
<20170120155015.4360-1-git@thecybershadow.net>

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
Next: Junio C Hamano
Message 1 of 11 in “show-ref: Allow --head to work with --verify”
  1. show-ref: Allow --head to work with --verifyVladimir Panteleev, Jan 20, 2017
  2. Junio C HamanoJan 20, 2017
  3. Vladimir PanteleevJan 20, 2017
  4. Vladimir PanteleevJan 20, 2017
  5. Junio C HamanoJan 20, 2017
  6. Junio C HamanoJan 20, 2017
  7. Junio C HamanoJan 20, 2017
  8. Vladimir PanteleevJan 20, 2017
  9. Junio C HamanoJan 20, 2017
  10. Junio C HamanoJan 20, 2017
  11. Vladimir PanteleevJan 21, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.