# Cannot negate `*` ignore pattern for directory with space in the name

3 messages from 2018-09-18 to 2018-09-18. Participants: Victor Engmark, Duy Nguyen.
Thread: https://gitlist.dev/t/49364

## Victor Engmark, 2018-09-18 04:03

Subject: Cannot negate `*` ignore pattern for directory with space in the name
Message-ID: <955f404f-83ed-758e-017b-d6b4a1f69ef7@catalyst.net.nz>
URL: https://gitlist.dev/e/955f404f-83ed-758e-017b-d6b4a1f69ef7%40catalyst.net.nz

```
To reproduce (from <https://unix.stackexchange.com/q/469708/3645>):

$ cd "$(mktemp --directory)"
$ mkdir foo\ bar
$ touch foo\ bar/test
$ git init
Initialized empty Git repository in /tmp/tmp.iGmBR6y2xR/.git/
$ git status --short
?? foo bar/
$ cat > .gitignore << EOF
> *
> !foo bar
> !foo\ bar
> !"foo bar"
> "!foo bar"
> !foo*
> !foo bar/
> !foo\ bar/
> !"foo bar/"
> "!foo bar/"
> !foo*/
> EOF
$ git status --short
[no output]

The pattern *can* be negated if it only matches directories:

$ cat > .gitignore << EOF
> */
> !foo\ bar/
> EOF
$ git status --short
?? .gitignore
?? foo bar/

I encountered this problem because Visual Studio Code creates a
configuration directory called "Code - OSS", and I exclude everything in
~/.config by default to avoid noise in `git status`.

$ git --version
git version 2.19.0

-- 
Kind regards
Victor Engmark

```

## Duy Nguyen, 2018-09-18 17:59

Subject: Re: Cannot negate `*` ignore pattern for directory with space in the name
Message-ID: <CACsJy8Cbp+1-CXMup4m=qLgJA511X0NtM51sFma_8nmp4_EhKg@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8Cbp%2B1-CXMup4m%3DqLgJA511X0NtM51sFma_8nmp4_EhKg%40mail.gmail.com
In-Reply-To: <955f404f-83ed-758e-017b-d6b4a1f69ef7@catalyst.net.nz>

```
On Tue, Sep 18, 2018 at 6:13 AM Victor Engmark
<victorengmark@catalyst.net.nz> wrote:
>
> To reproduce (from <https://unix.stackexchange.com/q/469708/3645>):
>
> $ cd "$(mktemp --directory)"
> $ mkdir foo\ bar
> $ touch foo\ bar/test
> $ git init
> Initialized empty Git repository in /tmp/tmp.iGmBR6y2xR/.git/
> $ git status --short
> ?? foo bar/
> $ cat > .gitignore << EOF
> > *
> > !foo bar
> > !foo\ bar
> > !"foo bar"

No need to quote, either with double quotes or backslashes. They are
interpreted as literal " and \

> $ git status --short
> [no output]

It's not exactly a bug, more like a trap. '*' matches anything, at
every level. So even if you negate 'foo bar', when we check 'foo
bar/test', '*' pattern applies again and ignores 'foo bar/test'. If
the first line in .gitignore is /* instead of * (to keep match
anything at the top level directory only), then it should work.
-- 
Duy

```

## Victor Engmark, 2018-09-18 21:03

Subject: Re: Cannot negate `*` ignore pattern for directory with space in the name
Message-ID: <4af0a71a-4b25-f09c-b238-3264e7a49058@catalyst.net.nz>
URL: https://gitlist.dev/e/4af0a71a-4b25-f09c-b238-3264e7a49058%40catalyst.net.nz
In-Reply-To: <CACsJy8Cbp+1-CXMup4m=qLgJA511X0NtM51sFma_8nmp4_EhKg@mail.gmail.com>

```
On 19/09/2018 05:59, Duy Nguyen wrote:
> On Tue, Sep 18, 2018 at 6:13 AM Victor Engmark
> <victorengmark@catalyst.net.nz> wrote:
[…]
>> $ cat > .gitignore << EOF
>>> *
>>> !foo bar
>>> !foo\ bar
>>> !"foo bar"
> 
> No need to quote, either with double quotes or backslashes. They are
> interpreted as literal " and \

Thanks! I just tried a bunch of things to see if anything stuck.

>> $ git status --short
>> [no output]
> 
> It's not exactly a bug, more like a trap. '*' matches anything, at
> every level. So even if you negate 'foo bar', when we check 'foo
> bar/test', '*' pattern applies again and ignores 'foo bar/test'. If
> the first line in .gitignore is /* instead of * (to keep match
> anything at the top level directory only), then it should work.

You're right, I've managed to induce the placebo effect in myself :)
Thank you for the help, and sorry for the noise!

-- 
Cheers
Victor

```
