-
Notifications
You must be signed in to change notification settings - Fork 892
/
Copy pathIgnore.cs
69 lines (60 loc) · 2.31 KB
/
Ignore.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LibGit2Sharp.Core;
namespace LibGit2Sharp
{
/// <summary>
/// Provides methods to manage the rules ensuring that some specific
/// untracked files are ignored.
/// </summary>
public class Ignore
{
private readonly Repository repo;
/// <summary>
/// Needed for mocking purposes.
/// </summary>
protected Ignore()
{ }
internal Ignore(Repository repo)
{
this.repo = repo;
}
/// <summary>
/// Adds a custom .gitignore rule that will be applied to futher operations to the Index. This is in addition
/// to the standard .gitignore rules that would apply as a result of the system/user/repo .gitignore
/// </summary>
/// <param name="rules">The content of a .gitignore file that will be applied.</param>
public virtual void AddTemporaryRules(IEnumerable<string> rules)
{
Ensure.ArgumentNotNull(rules, "rules");
var allRules = rules.Aggregate(new StringBuilder(), (acc, x) =>
{
acc.Append(x);
acc.Append("\n");
return acc;
});
Proxy.git_ignore_add_rule(repo.Handle, allRules.ToString());
}
/// <summary>
/// Resets all custom rules that were applied via calls to
/// <see cref="AddTemporaryRules"/> - note that this will not affect
/// the application of the user/repo .gitignores.
/// </summary>
public virtual void ResetAllTemporaryRules()
{
Proxy.git_ignore_clear_internal_rules(repo.Handle);
}
/// <summary>
/// Given a relative path, this method determines whether a path should be ignored, checking
/// both the custom ignore rules as well as the "normal" .gitignores.
/// </summary>
/// <param name="relativePath">A path relative to the repository</param>
/// <returns>true if the path should be ignored.</returns>
public virtual bool IsPathIgnored(string relativePath)
{
Ensure.ArgumentNotNullOrEmptyString(relativePath, "relativePath");
return Proxy.git_ignore_path_is_ignored(repo.Handle, relativePath);
}
}
}