csharpier icon indicating copy to clipboard operation
csharpier copied to clipboard

.gitignore from parent folders impacts formatting of children

Open yonguelink opened this issue 7 months ago • 3 comments

My {Home} folder, on windows, is managed via a git repository so I have the following file structure:

{Home}/.git/... {Home}/.gitignore {Home}/repos/{bunch of repositories}

The .gitignore in the {Home} folder contains repos to avoid committing stuff from the repositories I have on different machines into this "Home" repo.

Since I updated to csharpier 1.0.2 (I went from 0.30.x to 1.0.2), all my files are ignored by csharpier:

Image

After digging around, it's the repos in the .gitignore of my {Home} folder that's causing the issue.

Environments:

  • CSharpier Version: 1.0.2
  • Running CSharpier via: dotnet cli
  • Operating System: Windows
  • .csharpierrc Settings: Default
  • .editorconfig Settings: Default

Steps to reproduce:

  • Have a .gitignore somewhere in the directory chain of your files
  • Said .gitignore ignores the folder containing your files
  • Run the format or check commands

Or check the content of the following zip:

csharpier-reproduction.zip

If you uncomment the repos line in the root's .gitignore the formatting of the /repos/demo.cs file works.

Expected behavior:

The files should be formatted/checked.

I suggest that once a .gitignore file is found, to stop going further up in the chain.

Actual behavior:

The files are all ignored

yonguelink avatar Jun 09 '25 17:06 yonguelink

Gitignore is designed to have a hierarchy. If csharpier were to stop processing files when it found the first one it would be a non standard implementation.

You can modify the csharierignore file to specially include any files that are being ignored by your root gitignore. The csharierignore file takes priority over any gitignore file.

belav avatar Jun 09 '25 18:06 belav

If csharpier were to stop processing files when it found the first one it would be a non standard implementation.

I agree stopping at "the first one" is too simplistic, but git itself doesn't get confused by nested gitignore files in multiple repositories. I feel like this behavior should be applied to everything that uses the gitignore file. So it's more "if we find a .git folder (I assume that's not configurable in git? ...) we stop searching for more .gitignore files".

You can modify the csharierignore file to specially include any files that are being ignored by your root gitignore. The csharierignore file takes priority over any gitignore file.

That works, as a workaround IMO, - I didn't figure that .csharpierignore file were also read up in the directory hierarchy, so forcefully including my repos folder in ~/.csharpierignore seems to work.

yonguelink avatar Jun 09 '25 19:06 yonguelink

I agree stopping at "the first one" is too simplistic, but git itself doesn't get confused by nested gitignore files in multiple repositories. I feel like this behavior should be applied to everything that uses the gitignore file. So it's more "if we find a .git folder (I assume that's not configurable in git? ...) we stop searching for more .gitignore files".

Yeah looks like I wasn't correct with how git deals with .gitignore. It only takes one into account if it is in the current git repo. So it won't recurse to a parent folder that is not part of the same repo.

I can look at changing csharpier to match that behavior, I don't imagine it'll be too difficult to implement.

belav avatar Jun 13 '25 15:06 belav