8000 Introduce Repository.Conflicts · mm201/libgit2sharp@e808fb6 · GitHub
[go: up one dir, main page]

Skip to content

Commit e808fb6

Browse files
Edward Thomsonnulltoken
authored andcommitted
Introduce Repository.Conflicts
1 parent 048ab3c commit e808fb6

File tree

76 files changed

+482
-33
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+482
-33
lines changed

LibGit2Sharp.Tests/ConflictFixture.cs

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
using LibGit2Sharp.Tests.TestHelpers;
4+
using Xunit;
5+
using Xunit.Extensions;
6+
7+
namespace LibGit2Sharp.Tests
8+
{
9+
public class ConflictFixture : BaseFixture
10+
{
11+
public static IEnumerable<object[]> ConflictData
12+
{
13+
get
14+
{
15+
return new[]
16+
{
17+
new string[] { "ancestor-and-ours.txt", "5dee68477001f447f50fa7ee7e6a818370b5c2fb", "dad0664ae617d36e464ec08ed969ff496432b075", null },
18+
new string[] { "ancestor-and-theirs.txt", "3aafd4d0bac33cc3c78c4c070f3966fb6e6f641a", null, "7b26cd5ac0ee68483ae4d5e1e00b064547ea8c9b" },
19+
new string[] { "ancestor-only.txt", "9736f4cd77759672322f3222ed3ddead1412d969", null, null },
20+
new string[] { "conflicts-one.txt", "1f85ca51b8e0aac893a621b61a9c2661d6aa6d81", "b7a41c703dc1f33185c76944177f3844ede2ee46", "516bd85f78061e09ccc714561d7b504672cb52da" },
21+
new string[] { "conflicts-two.txt", "84af62840be1b1c47b778a8a249f3ff45155038c", "ef70c7154145b09c7d08806e55fd0bfb7172576d", "220bd62631c8cf7a83ef39c6b94595f00517211e" },
22+
new string[] { "ours-and-theirs.txt", null, "9aaa9ae562a5f7362425a3fedc4d33ff74fe39e6", "0ca3f55d4ac2fa4703c149123b0b31d733112f86" },
23+
new string[] { "ours-only.txt", null, "9736f4cd77759672322f3222ed3ddead1412d969", null },
24+
new string[] { "theirs-only.txt", null, null, "9736f4cd77759672322f3222ed3ddead1412d969" },
25+
};
26+
}
27+
}
28+
29+
[Theory, PropertyData("ConflictData")]
30+
public void CanRetrieveSingleConflictByPath(string filepath, string ancestorId, string ourId, string theirId)
31+
{
32+
using (var repo = new Repository(MergedTestRepoWorkingDirPath))
33+
{
34+
Conflict conflict = repo.Conflicts[filepath];
35+
Assert.NotNull(conflict);
36+
37+
ObjectId expectedAncestor = ancestorId != null ? new ObjectId(ancestorId) : null;
38+
ObjectId expectedOurs = ourId != null ? new ObjectId(ourId) : null;
39+
ObjectId expectedTheirs = theirId != null ? new ObjectId(theirId) : null;
40+
41+
Assert.Null(repo.Index[filepath]);
42+
Assert.Equal(expectedAncestor, conflict.Ancestor != null ? conflict.Ancestor.Id : null);
43+
Assert.Equal(expectedOurs, conflict.Ours != null ? conflict.Ours.Id : null);
44+
Assert.Equal(expectedTheirs, conflict.Theirs != null ? conflict.Theirs.Id : null);
45+
}
46+
}
47+
48+
private string GetPath(Conflict conflict)
49+
{
50+
if (conflict.Ancestor != null)
51+
{
52+
return conflict.Ancestor.Path;
53+
}
54+
if (conflict.Ours != null)
55+
{
56+
return conflict.Ours.Path;
57+
}
58+
if (conflict.Theirs != null)
59+
{
60+
return conflict.Theirs.Path;
61+
}
62+
63+
return null;
64+
}
65+
66+
private string GetId(IndexEntry e)
67+
{
68+
if (e == null)
69+
{
70+
return null;
71+
}
72+
73+
return e.Id.ToString();
74+
}
75+
76+
[Fact]
77+
public void CanRetrieveAllConflicts()
78+
{
79+
using (var repo = new Repository(MergedTestRepoWorkingDirPath))
80+
{
81+
var expected = repo.Conflicts.Select(c => new string[] { GetPath(c), GetId(c.Ancestor), GetId(c.Ours), GetId(c.Theirs) }).ToArray();
82+
Assert.Equal(expected, ConflictData);
83+
}
84+
}
85+
}
86+
}

LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<ItemGroup>
6060
<Compile Include="CheckoutFixture.cs" />
6161
<Compile Include="CloneFixture.cs" />
62+
<Compile Include="ConflictFixture.cs" />
6263
<Compile Include="IgnoreFixture.cs" />
6364
<Compile Include="FetchHeadFixture.cs" />
6465
<Compile Include="MergeFixture.cs" />
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
this file is modified in
2+
the "ours" side and deleted
3+
in the "theirs" side so that
4+
a conflict will only include
5+
the ancestor and ours side
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
this file will be modified
2+
in the "theirs" side from the
3+
"ancestor" side, but will be
4+
deleted from the "ours" side
5+
to test that we can handle
6+
a missing "ours" side conflict
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<<<<<<< HEAD
2-
This is most certainly a conflict!
2+
!This is a conflict!
33
=======
44
This is a conflict!!!
55
>>>>>>> branch
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<<<<<<< HEAD
2-
This is without question another conflict!
2+
!This is another conflict!
33
=======
44
This is another conflict!!!
55
>>>>>>> branch

LibGit2Sharp.Tests/Resources/mergedrepo_wd/dot_git/COMMITMESSAGE

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
master
1+
# This is a combination of 2 commits.
2+
# The first commit's message is:
3+
4+
branch
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e2809157a7766f272e4cfe26e61ef2678a5357ff
1+
8eefb6f8061e4d10a7a59aac8771dc17958d93eb
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
Merge branch 'branch'
22

33
Conflicts:
4+
ancestor-and-ours.txt
5+
ancestor-and-theirs.txt
6+
ancestor-only.txt
47
conflicts-one.txt
58
conflicts-two.txt
9+
ours-and-theirs.txt
10+
ours-only.txt
11+
theirs-only.txt

0 commit comments

Comments
 (0)
0