I believe current implementation does not conform to Git behavior, where negation patterns are evaluated at the end so files in un-ignored directories cannot be ignored again:
|
public (bool hasMatchingRule, bool isIgnored) IsIgnored(string path) |
|
{ |
|
if (!path.StartsWith(basePath, StringComparison.Ordinal)) |
|
{ |
|
return (false, false); |
|
} |
|
|
|
var pathRelativeToIgnoreFile = |
|
path.Length > basePath.Length |
|
? path[basePath.Length..].Replace('\\', '/') |
|
: string.Empty; |
|
|
|
var isIgnored = false; |
|
var hasMatchingRule = false; |
|
|
|
foreach (var rule in this.positives) |
|
{ |
|
var isMatch = rule.IsMatch(pathRelativeToIgnoreFile); |
|
if (isMatch) |
|
{ |
|
hasMatchingRule = true; |
|
isIgnored = true; |
|
break; |
|
} |
|
} |
|
|
|
foreach (var rule in this.negatives) |
|
{ |
|
var isMatch = rule.IsMatch(pathRelativeToIgnoreFile); |
|
if (isMatch) |
|
{ |
|
hasMatchingRule = true; |
|
if (isIgnored) |
|
{ |
|
isIgnored = false; |
|
break; |
|
} |
|
} |
|
} |
|
|
|
return (hasMatchingRule, isIgnored); |
|
} |
Environments:
- CSharpier Version: 1.2.1
- Running CSharpier via: dotnet cli
- Operating System: Linux
- .csharpierrc Settings: NA
- .editorconfig Settings: NA
Steps to reproduce:
setup:
git init
mkdir -p Experimental/App123/IgnoreMe/
echo -e "Experimental/*\n\!App123/\nIgnoreMe/" > .gitignore
echo -e "int n;" > Experimental/test.cs
echo -e "int n;" > Experimental/App123/IgnoreMe/test.cs
Experimental/App123/IgnoreMe/test.cs should be ignored:
git check-ignore --verbose --non-matching Experimental/test.cs Experimental/App123/IgnoreMe/test.cs
output:
.gitignore:1:Experimental/* Experimental/test.cs
.gitignore:3:IgnoreMe/ Experimental/App123/IgnoreMe/test.cs
Expected behavior:
dnx csharpier@1.2.1 -- check .
output:
Actual behavior:
dnx csharpier@1.2.1 -- check .
output:
Error ./Experimental/App123/IgnoreMe/test.cs - Was not formatted.
----------------------------- Expected: Around Line 1 -----------------------------
int n;
----------------------------- Actual: Around Line 1 -----------------------------
int n;
Checked 1 files in 0ms.
I believe current implementation does not conform to Git behavior, where negation patterns are evaluated at the end so files in un-ignored directories cannot be ignored again:
csharpier/Src/CSharpier.Cli/IgnoreFile.cs
Lines 181 to 222 in 1ad752d
Environments:
Steps to reproduce:
setup:
Experimental/App123/IgnoreMe/test.csshould be ignored:output:
Expected behavior:
dnx csharpier@1.2.1 -- check .output:
Actual behavior:
dnx csharpier@1.2.1 -- check .output: