Repository navigation
iterator: don't treat the top level directory as ignored - #7497
Open
AbuYahya94 wants to merge 1 commit into
Open
AbuYahya94 wants to merge 1 commit into
AbuYahya94 wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With a
.gitignorethat contains only*/(also/*/or**/),git_status_list_newreports no untracked files at the top level of the working directory. Git 2.56.1 lists them as untracked.Reproduce
libgit2's status for the same directory omits
xand.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_pathindir.c).Change
Skip the ignore lookup for the top level frame, so nothing is inherited from it.
Testing
ignore::statusthat fails onmainand passes with the change.ctest: theofflinesuite (397 suites) andutilsuite (54) pass.This was found by a differential run of ignore implementations against
git check-ignore/git ls-filesfrom Git 2.56.1. The change was prepared with AI assistance (Claude) and reviewed by me.🤖 Generated with Claude Code