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)] 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(); } ///