Skip to content

Commit 8aaeee1

Browse files
committed
Checkout test verifying that Checkout does not remove ignored directories
1 parent bf722af commit 8aaeee1

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

LibGit2Sharp.Tests/CheckoutFixture.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Linq;
23
using LibGit2Sharp.Tests.TestHelpers;
34
using Xunit;
45
using Xunit.Extensions;
@@ -325,6 +326,39 @@ public void CheckingOutThroughRepositoryCallsCheckoutProgress()
325326
}
326327
}
327328

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+
328362
/// <summary>
329363
/// Helper method to populate a simple repository with
330364
/// a single file and two branches.

0 commit comments

Comments
 (0)