|
1 | 1 | using System;
|
| 2 | +using System.Linq; |
2 | 3 | using LibGit2Sharp.Tests.TestHelpers;
|
3 | 4 | using Xunit;
|
4 | 5 | using Xunit.Extensions;
|
@@ -325,6 +326,39 @@ public void CheckingOutThroughRepositoryCallsCheckoutProgress()
|
325 | 326 | }
|
326 | 327 | }
|
327 | 328 |
|
| 329 | + [Fact] |
| 330 | + public void CheckoutLeavesUntrackedDirectory() |
| 331 | + { |
| 332 | + SelfCleaningDirectory scd = BuildSelfCleaningDirectory(); |
| 333 | + |
| 334 | + using (var repo = Repository.Init(scd.DirectoryPath)) |
| 335 | + { |
| 336 | + PopulateBasicRepository(repo); |
| 337 | + |
| 338 | + // Generate a .gitignore file |
| 339 | + string gitIgnoreFilePath = Path.Combine(repo.Info.WorkingDirectory, ".gitignore"); |
| 340 | + File.WriteAllText(gitIgnoreFilePath, ".bin"); |
| 341 | + repo.Index.Stage(gitIgnoreFilePath); |
| 342 | + repo.Commit("Add git ignore file", Constants.Signature, Constants.Signature); |
| 343 | + |
| 344 | + // Create a bin directory |
| 345 | + string ignoredDirectoryPath = Path.Combine(repo.Info.WorkingDirectory, "bin"); |
| 346 | + Directory.CreateDirectory(ignoredDirectoryPath); |
| 347 | + |
| 348 | + // Create file in ignored bin directory |
| 349 | + string ignoredFilePath = Path.Combine(repo.Info.WorkingDirectory, Path.Combine("bin", "some_ignored_file.txt")); |
| 350 | + File.WriteAllText(ignoredFilePath, "hello from this ignored file."); |
| 351 | + |
| 352 | + // Verify that there is an untracked entry |
| 353 | + Assert.Equal(1, repo.Index.RetrieveStatus().Untracked.Count()); |
| 354 | + |
| 355 | + repo.Checkout(otherBranchName, CheckoutOptions.Force, null); |
| 356 | + |
| 357 | + Assert.True(Directory.Exists(ignoredDirectoryPath)); |
| 358 | + Assert.True(File.Exists(ignoredFilePath)); |
| 359 | + } |
| 360 | + } |
| 361 | + |
328 | 362 | /// <summary>
|
329 | 363 | /// Helper method to populate a simple repository with
|
330 | 364 | /// a single file and two branches.
|
|
0 commit comments