threads / bug / 62409

[BUG] spurious failure when adding tracked file in ignored directory

Subject: [BUG] spurious failure when adding tracked file in ignored directory

## tl;dr

3 messages between Oct 25, 2024 and Oct 27, 2024.

replies: 2people: 2as markdown or json

Christian Sattler· Oct 25, 2024, 23:30 UTC · lore

Adding a tracked file in an ignored directory causes a spurious warning and exit code 1 failure (despite actually adding the file). Example on 2.47.0:

git init mkdir dir touch dir/file git add dir/file echo dir >.gitignore git add dir/file

The last command fails with exit code 1 and prints:
> The following paths are ignored by one of your .gitignore files:
> dir
> hint: Use -f if you really want to add them.
> hint: Disable this message with "git config advice.addIgnoredFile false"

Suppose we change dir/file before the last command. Then after the last command, the change is in the index, despite what the warning indicates.

- Christian
Johannes Sixt· Oct 27, 2024, 13:44 UTC · re: Christian Sattler · lore

Re: [BUG] spurious failure when adding tracked file in ignored directory

Am 26.10.24 um 01:30 schrieb Christian Sattler:
Show 19 quoted lines
> Adding a tracked file in an ignored directory causes a spurious warning and
> exit code 1 failure (despite actually adding the file). Example on 2.47.0:
> 
> git init
> mkdir dir
> touch dir/file
> git add dir/file
> echo dir >.gitignore
> git add dir/file
> 
> The last command fails with exit code 1 and prints:
> 
>> The following paths are ignored by one of your .gitignore files:
>> dir
>> hint: Use -f if you really want to add them.
>> hint: Disable this message with "git config advice.addIgnoredFile false"
> 
> Suppose we change dir/file before the last command.  Then after the last
> command, the change is in the index, despite what the warning indicates.

I cannot reproduce your claim "despite actually adding the file": the file is not added. So, everything works as intended. What does `git status` tell after `git add`?

-- Hannes
Christian Sattler· Oct 27, 2024, 14:07 UTC · re: Johannes Sixt · lore

Re: [BUG] spurious failure when adding tracked file in ignored directory

On Sun, 27 Oct 2024 at 14:45, Johannes Sixt <j6t@kdbg.org> wrote:
> I cannot reproduce your claim "despite actually adding the file": the
> file is not added. So, everything works as intended. What does `git
> status` tell after `git add`?
Here is the example with modifications before the add.

git init mkdir dir touch dir/file git add dir/file echo dir >.gitignore echo content >dir/file

Output of git status:
Show 7 quoted lines
> On branch main
>
> No commits yet
>
> Changes to be committed:
>   (use "git rm --cached <file>..." to unstage)
> new file:   dir/file
> Changes not staged for commit:
>   (use "git add <file>..." to update what will be committed)
>   (use "git restore <file>..." to discard changes in working directory)
> modified:   dir/file
> Untracked files:
>   (use "git add <file>..." to include in what will be committed)
> .gitignore
git add dir/file  # fails with warning and exit code 1
Output of git status:
Show 7 quoted lines
> On branch main
>
> No commits yet
>
> Changes to be committed:
>   (use "git rm --cached <file>..." to unstage)
> new file:   dir/file
> Untracked files:
>   (use "git add <file>..." to include in what will be committed)
> .gitignore

← back to recent threads