From 20e03ee3463817f1de787b48ab029aef43f98e89 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Sun, 12 Feb 2017 14:08:08 -0500 Subject: [PATCH 1/2] Stage/Unstage: ensure we write the index Ensure that `Commands.Stage` and `Commands.Unstage` write the index. --- LibGit2Sharp.Tests/StageFixture.cs | 18 ++++++++++++++++++ LibGit2Sharp.Tests/UnstageFixture.cs | 19 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/LibGit2Sharp.Tests/StageFixture.cs b/LibGit2Sharp.Tests/StageFixture.cs index b606a745e..ca01c95a1 100644 --- a/LibGit2Sharp.Tests/StageFixture.cs +++ b/LibGit2Sharp.Tests/StageFixture.cs @@ -33,6 +33,24 @@ public void CanStage(string relativePath, FileStatus currentStatus, bool doesCur } } + [Theory] + [InlineData("deleted_unstaged_file.txt", FileStatus.DeletedFromIndex)] + [InlineData("modified_unstaged_file.txt", FileStatus.ModifiedInIndex)] + [InlineData("new_untracked_file.txt", FileStatus.NewInIndex)] + public void StagingWritesIndex(string relativePath, FileStatus expectedStatus) + { + string path = SandboxStandardTestRepo(); + using (var repo = new Repository(path)) + { + Commands.Stage(repo, relativePath); + } + + using (var repo = new Repository(path)) + { + Assert.Equal(expectedStatus, repo.RetrieveStatus(relativePath)); + } + } + [Fact] public void CanStageTheUpdationOfAStagedFile() { diff --git a/LibGit2Sharp.Tests/UnstageFixture.cs b/LibGit2Sharp.Tests/UnstageFixture.cs index 786ed14c7..e36510ba7 100644 --- a/LibGit2Sharp.Tests/UnstageFixture.cs +++ b/LibGit2Sharp.Tests/UnstageFixture.cs @@ -84,6 +84,25 @@ public void CanUnstage( } } + + [Theory] + [InlineData("modified_staged_file.txt", FileStatus.ModifiedInWorkdir)] + [InlineData("new_tracked_file.txt", FileStatus.NewInWorkdir)] + [InlineData("deleted_staged_file.txt", FileStatus.DeletedFromWorkdir)] + public void UnstagingWritesIndex(string relativePath, FileStatus expectedStatus) + { + string path = SandboxStandardTestRepo(); + using (var repo = new Repository(path)) + { + Commands.Unstage(repo, relativePath); + } + + using (var repo = new Repository(path)) + { + Assert.Equal(expectedStatus, repo.RetrieveStatus(relativePath)); + } + } + [Theory] [InlineData("new_untracked_file.txt", FileStatus.NewInWorkdir)] [InlineData("where-am-I.txt", FileStatus.Nonexistent)] From 119e59482552225bc9c4f01d4b911d23e552299c Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Sun, 12 Feb 2017 14:08:30 -0500 Subject: [PATCH 2/2] Commands.Unstage: write the index --- LibGit2Sharp/Commands/Stage.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/LibGit2Sharp/Commands/Stage.cs b/LibGit2Sharp/Commands/Stage.cs index 9917ca52a..a1febafcb 100644 --- a/LibGit2Sharp/Commands/Stage.cs +++ b/LibGit2Sharp/Commands/Stage.cs @@ -199,6 +199,8 @@ public static void Unstage(IRepository repository, IEnumerable paths, Ex { repository.Index.Replace(repository.Head.Tip, paths, explicitPathsOptions); } + + repository.Index.Write(); } ///