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

[PATCH v2] Add tests for wildcard "path vs ref" disambiguation

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jul 1, 2015, 11:08 UTC
Message-ID
<1435748894-4636-1-git-send-email-pclouds@gmail.com>
In-Reply-To
<1435668007-31231-1-git-send-email-pclouds@gmail.com>

Commit 28fcc0b (pathspec: avoid the need of "--" when wildcard is used - 2015-05-02) changes how the disambiguation rules work. This patch adds some tests to demonstrate, basically, if wildcard characters are in an argument:

 - if the argument is valid extended sha-1 syntax, "--" must be used
 - otherwise the argument is considered a path, even without "--"

And wildcard can appear in extended sha-1 syntax, either as part of regex in ":/<regex>" or as the literal path in ":<path>". The latter case is less likely to happen in real world. But if you do ":/" a lot, you may need to type "--" more.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 v2 just adds tests as the code is already in 'master' for some time.
 t/t2019-checkout-ambiguous-ref.sh | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
diff --git a/t/t2019-checkout-ambiguous-ref.sh b/t/t2019-checkout-ambiguous-ref.sh
index b99d519..e5ceba3 100755
--- a/t/t2019-checkout-ambiguous-ref.sh
+++ b/t/t2019-checkout-ambiguous-ref.sh
@@ -56,4 +56,30 @@ test_expect_success VAGUENESS_SUCCESS 'checkout reports switch to branch' '
 	test_i18ngrep ! "^HEAD is now at" stderr
 '
 
+test_expect_success 'wildcard ambiguation, paths win' '
+	git init ambi &&
+	(
+		cd ambi &&
+		echo a >a.c &&
+		git add a.c &&
+		echo b >a.c &&
+		git checkout "*.c" &&
+		echo a >expect &&
+		test_cmp expect a.c
+	)
+'
+
+test_expect_success 'wildcard ambiguation, refs lose' '
+	git init ambi2 &&
+	(
+		cd ambi2 &&
+		echo a >"*.c" &&
+		git add . &&
+		test_must_fail git show :"*.c" &&
+		git show :"*.c" -- >actual &&
+		echo a >expect &&
+		test_cmp expect actual
+	)
+'
+
 test_done
-- 
2.3.0.rc1.137.g477eb31
Previous: Duy NguyenNext: Junio C Hamano
Message 4 of 5 in “Avoid the need of "--" when wildcard pathspec is used”
  1. Avoid the need of "--" when wildcard pathspec is usedNguyễn Thái Ngọc Duy, Jun 30, 2015
  2. Junio C HamanoJun 30, 2015
  3. Duy NguyenJun 30, 2015
  4. Add tests for wildcard "path vs ref" disambiguationNguyễn Thái Ngọc Duy, Jul 1, 2015
  5. Junio C HamanoJul 1, 2015

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.