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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 16, 2025 at 4:02 AM brian m. carlson
<sandals@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> 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

> > +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

> 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





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux