|
1 | 1 | using System.Collections.Generic;
|
| 2 | +using System.IO; |
2 | 3 | using System.Linq;
|
3 | 4 | using LibGit2Sharp.Tests.TestHelpers;
|
4 | 5 | using Xunit;
|
@@ -26,6 +27,50 @@ public static IEnumerable<object[]> ConflictData
|
26 | 27 | }
|
27 | 28 | }
|
28 | 29 |
|
| 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 | + |
29 | 74 | [Theory, PropertyData("ConflictData")]
|
30 | 75 | public void CanRetrieveSingleConflictByPath(string filepath, string ancestorId, string ourId, string theirId)
|
31 | 76 | {
|
|
0 commit comments