forked from libgit2/libgit2sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIgnoreFixture.cs
More file actions
119 lines (95 loc) · 4.34 KB
/
Copy pathIgnoreFixture.cs
File metadata and controls
119 lines (95 loc) · 4.34 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
using System;
using System.IO;
using System.Linq;
using LibGit2Sharp.Tests.TestHelpers;
using Xunit;
namespace LibGit2Sharp.Tests
{
public class IgnoreFixture : BaseFixture
{
[Fact]
public void TemporaryRulesShouldApplyUntilCleared()
{
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
Touch(repo.Info.WorkingDirectory, "Foo.cs", "Bar");
Assert.Contains("Foo.cs", repo.RetrieveStatus().Untracked.Select(s => s.FilePath));
repo.Ignore.AddTemporaryRules(new[] { "*.cs" });
Assert.DoesNotContain("Foo.cs", repo.RetrieveStatus().Untracked.Select(s => s.FilePath));
repo.Ignore.ResetAllTemporaryRules();
Assert.Contains("Foo.cs", repo.RetrieveStatus().Untracked.Select(s => s.FilePath));
}
}
[Fact]
public void IsPathIgnoredShouldVerifyWhetherPathIsIgnored()
{
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
Touch(repo.Info.WorkingDirectory, "Foo.cs", "Bar");
Assert.False(repo.Ignore.IsPathIgnored("Foo.cs"));
repo.Ignore.AddTemporaryRules(new[] { "*.cs" });
Assert.True(repo.Ignore.IsPathIgnored("Foo.cs"));
repo.Ignore.ResetAllTemporaryRules();
Assert.False(repo.Ignore.IsPathIgnored("Foo.cs"));
}
}
[Fact]
public void CallingIsPathIgnoredWithBadParamsThrows()
{
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
Assert.Throws<ArgumentException>(() => repo.Ignore.IsPathIgnored(string.Empty));
Assert.Throws<ArgumentNullException>(() => repo.Ignore.IsPathIgnored(null));
}
}
[Fact]
public void AddingATemporaryRuleWithBadParamsThrows()
{
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
Assert.Throws<ArgumentNullException>(() => repo.Ignore.AddTemporaryRules(null));
}
}
[Fact]
public void CanCheckIfAPathIsIgnoredUsingThePreferedPlatformDirectorySeparatorChar()
{
string path = SandboxStandardTestRepo();
using (var repo = new Repository(path))
{
Touch(repo.Info.WorkingDirectory, ".gitignore", "/NewFolder\n/NewFolder/NewFolder");
Assert.False(repo.Ignore.IsPathIgnored("File.txt"));
Assert.True(repo.Ignore.IsPathIgnored("NewFolder"));
Assert.True(repo.Ignore.IsPathIgnored(string.Join("/", "NewFolder", "NewFolder")));
Assert.True(repo.Ignore.IsPathIgnored(string.Join("/", "NewFolder", "NewFolder", "File.txt")));
}
}
[Fact]
public void HonorDeeplyNestedGitIgnoreFile()
{
string path = InitNewRepository();
using (var repo = new Repository(path))
{
var gitIgnoreFile = string.Join("/", "deeply", "nested", ".gitignore");
Touch(repo.Info.WorkingDirectory, gitIgnoreFile, "SmtCounters.h");
Commands.Stage(repo, gitIgnoreFile);
repo.Commit("Add .gitignore", Constants.Signature, Constants.Signature);
Assert.False(repo.RetrieveStatus().IsDirty);
var ignoredFile = string.Join("/", "deeply", "nested", "SmtCounters.h");
Touch(repo.Info.WorkingDirectory, ignoredFile, "Content");
Assert.False(repo.RetrieveStatus().IsDirty);
var file = string.Join("/", "deeply", "nested", "file.txt");
Touch(repo.Info.WorkingDirectory, file, "Yeah!");
var repositoryStatus = repo.RetrieveStatus(new StatusOptions { IncludeIgnored = true });
Assert.True(repositoryStatus.IsDirty);
Assert.Equal(FileStatus.Ignored, repositoryStatus[ignoredFile].State);
Assert.Equal(FileStatus.NewInWorkdir, repositoryStatus[file].State);
Assert.True(repo.Ignore.IsPathIgnored(ignoredFile));
Assert.False(repo.Ignore.IsPathIgnored(file));
}
}
}
}