|
1 | 1 | using System;
|
2 | 2 | using System.IO;
|
3 | 3 | using System.Linq;
|
| 4 | +using System.Text; |
4 | 5 | using LibGit2Sharp.Tests.TestHelpers;
|
5 | 6 | using Xunit;
|
6 | 7 | using Xunit.Extensions;
|
@@ -310,5 +311,41 @@ private static void AssertStatus(bool shouldIgnoreCase, FileStatus expectedFileS
|
310 | 311 | Assert.False(shouldIgnoreCase);
|
311 | 312 | }
|
312 | 313 | }
|
| 314 | + |
| 315 | + [Fact] |
| 316 | + public void RetrievingTheStatusOfTheRepositoryHonorsTheGitIgnoreDirectivesThroughoutDirectories() |
| 317 | + { |
| 318 | + char dirSep = Path.DirectorySeparatorChar; |
| 319 | + |
| 320 | + string path = CloneStandardTestRepo(); |
| 321 | + using (var repo = new Repository(path)) |
| 322 | + { |
| 323 | + Touch(repo.Info.WorkingDirectory, "bin/look-ma.txt", "I'm going to be ignored!"); |
| 324 | + Touch(repo.Info.WorkingDirectory, "bin/what-about-me.txt", "Huh?"); |
| 325 | + |
| 326 | + string gitignorePath = Path.Combine(repo.Info.WorkingDirectory, ".gitignore"); |
| 327 | + |
| 328 | + File.WriteAllText(gitignorePath, "bin"); |
| 329 | + |
| 330 | + Assert.Equal(FileStatus.Ignored, repo.Index.RetrieveStatus("bin/look-ma.txt")); |
| 331 | + Assert.Equal(FileStatus.Ignored, repo.Index.RetrieveStatus("bin/what-about-me.txt")); |
| 332 | + |
| 333 | + RepositoryStatus newStatus = repo.Index.RetrieveStatus(); |
| 334 | + Assert.Equal(new[] { "bin" + dirSep }, newStatus.Ignored); |
| 335 | + |
| 336 | + var sb = new StringBuilder(); |
| 337 | + sb.AppendLine("bin/*"); |
| 338 | + sb.AppendLine("!bin/w*"); |
| 339 | + File.WriteAllText(gitignorePath, sb.ToString()); |
| 340 | + |
| 341 | + Assert.Equal(FileStatus.Ignored, repo.Index.RetrieveStatus("bin/look-ma.txt")); |
| 342 | + Assert.Equal(FileStatus.Untracked, repo.Index.RetrieveStatus("bin/what-about-me.txt")); |
| 343 | + |
| 344 | + newStatus = repo.Index.RetrieveStatus(); |
| 345 | + |
| 346 | + Assert.Equal(new[] { "bin" + dirSep + "look-ma.txt" }, newStatus.Ignored); |
| 347 | + Assert.True(newStatus.Untracked.Contains("bin" + dirSep + "what-about-me.txt" )); |
| 348 | + } |
| 349 | + } |
313 | 350 | }
|
314 | 351 | }
|
0 commit comments