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

5 messages from 2017-04-14 to 2017-04-16. Participants: Alistair Buxton, Duy Nguyen.
Thread: https://gitlist.dev/t/45692

## Alistair Buxton, 2017-04-14 19:17

Subject: [BUG] ls-files '**' globstar matches one or more directories instead of zero or more directories
Message-ID: <CAO-Op+GujOUuueqwOKbb1NosZ-VYY5KVWm1+HNMC8xhd0ApEDw@mail.gmail.com>
URL: https://gitlist.dev/e/CAO-Op%2BGujOUuueqwOKbb1NosZ-VYY5KVWm1%2BHNMC8xhd0ApEDw%40mail.gmail.com

```
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, 2017-04-16 10:53

Subject: Re: [BUG] ls-files '**' globstar matches one or more directories instead of zero or more directories
Message-ID: <CACsJy8ASuQqnZb97BmPtOeAoTuS4bE6-7p21SDd9DP6SNyX+3Q@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8ASuQqnZb97BmPtOeAoTuS4bE6-7p21SDd9DP6SNyX%2B3Q%40mail.gmail.com
In-Reply-To: <CAO-Op+GujOUuueqwOKbb1NosZ-VYY5KVWm1+HNMC8xhd0ApEDw@mail.gmail.com>

```
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)
>
> 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, 2017-04-16 11:25

Subject: Re: [BUG] ls-files '**' globstar matches one or more directories instead of zero or more directories
Message-ID: <CACsJy8DQWrLZF3wUQ5WF2FfriM6ko8Zwm_x5ErEEWTE6n5rayw@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8DQWrLZF3wUQ5WF2FfriM6ko8Zwm_x5ErEEWTE6n5rayw%40mail.gmail.com
In-Reply-To: <CAO-Op+GujOUuueqwOKbb1NosZ-VYY5KVWm1+HNMC8xhd0ApEDw@mail.gmail.com>

```
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, 2017-04-16 16:29

Subject: Re: [BUG] ls-files '**' globstar matches one or more directories instead of zero or more directories
Message-ID: <CAO-Op+Fd9x7O66skWWy5TkTfMst7ohUiw3U9MMujyvYsjWnFSg@mail.gmail.com>
URL: https://gitlist.dev/e/CAO-Op%2BFd9x7O66skWWy5TkTfMst7ohUiw3U9MMujyvYsjWnFSg%40mail.gmail.com
In-Reply-To: <CACsJy8DQWrLZF3wUQ5WF2FfriM6ko8Zwm_x5ErEEWTE6n5rayw@mail.gmail.com>

```
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, 2017-04-16 18:45

Subject: Re: [BUG] ls-files '**' globstar matches one or more directories instead of zero or more directories
Message-ID: <CAO-Op+HTNdn6gE_V-4dBjjYTfSjq71sXhBVV6vutFzm2fsctQQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAO-Op%2BHTNdn6gE_V-4dBjjYTfSjq71sXhBVV6vutFzm2fsctQQ%40mail.gmail.com
In-Reply-To: <CAO-Op+Fd9x7O66skWWy5TkTfMst7ohUiw3U9MMujyvYsjWnFSg@mail.gmail.com>

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

```
