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

[PATCH] t3706: Add test for wildcard vs literal pathspec

From
K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
Date
Apr 12, 2025, 17:40 UTC
Message-ID
<20250412174051.780148-1-jayatheerthkulkarni2005@gmail.com>
In-Reply-To
<20250412094607.236382-2-jayatheerthkulkarni2005@gmail.com>

When 'git add <pattern>' is run, and a file exists whose literal name matches <pattern> (e.g., a file named "f*" when running 'git add f*'), Git should treat the pattern as a wildcard matching multiple files, rather than just adding the literal file.

Add a test case that:
 1. Creates files 'f*', 'f**', and 'foo'.
 2. Verifies that 'git add "f\*\*"'
    correctly adds only the literal file 'f**'.
 3. Verifies that 'git add 'f*'' (quoted to prevent shell expansion)
    correctly adds 'f*', 'f**', and 'foo' by treating 'f*' as a
    wildcard.
Covering these the test adds 5 cases.
Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
---
 t/meson.build                   |  1 +
 t/t3706-add-wildcard-literal.sh | 44 +++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)
 create mode 100755 t/t3706-add-wildcard-literal.sh
diff --git a/t/meson.build b/t/meson.build
index 8b3aed14ea..e9cd9da8a2 100644
--- a/t/meson.build
+++ b/t/meson.build
@@ -417,6 +417,7 @@ integration_tests = [
   't3703-add-magic-pathspec.sh',
   't3704-add-pathspec-file.sh',
   't3705-add-sparse-checkout.sh',
+  't3706-add-wildcard-literal.sh',
   't3800-mktag.sh',
   't3900-i18n-commit.sh',
   't3901-i18n-patch.sh',
diff --git a/t/t3706-add-wildcard-literal.sh b/t/t3706-add-wildcard-literal.sh
new file mode 100755
index 0000000000..0fc27b28ac
--- /dev/null
+++ b/t/t3706-add-wildcard-literal.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+
+test_description='git add: wildcard must not be shadowed by literal filename'
+
+. ./test-lib.sh
+
+test_expect_success 'setup: create files and initial commit' '
+    mkdir testdir &&
+    >testdir/f\* &&
+    >testdir/f\*\* &&
+    >testdir/foo &&
+    git add testdir &&
+    git commit -m "Initial setup with literal wildcard files"
+'
+
+test_expect_success 'clean slate before testing wildcard behavior' '
+    git rm -rf testdir &&
+    git commit -m "Clean state"
+'
+
+test_expect_success 'recreate files to test add behavior' '
+    mkdir testdir &&
+    >testdir/f\* &&
+    >testdir/f\*\* &&
+    >testdir/foo
+'
+
+test_expect_success 'quoted literal: git add "f\\*\\*" adds only f**' '
+    git reset &&
+    git add "testdir/f\\*\\*" &&
+    git ls-files >actual &&
+    echo "testdir/f**" >expected &&
+    test_cmp expected actual
+'
+
+test_expect_success 'wildcard: git add f* adds f*, f** and foo' '
+    git reset &&
+    git add '\''testdir/f*'\'' &&
+    git ls-files | sort >actual &&
+    printf "%s\n" "testdir/f*" "testdir/f**" "testdir/foo" | sort >expected &&
+    test_cmp expected actual
+'
+
+test_done
\ No newline at end of file
-- 
2.49.0
Previous: K JayatheerthNext: Lucas Seiki Oshiro
Message 3 of 19 in “add: fix pathspec handling when literal filenames match wildcard”
  1. 0/1 add: fix pathspec handling when literal filenames match wildcardK Jayatheerth, Apr 12, 2025
  2. 1/1 add: fix handling literal filenames and wildcardsK Jayatheerth, Apr 12, 2025
  3. t3706: Add test for wildcard vs literal pathspecK Jayatheerth, Apr 12, 2025
  4. Lucas Seiki OshiroApr 14, 2025
  5. JAYATHEERTH KApr 14, 2025
  6. Junio C HamanoApr 14, 2025
  7. brian m. carlsonApr 15, 2025
  8. JAYATHEERTH KApr 16, 2025
  9. Junio C HamanoApr 16, 2025
  10. JAYATHEERTH KApr 16, 2025
  11. Lucas Seiki OshiroApr 16, 2025
  12. Junio C HamanoApr 16, 2025
  13. JAYATHEERTH KApr 19, 2025
  14. Lucas Seiki OshiroApr 19, 2025
  15. JAYATHEERTH KApr 22, 2025
  16. JAYATHEERTH KApr 16, 2025
  17. JAYATHEERTH KApr 16, 2025
  18. Lucas Seiki OshiroApr 12, 2025
  19. JAYATHEERTH KApr 12, 2025

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.