Skip to content

Commit

Permalink
Always ignore any files in .git folder (#1444)
Browse files Browse the repository at this point in the history
closes #1438
  • Loading branch information
belav authored Jan 20, 2025
1 parent fe57b44 commit 6eb1253
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
18 changes: 18 additions & 0 deletions Src/CSharpier.Cli.Tests/CliTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ public async Task Should_Respect_Ignore_File_With_Subdirectory_When_DirectorOrFi
result.Should().Be(unformattedContent, $"The file at {filePath} should have been ignored");
}

[TestCase(".git")]
[TestCase("subdirectory/.git")]
[TestCase("node_modules")]
[TestCase("subdirectory/node_modules")]
[TestCase("obj")]
[TestCase("subdirectory/obj")]
public async Task Should_Ignore_Special_Case_Files(string path)
{
var unformattedContent = "public class Unformatted { }";
var filePath = $"{path}/IgnoredFile.cs";
await this.WriteFileAsync(filePath, unformattedContent);

await new CsharpierProcess().WithArguments(".").ExecuteAsync();
var result = await this.ReadAllTextAsync(filePath);

result.Should().Be(unformattedContent, $"The file at {filePath} should have been ignored");
}

[Test]
public async Task Should_Support_Config_Path()
{
Expand Down
2 changes: 1 addition & 1 deletion Src/CSharpier.Cli/IgnoreFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ internal class IgnoreFile
{
protected Ignore.Ignore Ignore { get; }
protected string IgnoreBaseDirectoryPath { get; }
private static readonly string[] alwaysIgnored = ["**/node_modules/**/*.cs", "**/obj/**/*.cs"];
private static readonly string[] alwaysIgnored = ["**/node_modules", "**/obj", "**/.git"];

protected IgnoreFile(Ignore.Ignore ignore, string ignoreBaseDirectoryPath)
{
Expand Down
7 changes: 5 additions & 2 deletions docs/Ignore.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ _See [Configuration](CLI.md) for including these files_
- Any file that ends with `.g.i.cs`
- Any file that begins with a comment that contains `<autogenerated` or `<auto-generated`

#### Node Module Files
#### Special Case Files

- Any file that matches the gitignore syntax `**/node_modules/**/*.cs`
- Any file that matches the gitignore syntax
- `**/node_modules`
- `**/obj`
- `**/.git`

## Ignoring Code

Expand Down

0 comments on commit 6eb1253

Please sign in to comment.