Skip to content

Negation re-includes files under a directory excluded by a directory rule #7283

Open

Description

@jkoppel

Reproduction steps

.gitignore:

d/
!d/sub/*

Layout:

d/
  sub/
    f.txt

Then query whether d/sub/f.txt is ignored, e.g. git_ignore_path_is_ignored(), or
git_status/git_diff_tree_to_workdir with GIT_DIFF_INCLUDE_UNTRACKED.

Expected behavior

d/sub/f.txt is ignored, matching core git: git check-ignore d/sub/f.txt reports it's
excluded by the d/ rule. The !d/sub/* negation has no effect because a parent directory is
excluded — per the gitignore docs: "It is not possible to re-include a file if a parent
directory of that file is excluded."

Actual behavior

libgit2 reports d/sub/f.txt as not ignored (git_ignore_path_is_ignored returns 0, and
it shows up as untracked under GIT_DIFF_INCLUDE_UNTRACKED).

Same result with d/** instead of d/, and with !d/sub/** instead of !d/sub/*.

It works correctly when the negation targets a direct child of the excluded dir
(d/sub/ + !d/sub/f.txt → ignored, agreeing with git); the divergence only appears when the
re-included path sits under an intermediate subdirectory of the excluded directory.

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