# bug with git add and .gitignore

2 messages from 2017-05-10 to 2017-05-16. Participants: Orgad Shaneh, Samuel Lijin.
Thread: https://gitlist.dev/t/45921

## Orgad Shaneh, 2017-05-10 13:44

Subject: bug with git add and .gitignore
Message-ID: <CAGHpTBLGwGXZk=xAB+Pb4GvtqN8+K=8BuaA-zov9sZZat-OYHQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAGHpTBLGwGXZk%3DxAB%2BPb4GvtqN8%2BK%3D8BuaA-zov9sZZat-OYHQ%40mail.gmail.com

```
Hi,

When a not-ignored file inside an ignore directory is added along with
other files, a false alarm is shown:

git init
echo /d/ > .gitignore
mkdir d
touch d/file foo
git add -f d/file foo
git add d/file
# fine
git add d/file foo
# The following paths are ignored by one of your .gitignore files:
# d
# Use -f if you really want to add them.

I did not try to add a new file in d. It's the same file that is
already indexed.

- Orgad

```

## Samuel Lijin, 2017-05-16 19:10

Subject: Re: bug with git add and .gitignore
Message-ID: <CAJZjrdUPU8bGji9yCv-8CWN2zaV8WSkvTv+9c3Q5pmnrgyaEXw@mail.gmail.com>
URL: https://gitlist.dev/e/CAJZjrdUPU8bGji9yCv-8CWN2zaV8WSkvTv%2B9c3Q5pmnrgyaEXw%40mail.gmail.com
In-Reply-To: <CAGHpTBLGwGXZk=xAB+Pb4GvtqN8+K=8BuaA-zov9sZZat-OYHQ@mail.gmail.com>

```
On Wed, May 10, 2017 at 9:44 AM, Orgad Shaneh <orgads@gmail.com> wrote:
> Hi,
>
> When a not-ignored file inside an ignore directory is added along with
> other files, a false alarm is shown:
>
> git init
> echo /d/ > .gitignore
> mkdir d
> touch d/file foo
> git add -f d/file foo
> git add d/file
> # fine
> git add d/file foo
> # The following paths are ignored by one of your .gitignore files:
> # d
> # Use -f if you really want to add them.

For anyone who wants to take a shot at this, the reason this happens
is because when "add d/file foo" is invoked, when add.c:cmd_add()
calls fill_directory(), d/ gets added to dir->ignored, so add_files()
complains. I'm not sure if that's *supposed* to happen, and the issue
is somewhere else, or the call to read_directory_recursive() from
fill_directory() doesn't properly respect the pathspec.

> I did not try to add a new file in d. It's the same file that is
> already indexed.
>
> - Orgad

```
