threads / bug / 45692

[BUG] ls-files '**' globstar matches one or more directories instead of zero or more directories

Subject: [BUG] ls-files '**' globstar matches one or more directories instead of zero or more directories

## tl;dr

5 messages between Apr 14, 2017 and Apr 16, 2017.

replies: 4people: 2as markdown or json

Alistair Buxton· Apr 14, 2017, 19:17 UTC · lore
To reproduce, go to any git repository and run:
    diff <(git ls-files '**/*' | sort) <(git ls-files | sort)
Expected result: No output since both commands should produce identical output.
Actual result: '**/*' only matches files at least one directory deep.

The same happens with eg '**/Makefile' - only Makefiles in subdirectories are listed.

I have personally tested with 2.7.8 and 2.12.0. Others on IRC report that this happens in the next branch.

-- 
Alistair Buxton
a.j.buxton@gmail.com
Duy Nguyen· Apr 16, 2017, 10:53 UTC · re: Alistair Buxton · lore

Re: [BUG] ls-files '**' globstar matches one or more directories instead of zero or more directories

On Sat, Apr 15, 2017 at 2:17 AM, Alistair Buxton <a.j.buxton@gmail.com> wrote:
Show 13 quoted lines
> To reproduce, go to any git repository and run:
>
>     diff <(git ls-files '**/*' | sort) <(git ls-files | sort)
>
> Expected result: No output since both commands should produce identical output.
>
> Actual result: '**/*' only matches files at least one directory deep.
>
> The same happens with eg '**/Makefile' - only Makefiles in
> subdirectories are listed.
>
> I have personally tested with 2.7.8 and 2.12.0. Others on IRC report
> that this happens in the next branch.
Another data point. t3070-wildmatch.sh has a test for this case
match 1 0 'foo' '**/foo'

so the pattern matching machinery is _not_ broken. There may be some changes in ls-files (pathspec-related?) that leads to this. But I didn't try to bisect it.

-- 
Duy
Duy Nguyen· Apr 16, 2017, 11:25 UTC · re: Alistair Buxton · lore

Re: [BUG] ls-files '**' globstar matches one or more directories instead of zero or more directories

On Sat, Apr 15, 2017 at 2:17 AM, Alistair Buxton <a.j.buxton@gmail.com> wrote:
> To reproduce, go to any git repository and run:
>
>     diff <(git ls-files '**/*' | sort) <(git ls-files | sort)
Actually the '**/' magic only kicks in if you write
git ls-files ':(glob)**/*'
Without that '**' is a normal '*' and matching just subdirs is expected.
-- 
Duy
Alistair Buxton· Apr 16, 2017, 16:29 UTC · re: Duy Nguyen · lore

Re: [BUG] ls-files '**' globstar matches one or more directories instead of zero or more directories

On 16 April 2017 at 12:25, Duy Nguyen <pclouds@gmail.com> wrote:
> git ls-files ':(glob)**/*'
>
> Without that '**' is a normal '*' and matching just subdirs is expected.

But '*/' should match exactly one subdirectory deep. Instead it matches one more more subdirectories.

Meaning it behaves the way '**/*/' should.
Try the following in the git source repo:
    shopt -s globstar
    diff <(ls -1 */.gitignore | sort) <(git ls-files '*/.gitignore' | sort)
    diff <(ls -1 */**/.gitignore | sort) <(git ls-files '*/.gitignore' | sort)
of course it works as expected if you say the magic word:
    diff <(ls -1 */.gitignore | sort) <(git ls-files
':(glob)*/.gitignore' | sort)
-- 
Alistair Buxton
a.j.buxton@gmail.com
Alistair Buxton· Apr 16, 2017, 18:45 UTC · re: Alistair Buxton · lore

Re: [BUG] ls-files '**' globstar matches one or more directories instead of zero or more directories

On IRC someone pointed me to the glossary section for pathspec, and I find that even more confusing.

In the section about ":(glob)" it says:
> For example, "**/foo" matches file or directory "foo" anywhere, the same as pattern "foo".

This is not true for ls-files: ":(glob)**/.gitignore" is completely different to ":(glob).gitignore".

The only place where it is true is inside .gitignore files, and there the ":(glob)" syntax does not work.

-- 
Alistair Buxton
a.j.buxton@gmail.com

← back to recent threads