# git check-ignore ignores negated entries

2 messages from 2018-09-20 to 2018-09-21. Participants: David Alphus, Duy Nguyen.
Thread: https://gitlist.dev/t/49392

## David Alphus, 2018-09-20 17:22

Subject: git check-ignore ignores negated entries
Message-ID: <CAB=bJ9Mjw2keJ3aspLWcreLBcB15Eq-WjtBO0XS8B=C3XJmx9A@mail.gmail.com>
URL: https://gitlist.dev/e/CAB%3DbJ9Mjw2keJ3aspLWcreLBcB15Eq-WjtBO0XS8B%3DC3XJmx9A%40mail.gmail.com

```
If a .gitignore contains a ! entry, git check-ignore will still say
the matching file is ignored if the file is not in the index.

Simple case to reproduce:

$ git init .
$ echo "*.c" > .gitignore
$ echo '!a.c' >> .gitignore
$ touch a.c b.c
$ git check-ignore a.c b.c
a.c
b.c
$ git add *.c
The following paths are ignored by one of your .gitignore files:
b.c
Use -f if you really want to add them.
$ git check-ignore a.c b.c
b.c
$ git check-ignore --no-index a.c b.c
a.c
b.c
$ git check-ignore --no-index --verbose a.c b.c
.gitignore:2:!a.c       a.c
.gitignore:1:*.c        b.c

In looking through check-ignore.c, it appears that we check that
last_exclude_matching() returns an exclude object. It should be noted
that we do not consider that exclude struct can be set with the
EXC_FLAG_NEGATIVE flag. This flag says that the final matching rule
should not be ignored.
check_ignore needs to consider this condition in order to work properly.

```

## Duy Nguyen, 2018-09-21 16:13

Subject: Re: git check-ignore ignores negated entries
Message-ID: <CACsJy8Cn-SyY6E8O3ttmr8k2vJ+8gGoN+NFmUSD71yiC1t552w@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8Cn-SyY6E8O3ttmr8k2vJ%2B8gGoN%2BNFmUSD71yiC1t552w%40mail.gmail.com
In-Reply-To: <CAB=bJ9Mjw2keJ3aspLWcreLBcB15Eq-WjtBO0XS8B=C3XJmx9A@mail.gmail.com>

```
On Thu, Sep 20, 2018 at 7:25 PM David Alphus <david.alphus@gmail.com> wrote:
> In looking through check-ignore.c, it appears that we check that
> last_exclude_matching() returns an exclude object. It should be noted
> that we do not consider that exclude struct can be set with the
> EXC_FLAG_NEGATIVE flag. This flag says that the final matching rule
> should not be ignored.
> check_ignore needs to consider this condition in order to work properly.

I haven't checked the code yet. But since you already did, patches are
welcome ;-)
-- 
Duy

```
