Stop .gitignore walk at git worktree boundary by Jacko1394 · Pull Request #1860 · belav/csharpier (original) (raw)

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.

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

Checklist