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

[PATCH 4/6] check_filename(): handle ":^" path magic

From
Jeff King <peff@peff.net>
Date
May 26, 2017, 19:08 UTC
Message-ID
<20170526190839.773oeulwzxnl3x3n@sigill.intra.peff.net>
In-Reply-To
<20170526190607.jr44oygs6mzm3q6e@sigill.intra.peff.net>

We special-case "git log :/foo" to work when "foo" exists in the working tree. But :^ (and its alias :!) do not get the same treatment, requiring the user to supply a disambiguating "--". Let's make them work without requiring the user to type the "--".

Signed-off-by: Jeff King <peff@peff.net>
---
 setup.c                       |  4 ++++
 t/t4208-log-magic-pathspec.sh | 13 +++++++++++++
 2 files changed, 17 insertions(+)
diff --git a/setup.c b/setup.c
index f2a8070bd..86bb7c9a9 100644
--- a/setup.c
+++ b/setup.c
@@ -141,6 +141,10 @@ int check_filename(const char *prefix, const char *arg)
 		if (!*arg) /* ":/" is root dir, always exists */
 			return 1;
 		prefix = NULL;
+	} else if (skip_prefix(arg, ":!", &arg) ||
+		   skip_prefix(arg, ":^", &arg)) {
+		if (!*arg) /* excluding everything is silly, but allowed */
+			return 1;
 	}
 
 	if (prefix)
diff --git a/t/t4208-log-magic-pathspec.sh b/t/t4208-log-magic-pathspec.sh
index 70bc64100..67250ebdc 100755
--- a/t/t4208-log-magic-pathspec.sh
+++ b/t/t4208-log-magic-pathspec.sh
@@ -52,6 +52,19 @@ test_expect_success 'git log HEAD -- :/' '
 	test_cmp expected actual
 '
 
+test_expect_success '"git log :^sub" is not ambiguous' '
+	git log :^sub
+'
+
+test_expect_success '"git log :^does-not-exist" does not match anything' '
+	test_must_fail git log :^does-not-exist
+'
+
+test_expect_success  '"git log :!" behaves the same as :^' '
+	git log :!sub &&
+	test_must_fail git log :!does-not-exist
+'
+
 test_expect_success 'command line pathspec parsing for "git log"' '
 	git reset --hard &&
 	>a &&
-- 
2.13.0.496.ge44ba89db
Previous: Jeff KingNext: Jeff King
Message 8 of 13 in “recognize pathspec magic without "--" disambiguation”
  1. recognize pathspec magic without "--" disambiguationJeff King, May 25, 2017
  2. Junio C HamanoMay 26, 2017
  3. Jeff KingMay 26, 2017
  4. 0/6 make "^:foo" work without disambiguating "--"Jeff King, May 26, 2017
  5. 1/6 t4208: add check for ":/" without matching fileJeff King, May 26, 2017
  6. 3/6 check_filename(): use skip_prefixJeff King, May 26, 2017
  7. 2/6 check_filename(): refactor ":/" handlingJeff King, May 26, 2017
  8. 4/6 check_filename(): handle ":^" path magicJeff King, May 26, 2017
  9. 6/6 verify_filename(): flip order of checksJeff King, May 26, 2017
  10. 5/6 verify_filename(): treat ":(magic)" as a pathspecJeff King, May 26, 2017
  11. Ævar Arnfjörð BjarmasonMay 27, 2017
  12. Jeff KingMay 27, 2017
  13. Junio C HamanoMay 28, 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.