goelhardik / ignore Goto Github PK
View Code? Open in Web Editor NEW.gitignore based parser implemented in C# according to the .gitignore spec 2.29.2.
License: MIT License
.gitignore based parser implemented in C# according to the .gitignore spec 2.29.2.
License: MIT License
*+
=> .*+(/.*)?$
will generate an error:
System.Text.RegularExpressions.RegexParseException
Invalid pattern '.*+(/.*)?$' at offset 3. Nested quantifier '+'.
(taken from git's .gitignore
)
Great library. :-)
Hello, was wondering if there is a plan to update to the v2.43.0 .gitignore spec?
Windows allows either /
or \
for path chars, however if a rule is ".vs/*" but the path passed in is ".vs\myfile.txt" it does not say it should be ignored. Replacing all backslashes with forward slashes in both the initial path adding and match tries should fix it but would be good if it worked like git.
There is a problem with some of the Visual Studio .gitignore rules.
https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
The problem is these folder rules:
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
[Ww][Ii][Nn]32/
[Aa][Rr][Mm]/
[Aa][Rr][Mm]64/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
[Ll]ogs/
When I run a test in Ignore I get matches for folder names like MyLog, MyObj etc. This is an error because only the suffix in the folder name matches the rules.
Unit test example:
[Fact]
public void SimpleIgnore_ObjDir() => GitBasedTest(
@"""
[Bb]in/
[Oo]bj/
[Oo]ut/
[Ll]og/
[Ll]ogs/
""",
new[] { "foo/bar", "WpfObj/bar", "MyLog/foo" });
Git will not ignore these folders, but the Ignore code will.
Hello, I have problem with this case:
Unit test:
[TestCase]
public void TestIngoreMorePatterns()
{
var ignore = new Ignore.Ignore();
ignore.Add("!.gitignore");
ignore.Add("folder");
ignore.IsIgnored(@".gitignore").Should().BeFalse();
ignore.IsIgnored(@"src/Testfolder/.gitignore").Should().BeFalse();
ignore.IsIgnored(@"tools/Testfolder/.gitignore").Should().BeFalse();
}
Test is failing but it should not. Testfolder is not folder.
[Fact]
public void SimpleIgnore_Dotfiles_WithStar2() => GitBasedTest(
@"""
.vs/*
""",
new[] { "C:/foo/.vs/a.txt", "foo/.vs/a.txt", ".vs/a.txt" });
C:/foo/.vs/a.txt
should be ignored by the lib and is not.
I'm not sure why "foo/.vs/a.txt" is not ignored though ๐
**foo.txt
will produce **foo\.txt(/.*)?$
which is not valid:
System.Text.RegularExpressions.RegexParseException
Invalid pattern '**foo\.txt(/.*)?$' at offset 1. Quantifier {x,y} following nothing.
We are building a library in which we are relying on this project. We would like to strong name the library, however this would require to all the dependencies to be strong named as well, which as already mentioned includes this one. It would be the most convenient way for us and it would be a nice benefit for everyone else relying on this project.
In essence to fix this create a .snk
file and enter the following command in a Developer Command Prompt for VS
:
sn -k ignore.snk
Move the file to the same location as the Directory.Build.props
and add the following inside the Directory.Build.props
file:
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)/ignore.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
If you need any further assistance, or want me to create a PR for this feel free to tell me so. Any effort on your end is highly appreciated ๐
Didn't have time to investigate more but this test is failing:
[Fact]
public void SimpleIgnore_Dotfiles_WithStar3() => GitBasedTest(
@"""
*.mm.*
""",
new[] { "file.mm", "commonFile.txt" });
"commonFile.txt" is ignored by the lib.
Hello, this class seems awesome and I apologize in advance if my question seems stupid.
I have a repo on the disk, and it has an existing .gitignore
file that I want respected. Meaning, parse the .gitignore
file and then apply the rules in it. Is there a way to do that?
Might I proceed as the following (pseudo code):
namespace Ignore
{
public class Ignore
{
/*...*/
public void Ingest(string pathname /*pathname of the .gitignore file*/)
{
try
{
if (!File.Exists(pathname)) return;
if (!".gitignore".Equals(Path.GetFileName(pathname)) return;
var lines = File.ReadAllLines(pathname).ToList();
if (lines == null) return;
if (lines.Count == 0) return;
Add(lines.ToArray());
}
catch(Exception ex)
{
/* log the exception or handle it in another fashion */
}
}
/* ... */
}
Listing 1. Proposed methodology for ingesting an existing .gitignore
file that is already on the disk.
Would the code above work?
**/test/**/*.json
pattern with a file structure of api/test/unit/TestData/GitHubWebhook_New.json
is not working.
The file should be ignored.
Example:
public bool IsMatch(ReadOnlySpan<char> input)
{
return parsedRegex != null && parsedRegex.IsMatch(input);
}
Just add that signature in addition to the one taking string.
This reduces my time of scanning 200K files from 1.79 --> 1.57 seconds.
It's because the ReadOnlySpan supports an efficient Slice() operation, so I'm not scanning the part of the path above where the .gitignore file resides.
I'm the author of ViLark, a file chooser for vim, sort of like fzf.
And thanks for this library, it helps a lot. Although I am getting very slow performance with a wildcard like '*.pyc', I might dig into that if I have time.
If you pass an absolute path, dependind on the rule it will work correctly or not. It might give the impression that it's ok to use it like that.
Maybe it should throw when the path is rooted?
ignore.IsIgnored("C:\repos\foo.txt"); // => throw
ignore.IsIgnored("\foo.txt"); // => throw
ignore.IsIgnored("foo.txt"); // => OK
Pr https://github.com/goelhardik/ignore/pull/43/files displays the error
var ignore = new Ignore.Ignore();
ignore.Add(".*");
ignore.IsIgnored("/.dotfile").Dump(); // returns true
ignore.IsIgnored("/no.dotfile").Dump(); // returns true
The second one should not be ignored.
Tested using git.
Gitignore:
.*
Created the files .dotfile
and no.dotfile
: no.dotfile
shows up in the changes
tab.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.