Skip to content

iterator: don't treat the top level directory as ignored - #7497

Open
AbuYahya94 wants to merge 1 commit into
libgit2:mainfrom
AbuYahya94:iterator-root-not-ignored
Open

AbuYahya94 wants to merge 1 commit into
libgit2:mainfrom
AbuYahya94:iterator-root-not-ignored

Conversation

@AbuYahya94

Copy link
Copy Markdown

With a .gitignore that contains only */ (also /*/ or **/), git_status_list_new reports no untracked files at the top level of the working directory. Git 2.56.1 lists them as untracked.

Reproduce

$ printf '*/\n' > .gitignore
$ touch x && mkdir d && touch d/y
$ git status --porcelain --untracked-files=all
?? .gitignore
?? x

libgit2's status for the same directory omits x and .gitignore.

Cause

When the workdir iterator pushes its first frame, it looks up the ignore state of the top level directory using an empty path. A rule that matches any directory matches that empty path, so the top level frame is marked as ignored, and every top level file with no rule of its own inherits that state.

Git never matches ignore rules against the working directory itself, only against the entries inside it (read_directory / treat_path in dir.c).

Change

Skip the ignore lookup for the top level frame, so nothing is inherited from it.

Testing

  • New test in ignore::status that fails on main and passes with the change.
  • ctest: the offline suite (397 suites) and util suite (54) pass.

This was found by a differential run of ignore implementations against git check-ignore / git ls-files from Git 2.56.1. The change was prepared with AI assistance (Claude) and reviewed by me.

🤖 Generated with Claude Code

When the workdir iterator pushes its first frame, it looks up the
ignore state of the top level directory using an empty path. A rule
that matches any directory, such as "*/", "/*/" or "**/", matches that
empty path, so the top level frame is marked as ignored. Every file at
the top level that has no rule of its own then inherits that state, and
`git_status_list_new` reports none of them as untracked: with a
.gitignore containing only "*/", status is empty apart from the ignored
directories.

Git never matches ignore rules against the working directory itself,
only against the paths within it, and lists those files as untracked.
Skip the lookup for the top level frame so that nothing is inherited
from it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant