Fix gitignore ancestor detection for git worktrees#1424
Merged
Conversation
Git worktrees use a `.git` file (containing a pointer to the actual git directory) instead of a `.git` directory. The gitignore ancestor traversal was only checking for directories, causing it to incorrectly continue searching beyond the worktree root into the parent repository. This adds an `isGitRoot()` helper that checks for both `.git` directory and `.git` file, fixing the boundary detection for worktrees.
Contributor
Author
|
following up on my spam in #990 |
commit: |
git doesn't allow .git files to be committed so it has to be created
Contributor
Author
|
i fixed some of the basic test failures. i forgot to make sure git included the |
webpro
reviewed
Jan 1, 2026
Member
webpro
left a comment
There was a problem hiding this comment.
Thanks! Hopefully we can get the test issues fixed.
|
|
||
| // Create the .git file for worktree tests (git won't track files named .git) | ||
| const worktreeRoot = resolve('fixtures/glob-worktree/root'); | ||
| copyFileSync(join(worktreeRoot, 'dot-git'), join(worktreeRoot, '.git')); |
Member
There was a problem hiding this comment.
Probably good to clean up as well, also see
Member
There was a problem hiding this comment.
Thanks! What I meant is to clean up after the test ran, but it does not seem to matter, so I guess we're good here.
Organize git worktree tests into a describe block and move the .git file setup from module-level into test.before() for better test isolation.
Member
|
Thanks Kyle! Way to go 😉 |
Member
|
🚀 This pull request is included in v5.79.0. See Release 5.79.0 for release notes. Using Knip in a commercial project? Please consider becoming a sponsor. |
3 tasks
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.
Git worktrees use a
.gitfile (containing a pointer to the actual gitdirectory) instead of a
.gitdirectory. The gitignore ancestor traversalwas only checking for directories, causing it to incorrectly continue
searching beyond the worktree root into the parent repository.
This adds an
isGitRoot()helper that checks for both.gitdirectoryand
.gitfile, fixing the boundary detection for worktrees.