8000 repo.Reset() renamed items correctly · GiTechLab/libgit2sharp@fcb3711 · GitHub
[go: up one dir, main page]

Skip to content

Commit fcb3711

Browse files
author
Edward Thomson
committed
repo.Reset() renamed items correctly
1 parent 19cd630 commit fcb3711

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

LibGit2Sharp.Tests/ResetIndexFixture.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,59 @@ public void ResettingTheIndexToASubsetOfTheContentOfACommitWithCommitAsArgumentA
151151
repo.Reset(repo.Lookup<Commit>("5b5b025"), new[] { "new.txt", "non-existent-path-28.txt" }, new ExplicitPathsOptions()));
152152
}
153153
}
154+
155+
[Fact]
156+
public void CanResetTheIndexWhenARenameExists()
157+
{
158+
using (var repo = new Repository(CloneStandardTestRepo()))
159+
{
160+
repo.Index.Move("branch_file.txt", "renamed_branch_file.txt");
161+
repo.Reset(repo.Lookup<Commit>("32eab9c"));
162+
163+
RepositoryStatus status = repo.Index.RetrieveStatus();
164+
Assert.Equal(0, status.Where(IsStaged).Count());
165+
}
166+
}
167+
168+
[Fact]
169+
public void CanResetSourceOfARenameInIndex()
170+
{
171+
using (var repo = new Repository(CloneStandardTestRepo()))
172+
{
173+
repo.Index.Move("branch_file.txt", "renamed_branch_file.txt");
174+
175+
RepositoryStatus oldStatus = repo.Index.RetrieveStatus();
176+
Assert.Equal(1, oldStatus.RenamedInIndex.Count());
177+
Assert.Equal(FileStatus.Nonexistent, oldStatus["branch_file.txt"].State);
178+
Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State);
179+
180+
repo.Reset(repo.Lookup<Commit>("32eab9c"), new string[] { "branch_file.txt" });
181+
182+
RepositoryStatus newStatus = repo.Index.RetrieveStatus();
183+
Assert.Equal(0, newStatus.RenamedInIndex.Count());
184+
Assert.Equal(FileStatus.Missing, newStatus["branch_file.txt"].State);
185+
Assert.Equal(FileStatus.Added, newStatus["renamed_branch_file.txt"].State);
186+
}
187+
}
188+
189+
[Fact]
190+
public void CanResetTargetOfARenameInIndex()
191+
{
192+
using (var repo = new Repository(CloneStandardTestRepo()))
193+
{
194+
repo.Index.Move("branch_file.txt", "renamed_branch_file.txt");
195+
196+
RepositoryStatus oldStatus = repo.Index.RetrieveStatus();
197+
Assert.Equal(1, oldStatus.RenamedInIndex.Count());
198+
Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State);
199+
200+
repo.Reset(repo.Lookup<Commit>("32eab9c"), new string[] { "renamed_branch_file.txt" });
201+
202+
RepositoryStatus newStatus = repo.Index.RetrieveStatus();
203+
Assert.Equal(0, newStatus.RenamedInIndex.Count());
204+
Assert.Equal(FileStatus.Untracked, newStatus["renamed_branch_file.txt"].State);
205+
Assert.Equal(FileStatus.Removed, newStatus["branch_file.txt"].State);
206+
}
207+
}
154208
}
155209
}

LibGit2Sharp/Repository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ public void Reset(Commit commit, IEnumerable<string> paths = null, ExplicitPaths
792792

793793
Ensure.ArgumentNotNull(commit, "commit");
794794

795-
var changes = Diff.Compare<TreeChanges>(commit.Tree, DiffTargets.Index, paths, explicitPathsOptions);
795+
var changes = Diff.Compare<TreeChanges>(commit.Tree, DiffTargets.Index, paths, explicitPathsOptions, new CompareOptions { Similarity = SimilarityOptions.None });
796796
Index.Reset(changes);
797797
}
798798

0 commit comments

Comments
 (0)
0