All of lore.kernel.org
 help / color / mirror / Atom feed
From: K Jayatheerth <jayatheerthkulkarni2005@gmail.com>
To: jayatheerthkulkarni2005@gmail.com
Cc: git@vger.kernel.org, peff@peff.net, piotrsiupa@gmail.com
Subject: [PATCH] t3706: Add test for wildcard vs literal pathspec
Date: Sat, 12 Apr 2025 23:10:51 +0530	[thread overview]
Message-ID: <20250412174051.780148-1-jayatheerthkulkarni2005@gmail.com> (raw)
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


  reply	other threads:[~2025-04-12 17:41 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-12  9:46 [PATCH 0/1] add: fix pathspec handling when literal filenames match wildcard K Jayatheerth
2025-04-12  9:46 ` [PATCH 1/1] add: fix handling literal filenames and wildcards K Jayatheerth
2025-04-12 17:40   ` K Jayatheerth [this message]
2025-04-14 16:51     ` [PATCH] t3706: Add test for wildcard vs literal pathspec Lucas Seiki Oshiro
2025-04-14 17:08       ` JAYATHEERTH K
2025-04-14 21:42     ` Junio C Hamano
2025-04-15 22:32     ` brian m. carlson
2025-04-16  1:56       ` JAYATHEERTH K
2025-04-16 13:11         ` Junio C Hamano
2025-04-16 14:49           ` JAYATHEERTH K
2025-04-16 15:49             ` Lucas Seiki Oshiro
2025-04-16 16:00               ` Junio C Hamano
2025-04-19  4:59                 ` JAYATHEERTH K
2025-04-19 17:43                   ` Lucas Seiki Oshiro
2025-04-22 11:57                     ` JAYATHEERTH K
2025-04-16 16:40               ` JAYATHEERTH K
2025-04-16 16:43                 ` JAYATHEERTH K
2025-04-12 15:45 ` [PATCH 0/1] add: fix pathspec handling when literal filenames match wildcard Lucas Seiki Oshiro
2025-04-12 17:34   ` JAYATHEERTH K

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250412174051.780148-1-jayatheerthkulkarni2005@gmail.com \
    --to=jayatheerthkulkarni2005@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=piotrsiupa@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.