Skip to content

Only look for gitignore files inside the scope of the current git repo#1649

Merged
belav merged 5 commits into
mainfrom
limit-git
Jul 5, 2025
Merged

Only look for gitignore files inside the scope of the current git repo#1649
belav merged 5 commits into
mainfrom
limit-git

Conversation

@belav
Copy link
Copy Markdown
Owner

@belav belav commented Jul 5, 2025

closes #1627

@belav belav merged commit 891de9a into main Jul 5, 2025
6 checks passed
@belav belav deleted the limit-git branch July 5, 2025 15:09
belav pushed a commit that referenced this pull request May 17, 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

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

Co-authored-by: Jack Della <jack.della@revivefinancial.com.au>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.

.gitignore from parent folders impacts formatting of children

1 participant