Skip to content

Negation in a nested .gitignore fails to re-include a directory excluded by a parent .gitignore #7284

Open

Description

@jkoppel

Reproduction steps

Root .gitignore:

**/vendor/

a/.gitignore:

!vendor

Layout:

.gitignore
a/
  .gitignore
  vendor/
    f.txt

Then query whether a/vendor/f.txt is ignored, e.g. git_ignore_path_is_ignored(), or
git_status with GIT_DIFF_INCLUDE_UNTRACKED.

Expected behavior

a/vendor/f.txt is not ignored, matching core git: the nested a/.gitignore negation
!vendor re-includes the directory that the root **/vendor/ excluded. git check-ignore -v a/vendor/f.txt exits 1 (no match), and git ls-files --others --exclude-standard lists
a/vendor/f.txt.

Actual behavior

libgit2 reports a/vendor/f.txt as ignored (git_ignore_path_is_ignored returns 1; the
file is omitted from the untracked set under GIT_DIFF_INCLUDE_UNTRACKED).

The negation is honored when it lives in the same .gitignore as the exclude — i.e.
root .gitignore of **/vendor/ + !a/vendor correctly yields not-ignored. The divergence
appears only when the negation is in a nested (child-directory) .gitignore. (vendor/
instead of **/vendor/ reproduces it too.)

Version of libgit2 (release number or SHA1)

1.9.2

Operating system(s) tested

macOS 15.5 (Apple Silicon)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions