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

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

From
JAYATHEERTH K <jayatheerthkulkarni2005@gmail.com>
Date
Apr 16, 2025, 01:56 UTC
Message-ID
<CA+rGoLfAidyuomeNym5WX8Bo7-jPcfHx35wDeZ7W2aorAN-B7g@mail.gmail.com>
In-Reply-To
<Z_7ekhsBzXK6LKuV@tapette.crustytoothpaste.net>

On Wed, Apr 16, 2025 at 4:02 AM brian m. carlson <sandals@crustytoothpaste.net> wrote:

Show 14 quoted lines
>
> On 2025-04-12 at 17:40:51, K Jayatheerth wrote:
> > +test_expect_success 'recreate files to test add behavior' '
> > +    mkdir testdir &&
> > +    >testdir/f\* &&
> > +    >testdir/f\*\* &&
>
> I just want to point out that creating files with asterisks may not be
> possible on Windows due to limitations in the file system.  I'm not a
> Windows expert, so unfortunately I can't provide more details than that,
> but you may end up needing to add a prerequisite here to skip this on
> our Windows platforms if necessary.  Hopefully CI and a suitable search
> can help you figure it out.
>
Ok I will look into it, thank you for letting me know
Show 9 quoted lines
> > +test_done
> > \ No newline at end of file
>
> We do want to keep newlines at the end of a file.  POSIX mandates one on
> text files and some systems are less tolerant of missing newlines than
> others.  Usually Linux and the BSDs handle this just fine, but some
> proprietary Unix systems, which unfortunately we don't have CI for, tend
> to be the ones that are less happy about this.
>
Ok I will make sure of that
Show 5 quoted lines
> I haven't given this a full review, since others have done that instead,
> but just pointed out one or two things that got my attention.
> --
> brian m. carlson (they/them)
> Toronto, Ontario, CA
While I was looking into the reviews I was creating various test cases
with these files
'*'  '**'  '?'  '\*'  '[abc]'   commit_files  'f*'  'f**'  'file[1-3]'
 'foo*bar'  'f?z'  'hello?world'

Everything went correct But when I checked \* and which is used for getting * as specific but there is also a literal \* in the above files

So it still adds both, I'm unsure if that is the intended behaviour.

but when I say git add "\*" it adds both the files * and \* But rest of the other wildcards and literals work as intended which is why I incorporated the \* literal

I also think I will still divide the test file because git add isn't the only one that looks into wildcards and pathspec

I think something like git commit "*" -m "Test" also would be a great test
or even git rm command.

About the windows question, I think I will see if there is any common ground I could find But until then I think prereq is a great option.

For reference my test file looks something like this,
--- /dev/null
+++ b/t/t6137-pathspec-wildcard-literal.sh
@@ -0,0 +1,139 @@
+#!/bin/sh
+
+test_description='test wildcards and literals with various git commands'
+
+. ./test-lib.sh
+
+reset_git_repo () {
+ rm -rf .git &&
+ git init
+}
+
+test_expect_success 'setup' '
+ mkdir testdir &&
+ cd testdir &&
+ touch "*" "?" "[abc]" "f*" "f?z" "a" &&
+ touch "**" "foo*bar" "hello?world" "f**" "hello_world" &&
+ git init
+'
+
+test_expect_success 'check * wildcard in git add' '
+ git init &&
+ git add "*" &&
+ cat >expected_files <<EOF &&
+*
+**
+?
+[abc]
+a
+f*
+f**
+f?z
+foo*bar
+hello?world
+hello_world
+EOF
+ git ls-files >actual_files &&
+ test_cmp expected_files actual_files
+'
+
+test_expect_success 'check \* literal in git add' '
+ reset_git_repo &&
+ git add "\*" &&
+ cat >expected_files <<EOF &&
+*
+EOF
+ git ls-files >actual_files &&
+ test_cmp expected_files actual_files
+'
+
+test_expect_success 'check f* wildcard in git add' '
+ reset_git_repo &&
+ git add "f*" &&
+ cat >expected_files <<EOF &&
+f*
+f**
+f?z
+foo*bar
+EOF
+ git ls-files >actual_files &&
+ test_cmp expected_files actual_files
+'
+
+test_expect_success 'check f\* literal in git add' '
+ reset_git_repo &&
+ git add "f\*" &&
+ cat >expected_files <<EOF &&
+f*
+EOF
+ git ls-files >actual_files &&
+ test_cmp expected_files actual_files
+'
+
+test_expect_success 'check f** wildcard in git add' '
+ reset_git_repo &&
+ git add "f**" &&
+ cat >expected_files <<EOF &&
+f*
+f**
+f?z
+foo*bar
+EOF
+ git ls-files >actual_files &&
+ test_cmp expected_files actual_files
+'
+
+test_expect_success 'check f\*\* literal in git add' '
+ reset_git_repo &&
+ git add "f\*\*" &&
+ cat >expected_files <<EOF &&
+f**
+EOF
+ git ls-files >actual_files &&
+ test_cmp expected_files actual_files
+'
+
+test_expect_success 'check ? wildcard in git add' '
+ reset_git_repo &&
+ git add "?" &&
+ cat >expected_files <<EOF &&
+*
+?
+a
+EOF
+ git ls-files >actual_files &&
+ test_cmp expected_files actual_files
+'
+
+test_expect_success 'check \? literal in git add' '
+ reset_git_repo &&
+ git add "\?" &&
+ cat >expected_files <<EOF &&
+?
+EOF
+ git ls-files >actual_files &&
+ test_cmp expected_files actual_files
+'
+
+test_expect_success 'check hello?world wildcard in git add' '
+ reset_git_repo &&
+ git add "hello?world" &&
+ cat >expected_files <<EOF &&
+hello?world
+hello_world
+EOF
+ git ls-files >actual_files &&
+ test_cmp expected_files actual_files
+'
+
+test_expect_success 'check hello\?world literal in git add' '
+ reset_git_repo &&
+ git add "hello\?world" &&
+ cat >expected_files <<EOF &&
+hello?world
+EOF
+ git ls-files >actual_files &&
+ test_cmp expected_files actual_files
+'
+
+test_done
-- 
2.49.GIT
Previous: brian m. carlsonNext: Junio C Hamano
Message 8 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.