Skip to content

Stop .gitignore walk at git worktree boundary#1860

Merged
belav merged 1 commit into
belav:mainfrom
Jacko1394:gitignore-worktree-boundary
May 17, 2026
Merged

Stop .gitignore walk at git worktree boundary#1860
belav merged 1 commit into
belav:mainfrom
Jacko1394:gitignore-worktree-boundary

Conversation

@Jacko1394
Copy link
Copy Markdown
Contributor

@Jacko1394 Jacko1394 commented May 15, 2026

Issue

csharpier was not formatting any files, in a worktree under a .gitignored folder path

Description

IgnoreFile.FindIgnorePaths walks up from the target directory collecting .gitignore files and stops when it encounters a .git directory. In a git worktree, .git is a file containing a gitdir: pointer rather than a directory, so the walk continued past the worktree root.

When the worktree lives at a path the parent repo's .gitignore excludes (e.g. tools that create worktrees inside an ignored folder), every file in the worktree is matched by the parent ignore rule and dotnet csharpier format . reports Formatted 0 files.

This change also stops the walk when .git exists as a file, matching git's own treatment of the worktree as a separate working tree. Added a regression test that mirrors the existing Gitignore_Outside_Git_Is_Not_Used but with .git as a file.

Related Issue

Follow-up to #1627 / #1649, which introduced the .git directory boundary but did not cover worktrees.

Checklist

  • My code follows the project's code style
    • always var
    • follow existing naming conventions
    • always this.
    • no pointless comments
  • I will not force push after a code review of my PR has started
  • I have added tests that cover my changes

In a git worktree the `.git` entry is a file containing a `gitdir:` pointer
rather than a directory, so `IgnoreFile.FindIgnorePaths` walked past the
worktree root and pulled in the parent repo's `.gitignore`. When the worktree
lives at a path the parent excludes, every file in the worktree is reported
as ignored.

Treat `.git` as a boundary when it exists as a file as well as a directory.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Owner

@belav belav left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

@belav belav added this to the 1.3.0 milestone May 17, 2026
@belav belav merged commit 0040caa into belav:main May 17, 2026
7 checks passed
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.

2 participants