Skip to content

Commit

Permalink
Allow specification of MatchFlags at the list level, closes #7
Browse files Browse the repository at this point in the history
  • Loading branch information
markashleybell committed Jun 23, 2016
1 parent 39a9481 commit 204191b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 14 deletions.
24 changes: 24 additions & 0 deletions MAB.DotIgnore.Test/IgnoreListTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,30 @@ public void DirectoryInfo_Match_Log()
Assert.IsTrue(log[0] == "Ignored by test > test");
}

[Test]
public void Constructor_Flags_Respected()
{
var directory = new DirectoryInfo(_basePath + @"\TEST");
// Case sensitive list, should not match
var list1 = new IgnoreList(new string[] { "test" });
// Case insensitive, should match
var list2 = new IgnoreList(new string[] { "test" }, MatchFlags.CASEFOLD);
Assert.IsFalse(list1.IsIgnored(directory));
Assert.IsTrue(list2.IsIgnored(directory));
}

[Test]
public void Add_Rule_Flags_Respected()
{
var directory = new DirectoryInfo(_basePath + @"\TEST");
var list1 = new IgnoreList(new string[] { "x" });
var list2 = new IgnoreList(new string[] { "x" });
list1.AddRule("test");
list2.AddRule("test", MatchFlags.CASEFOLD);
Assert.IsFalse(list1.IsIgnored(directory));
Assert.IsTrue(list2.IsIgnored(directory));
}

[TearDown]
public void TearDown()
{
Expand Down
27 changes: 16 additions & 11 deletions MAB.DotIgnore/IgnoreList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,50 @@ public class IgnoreList
/// Create a list of ignore rules to check paths against
/// </summary>
/// <param name="rules">A list of glob ignore patterns as strings</param>
public IgnoreList(IEnumerable<string> rules)
/// <param name="flags">Optional flags determining pattern matching behaviour</param>
public IgnoreList(IEnumerable<string> rules, MatchFlags flags = MatchFlags.PATHNAME)
{
AddRules(rules);
AddRules(rules, flags);
}

/// <summary>
/// Create a list of ignore rules to check paths against
/// </summary>
/// <param name="ignoreFilePath">Path to a text file containing a list of glob ignore patterns as strings</param>
public IgnoreList(string ignoreFilePath)
/// <param name="flags">Optional flags determining pattern matching behaviour</param>
public IgnoreList(string ignoreFilePath, MatchFlags flags = MatchFlags.PATHNAME)
{
AddRules(File.ReadAllLines(ignoreFilePath));
AddRules(File.ReadAllLines(ignoreFilePath), flags);
}

/// <summary>
/// Add a rule to the ignore list
/// </summary>
/// <param name="rule">Glob ignore pattern as string</param>
public void AddRule(string rule)
/// <param name="flags">Optional flags determining pattern matching behaviour</param>
public void AddRule(string rule, MatchFlags flags = MatchFlags.PATHNAME)
{
AddRules(new string[] { rule });
AddRules(new string[] { rule }, flags);
}

/// <summary>
/// Add multiple rules to the ignore list
/// </summary>
/// <param name="ignoreFilePath">Path to a text file containing a list of glob ignore patterns as strings</param>
public void AddRules(string ignoreFilePath)
/// <param name="flags">Optional flags determining pattern matching behaviour</param>
public void AddRules(string ignoreFilePath, MatchFlags flags = MatchFlags.PATHNAME)
{
_rules.AddRange(CleanRules(File.ReadAllLines(ignoreFilePath)).Select(line => new IgnoreRule(line)));
_rules.AddRange(CleanRules(File.ReadAllLines(ignoreFilePath)).Select(line => new IgnoreRule(line, flags)));
}

/// <summary>
/// Add multiple rules to the ignore list
/// </summary>
/// <param name="rules">A list of glob ignore patterns as strings</param>
public void AddRules(IEnumerable<string> rules)
/// <param name="flags">Optional flags determining pattern matching behaviour</param>
public void AddRules(IEnumerable<string> rules, MatchFlags flags = MatchFlags.PATHNAME)
{
_rules.AddRange(CleanRules(rules).Select(line => new IgnoreRule(line)));
_rules.AddRange(CleanRules(rules).Select(line => new IgnoreRule(line, flags)));
}

/// <summary>
Expand All @@ -75,7 +80,7 @@ public void RemoveRule(string rule)
/// <summary>
/// Check if a file path matches any of the rules in the ignore list
/// </summary>
/// <param name="file">FileInfo representing the file to chec</param>
/// <param name="file">FileInfo representing the file to check</param>
public bool IsIgnored(FileInfo file)
{
return IsIgnored(file.FullName, false);
Expand Down
1 change: 1 addition & 0 deletions MAB.DotIgnore/IgnoreRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class IgnoreRule
/// Create an individual ignore rule for the specified pattern
/// </summary>
/// <param name="pattern">A glob pattern specifying file(s) this rule should ignore</param>
/// <param name="flags">Optional flags determining pattern matching behaviour</param>
public IgnoreRule(string pattern, MatchFlags flags = MatchFlags.PATHNAME)
{
if(Utils.IsNullOrWhiteSpace(pattern))
Expand Down
6 changes: 3 additions & 3 deletions MAB.DotIgnore/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0")]

0 comments on commit 204191b

Please sign in to comment.