10000 Add test to ensure conflicts are cleared when calling Index.Remove() · leoniDEV/libgit2sharp@56eb34b · GitHub
[go: up one dir, main page]

Skip to content

Commit 56eb34b

Browse files
yorahnulltoken
authored andcommitted
Add test to ensure conflicts are cleared when calling Index.Remove()
Beware, this is supported only for files which exist in the workdir (cf. comment in code). Partially fixes libgit2#325
1 parent bd1ef45 commit 56eb34b

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

LibGit2Sharp.Tests/ConflictFixture.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Collections.Generic;
2+
using System.IO;
23
using System.Linq;
34
using LibGit2Sharp.Tests.TestHelpers;
45
using Xunit;
@@ -26,6 +27,50 @@ public static IEnumerable<object[]> ConflictData
2627
}
2728
}
2829

30+
[Theory]
31+
[InlineData(true, "ancestor-and-ours.txt", true, false, FileStatus.Removed, 2)]
32+
[InlineData(false, "ancestor-and-ours.txt", true, true, FileStatus.Removed |FileStatus.Untracked, 2)]
33+
[InlineData(true, "ancestor-and-theirs.txt", true, false, FileStatus.Nonexistent, 2)]
34+
[InlineData(false, "ancestor-and-theirs.txt", true, true, FileStatus.Untracked, 2)]
35+
[InlineData(true, "conflicts-one.txt", true, false, FileStatus.Removed, 3)]
36+
[InlineData(false, "conflicts-one.txt", true, true, FileStatus.Removed | FileStatus.Untracked, 3)]
37+
[InlineData(true, "conflicts-two.txt", true, false, FileStatus.Removed, 3)]
38+
[InlineData(false, "conflicts-two.txt", true, true, FileStatus.Removed | FileStatus.Untracked, 3)]
39+
[InlineData(true, "ours-and-theirs.txt", true, false, FileStatus.Removed, 2)]
40+
[InlineData(false, "ours-and-theirs.txt", true, true, FileStatus.Removed | FileStatus.Untracked, 2)]
41+
[InlineData(true, "ours-only.txt", true, false, FileStatus.Removed, 1)]
42+
[InlineData(false, "ours-only.txt", true, true, FileStatus.Removed | FileStatus.Untracked, 1)]
43+
[InlineData(true, "theirs-only.txt", true, false, FileStatus.Nonexistent, 1)]
44+
[InlineData(false, "theirs-only.txt", true, true, FileStatus.Untracked, 1)]
45+
/* Conflicts clearing through Index.Remove() only works when a version of the entry exists in the workdir.
46+
* This is because libgit2's git_iterator_for_index() seem to only care about stage level 0.
47+
* Corrolary: other cases only work out of sheer luck (however, the behaviour is stable, so I guess we
48+
* can rely on it for the moment.
49+
* [InlineData(true, "ancestor-only.txt", false, false, FileStatus.Nonexistent, 0)]
50+
* [InlineData(false, "ancestor-only.txt", false, false, FileStatus.Nonexistent, 0)]
51+
*/
52+
public void CanClearConflictsByRemovingFromTheIndex(
53+
bool removeFromWorkdir, string filename, bool existsBeforeRemove, bool existsAfterRemove, FileStatus lastStatus, int removedIndexEntries)
54+
{
55+
var path = CloneMergedTestRepo();
56+
using (var repo = new Repository(path))
57+
{
58+
int count = repo.Index.Count;
59+
60+
string fullpath = Path.Combine(repo.Info.WorkingDirectory, filename);
61+
62+
Assert.Equal(existsBeforeRemove, File.Exists(fullpath));
63+
Assert.NotNull(repo.Conflicts[filename]);
64+
65+
repo.Index.Remove(filename, removeFromWorkdir);
66+
67+
Assert.Null(repo.Conflicts[filename]);
68+
Assert.Equal(count - removedIndexEntries, repo.Index.Count);
69+
Assert.Equal(existsAfterRemove, File.Exists(fullpath));
70+
Assert.Equal(lastStatus, repo.Index.RetrieveStatus(filename));
71+
}
72+
}
73+
2974
[Theory, PropertyData("ConflictData")]
3075
public void CanRetrieveSingleConflictByPath(string filepath, string ancestorId, string ourId, string theirId)
3176
{

0 commit comments

Comments
 (0)
0