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

Skip to content

Commit 2378a56

Browse files
author
Edward Thomson
committed
repo.Unstage() renamed items correctly
1 parent fcb3711 commit 2378a56

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

LibGit2Sharp.Tests/UnstageFixture.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,5 +233,60 @@ public void UnstagingFileWithBadParamsThrows()
233233
Assert.Throws<ArgumentException>(() => repo.Index.Unstage(new string[] { null }));
234234
}
235235
}
236+
237+
[Fact]
238+
public void CanUnstageSourceOfARename()
239+
{
240+
using (var repo = new Repository(CloneStandardTestRepo()))
241+
{
242+
repo.Index.Move("branch_file.txt", "renamed_branch_file.txt");
243+
244+
RepositoryStatus oldStatus = repo.Index.RetrieveStatus();
245+
Assert.Equal(1, oldStatus.RenamedInIndex.Count());
246+
Assert.Equal(FileStatus.Nonexistent, oldStatus["branch_file.txt"].State);
247+
Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State);
248+
249+
repo.Index.Unstage(new string[] { "branch_file.txt" });
250+
251+
RepositoryStatus newStatus = repo.Index.RetrieveStatus();
252+
Assert.Equal(0, newStatus.RenamedInIndex.Count());
253+
Assert.Equal(FileStatus.Missing, newStatus["branch_file.txt"].State);
254+
Assert.Equal(FileStatus.Added, newStatus["renamed_branch_file.txt"].State);
255+
}
256+
}
257+
258+
[Fact]
259+
public void CanUnstageTargetOfARename()
260+
{
261+
using (var repo = new Repository(CloneStandardTestRepo()))
262+
{
263+
repo.Index.Move("branch_file.txt", "renamed_branch_file.txt");
264+
265+
RepositoryStatus oldStatus = repo.Index.RetrieveStatus();
266+
Assert.Equal(1, oldStatus.RenamedInIndex.Count());
267+
Assert.Equal(FileStatus.RenamedInIndex, oldStatus["renamed_branch_file.txt"].State);
268+
269+
repo.Index.Unstage(new string[] { "renamed_branch_file.txt" });
270+
271+
RepositoryStatus newStatus = repo.Index.RetrieveStatus();
272+
Assert.Equal(0, newStatus.RenamedInIndex.Count());
273+
Assert.Equal(FileStatus.Untracked, newStatus["renamed_branch_file.txt"].State);
274+
Assert.Equal(FileStatus.Removed, newStatus["branch_file.txt"].State);
275+
}
276+
}
277+
278+
[Fact]
279+
public void CanUnstageBothSidesOfARename()
280+
{
281+
using (var repo = new Repository(CloneStandardTestRepo()))
282+
{
283+
repo.Index.Move("branch_file.txt", "renamed_branch_file.txt");
284+
repo.Index.Unstage(new string[] { "branch_file.txt", "renamed_branch_file.txt" });
285+
286+
RepositoryStatus status = repo.Index.RetrieveStatus();
287+
Assert.Equal(FileStatus.Missing, status["branch_file.txt"].State);
288+
Assert.Equal(FileStatus.Untracked, status["renamed_branch_file.txt"].State);
289+
}
290+
}
236291
}
237292
}

LibGit2Sharp/Index.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ public virtual void Unstage(IEnumerable<string> paths, ExplicitPathsOptions expl
211211

212212
if (repo.Info.IsHeadUnborn)
213213
{
214-
var changes = repo.Diff.Compare<TreeChanges>(null, DiffTargets.Index, paths, explicitPathsOptions);
214+
var changes = repo.Diff.Compare<TreeChanges>(null, DiffTargets.Index, paths, explicitPathsOptions, new CompareOptions { Similarity = SimilarityOptions.None });
215215

216216
Reset(changes);
217217
}

0 commit comments

Comments
 (0)
0