From fcb3711c64f535b57fb4e73c21d977e4fc13121f Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 19 Jun 2014 13:07:19 -0500 Subject: [PATCH 1/2] repo.Reset() renamed items correctly --- LibGit2Sharp.Tests/ResetIndexFixture.cs | 54 +++++++++++++++++++++++++ LibGit2Sharp/Repository.cs | 2 +- 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/LibGit2Sharp.Tests/ResetIndexFixture.cs b/LibGit2Sharp.Tests/ResetIndexFixture.cs index 23e6a1cc4..0e774cd7e 100644 --- a/LibGit2Sharp.Tests/ResetIndexFixture.cs +++ b/LibGit2Sharp.Tests/ResetIndexFixture.cs @@ -151,5 +151,59 @@ public void ResettingTheIndexToASubsetOfTheContentOfACommitWithCommitAsArgumentA repo.Reset(repo.Lookup("5b5b025"), new[] { "new.txt", "non-existent-path-28.txt" }, new ExplicitPathsOptions())); } } + + [Fact] + public void CanResetTheIndexWhenARenameExists() + { + using (var repo = new Repository(CloneStandardTestRepo())) + { + repo.Index.Move("branch_file.txt", "renamed_branch_file.txt"); + repo.Reset(repo.Lookup("32eab9c")); + + RepositoryStatus status = repo.Index.RetrieveStatus(); + Assert.Equal(0, status.Where(IsStaged).Count()); + } + } + + [Fact] + public void CanResetSourceOfARenameInIndex() + { + using (var repo = new Repository(CloneStandardTestRepo())) + { + repo.Index.Move("branch_file.txt", "renamed_branch_file.txt"); + + RepositoryStatus oldStatus = repo.Index.RetrieveStatus(); + Assert.Equal(1, oldStatus.RenamedInIndex.Count()); + Assert.Equal(FileStatus.Nonexistent, oldStatus["branch_file.txt"].State); + Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State); + + repo.Reset(repo.Lookup("32eab9c"), new string[] { "branch_file.txt" }); + + RepositoryStatus newStatus = repo.Index.RetrieveStatus(); + Assert.Equal(0, newStatus.RenamedInIndex.Count()); + Assert.Equal(FileStatus.Missing, newStatus["branch_file.txt"].State); + Assert.Equal(FileStatus.Added, newStatus["renamed_branch_file.txt"].State); + } + } + + [Fact] + public void CanResetTargetOfARenameInIndex() + { + using (var repo = new Repository(CloneStandardTestRepo())) + { + repo.Index.Move("branch_file.txt", "renamed_branch_file.txt"); + + RepositoryStatus oldStatus = repo.Index.RetrieveStatus(); + Assert.Equal(1, oldStatus.RenamedInIndex.Count()); + Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State); + + repo.Reset(repo.Lookup("32eab9c"), new string[] { "renamed_branch_file.txt" }); + + RepositoryStatus newStatus = repo.Index.RetrieveStatus(); + Assert.Equal(0, newStatus.RenamedInIndex.Count()); + Assert.Equal(FileStatus.Untracked, newStatus["renamed_branch_file.txt"].State); + Assert.Equal(FileStatus.Removed, newStatus["branch_file.txt"].State); + } + } } } diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index a0b5df92c..54791a8ed 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -792,7 +792,7 @@ public void Reset(Commit commit, IEnumerable paths = null, ExplicitPaths Ensure.ArgumentNotNull(commit, "commit"); - var changes = Diff.Compare(commit.Tree, DiffTargets.Index, paths, explicitPathsOptions); + var changes = Diff.Compare(commit.Tree, DiffTargets.Index, paths, explicitPathsOptions, new CompareOptions { Similarity = SimilarityOptions.None }); Index.Reset(changes); } From 2378a56fadea4b9cdd57e0abead4c5fd061567bc Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 19 Jun 2014 13:18:50 -0500 Subject: [PATCH 2/2] repo.Unstage() renamed items correctly --- LibGit2Sharp.Tests/UnstageFixture.cs | 55 ++++++++++++++++++++++++++++ LibGit2Sharp/Index.cs | 2 +- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/LibGit2Sharp.Tests/UnstageFixture.cs b/LibGit2Sharp.Tests/UnstageFixture.cs index fea1aea3b..47562a6fe 100644 --- a/LibGit2Sharp.Tests/UnstageFixture.cs +++ b/LibGit2Sharp.Tests/UnstageFixture.cs @@ -233,5 +233,60 @@ public void UnstagingFileWithBadParamsThrows() Assert.Throws(() => repo.Index.Unstage(new string[] { null })); } } + + [Fact] + public void CanUnstageSourceOfARename() + { + using (var repo = new Repository(CloneStandardTestRepo())) + { + repo.Index.Move("branch_file.txt", "renamed_branch_file.txt"); + + RepositoryStatus oldStatus = repo.Index.RetrieveStatus(); + Assert.Equal(1, oldStatus.RenamedInIndex.Count()); + Assert.Equal(FileStatus.Nonexistent, oldStatus["branch_file.txt"].State); + Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State); + + repo.Index.Unstage(new string[] { "branch_file.txt" }); + + RepositoryStatus newStatus = repo.Index.RetrieveStatus(); + Assert.Equal(0, newStatus.RenamedInIndex.Count()); + Assert.Equal(FileStatus.Missing, newStatus["branch_file.txt"].State); + Assert.Equal(FileStatus.Added, newStatus["renamed_branch_file.txt"].State); + } + } + + [Fact] + public void CanUnstageTargetOfARename() + { + using (var repo = new Repository(CloneStandardTestRepo())) + { + repo.Index.Move("branch_file.txt", "renamed_branch_file.txt"); + + RepositoryStatus oldStatus = repo.Index.RetrieveStatus(); + Assert.Equal(1, oldStatus.RenamedInIndex.Count()); + Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State); + + repo.Index.Unstage(new string[] { "renamed_branch_file.txt" }); + + RepositoryStatus newStatus = repo.Index.RetrieveStatus(); + Assert.Equal(0, newStatus.RenamedInIndex.Count()); + Assert.Equal(FileStatus.Untracked, newStatus["renamed_branch_file.txt"].State); + Assert.Equal(FileStatus.Removed, newStatus["branch_file.txt"].State); + } + } + + [Fact] + public void CanUnstageBothSidesOfARename() + { + using (var repo = new Repository(CloneStandardTestRepo())) + { + repo.Index.Move("branch_file.txt", "renamed_branch_file.txt"); + repo.Index.Unstage(new string[] { "branch_file.txt", "renamed_branch_file.txt" }); + + RepositoryStatus status = repo.Index.RetrieveStatus(); + Assert.Equal(FileStatus.Missing, status["branch_file.txt"].State); + Assert.Equal(FileStatus.Untracked, status["renamed_branch_file.txt"].State); + } + } } } diff --git a/LibGit2Sharp/Index.cs b/LibGit2Sharp/Index.cs index e953910dc..ee5e02979 100644 --- a/LibGit2Sharp/Index.cs +++ b/LibGit2Sharp/Index.cs @@ -211,7 +211,7 @@ public virtual void Unstage(IEnumerable paths, ExplicitPathsOptions expl if (repo.Info.IsHeadUnborn) { - var changes = repo.Diff.Compare(null, DiffTargets.Index, paths, explicitPathsOptions); + var changes = repo.Diff.Compare(null, DiffTargets.Index, paths, explicitPathsOptions, new CompareOptions { Similarity = SimilarityOptions.None }); Reset(changes); }