8000 Add some .gitignore handling test coverage · mm201/libgit2sharp@ac34838 · GitHub
[go: up one dir, main page]

Skip to content

Commit ac34838

Browse files
committed
Add some .gitignore handling test coverage
1 parent 2b77adb commit ac34838

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed

LibGit2Sharp.Tests/StatusFixture.cs

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,31 @@ public void RetrievingTheStatusOfARepositoryReturnNativeFilePaths()
127127
}
128128
}
129129

130+
[Fact]
131+
public void RetrievingTheStatusOfAnEmptyRepositoryHonorsTheGitIgnoreDirectives()
132+
{
133+
SelfCleaningDirectory scd = BuildSelfCleaningDirectory();
134+
135+
using (Repository repo = Repository.Init(scd.DirectoryPath))
136+
{
137+
string relativePath = "look-ma.txt";
138+
string fullFilePath = Path.Combine(repo.Info.WorkingDirectory, relativePath);
139+
File.WriteAllText(fullFilePath, "I'm going to be ignored!");
140+
141+
RepositoryStatus status = repo.Index.RetrieveStatus();
142+
Assert.Equal(new[] { relativePath }, status.Untracked);
143+
144+
string gitignorePath = Path.Combine(repo.Info.WorkingDirectory, ".gitignore");
145+
File.WriteAllText(gitignorePath, "*.txt" + Environment.NewLine);
146+
147+
RepositoryStatus newStatus = repo.Index.RetrieveStatus();
148+
newStatus.Untracked.Single().ShouldEqual(".gitignore");
149+
150+
repo.Index.RetrieveStatus(relativePath).ShouldEqual(FileStatus.Ignored);
151+
Assert.Equal(new[] { relativePath }, newStatus.Ignored);
152+
}
153+
}
154+
130155
[Fact]
131156
public void RetrievingTheStatusOfTheRepositoryHonorsTheGitIgnoreDirectives()
132157
{
@@ -137,13 +162,79 @@ public void RetrievingTheStatusOfTheRepositoryHonorsTheGitIgnoreDirectives()
137162
string fullFilePath = Path.Combine(repo.Info.WorkingDirectory, relativePath);
138163
File.WriteAllText(fullFilePath, "I'm going to be ignored!");
139164

165+
/*
166+
* $ git status --ignored
167+
* # On branch master
168+
* # Your branch and 'origin/master' have diverged,
169+
* # and have 2 and 2 different commit(s) each, respectively.
170+
* #
171+
* # Changes to be committed:
172+
* # (use "git reset HEAD <file>..." to unstage)
173+
* #
174+
* # deleted: deleted_staged_file.txt
175+
* # modified: modified_staged_file.txt
176+
* # new file: new_tracked_file.txt
177+
* #
178+
* # Changes not staged for commit:
179+
* # (use "git add/rm <file>..." to update what will be committed)
180+
* # (use "git checkout -- <file>..." to discard changes in working directory)
181+
* #
182+
* # modified: 1/branch_file.txt
183+
* # modified: README
184+
* # modified: branch_file.txt
185+
* # deleted: deleted_unstaged_file.txt
186+
* # modified: modified_unstaged_file.txt
187+
* # modified: new.txt
188+
* #
189+
* # Untracked files:
190+
* # (use "git add <file>..." to include in what will be committed)
191+
* #
192+
* # 1/look-ma.txt
193+
* # new_untracked_file.txt
194+
*/
195+
140196
RepositoryStatus status = repo.Index.RetrieveStatus();
141197

142198
Assert.Equal(new[]{relativePath, "new_untracked_file.txt"}, status.Untracked);
143199

144200
string gitignorePath = Path.Combine(repo.Info.WorkingDirectory, ".gitignore");
145201
File.WriteAllText(gitignorePath, "*.txt" + Environment.NewLine);
146202

203+
/*
204+
* $ git status --ignored
205+
* # On branch master
206+
* # Your branch and 'origin/master' have diverged,
207+
* # and have 2 and 2 different commit(s) each, respectively.
208+
* #
209+
* # Changes to be committed:
210+
* # (use "git reset HEAD <file>..." to unstage)
211+
* #
212+
* # deleted: deleted_staged_file.txt
213+
* # modified: modified_staged_file.txt
214+
* # new file: new_tracked_file.txt
215+
* #
216+
* # Changes not staged for commit:
217+
* # (use "git add/rm <file>..." to update what will be committed)
218+
* # (use "git checkout -- <file>..." to discard changes in working directory)
219+
* #
220+
* # modified: 1/branch_file.txt
221+
* # modified: README
222+
* # modified: branch_file.txt
223+
* # deleted: deleted_unstaged_file.txt
224+
* # modified: modified_unstaged_file.txt
225+
* # modified: new.txt
226+
* #
227+
* # Untracked files:
228+
* # (use "git add <file>..." to include in what will be committed)
229+
* #
230+
* # .gitignore
231+
* # Ignored files:
232+
* # (use "git add -f <file>..." to include in what will be committed)
233+
* #
234+
* # 1/look-ma.txt
235+
* # new_untracked_file.txt
236+
*/
237+
147238
RepositoryStatus newStatus = repo.Index.RetrieveStatus();
148239
newStatus.Untracked.Single().ShouldEqual(".gitignore");
149240

0 commit comments

Comments
 (0)
0