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

Skip to content

Commit e808fb6

Browse files
Edward Thomsonnulltoken
Edward Thomson
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
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3a34580a35add43a4cf361e8e9a30060a905c876
1+
9b2f98b1c086d3929eac387d39fae94425e0115f
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[core]
22
repositoryformatversion = 0
3-
filemode = true
3+
filemode = false
44
bare = false
55
logallrefupdates = true
6+
symlinks = false
67
ignorecase = true
8+
hideDotFiles = dotGitOnly
Binary file not shown.
Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
1-
0000000000000000000000000000000000000000 9a05ccb4e0f948de03128e095f39dae6976751c5 Edward Thomson <ethomson@edwardthomson.com> 1351371828 -0500 commit (initial): initial
2-
9a05ccb4e0f948de03128e095f39dae6976751c5 9a05ccb4e0f948de03128e095f39dae6976751c5 Edward Thomson <ethomson@edwardthomson.com> 1351371835 -0500 checkout: moving from master to branch
3-
9a05ccb4e0f948de03128e095f39dae6976751c5 e2809157a7766f272e4cfe26e61ef2678a5357ff Edward Thomson <ethomson@edwardthomson.com> 1351371872 -0500 commit: branch
4-
e2809157a7766f272e4cfe26e61ef2678a5357ff 9a05ccb4e0f948de03128e095f39dae6976751c5 Edward Thomson <ethomson@edwardthomson.com> 1351371873 -0500 checkout: moving from branch to master
5-
9a05ccb4e0f948de03128e095f39dae6976751c5 3a34580a35add43a4cf361e8e9a30060a905c876 Edward Thomson <ethomson@edwardthomson.com> 1351372106 -0500 commit: master
1+
0000000000000000000000000000000000000000 9107b30fe11ff310fec93876469147b263fb958c Edward Thomson <ethomson@microsoft.com> 1360632480 -0600 commit (initial): ancestor
2+
9107b30fe11ff310fec93876469147b263fb958c 9107b30fe11ff310fec93876469147b263fb958c Edward Thomson <ethomson@microsoft.com> 1360632483 -0600 checkout: moving from master to branch
3+
9107b30fe11ff310fec93876469147b263fb958c d4c107581ff54a41fd496e0a1f1b7b3354752103 Edward Thomson <ethomson@microsoft.com> 1360632833 -0600 commit: branch
4+
d4c107581ff54a41fd496e0a1f1b7b3354752103 9107b30fe11ff310fec93876469147b263fb958c Edward Thomson <ethomson@microsoft.com> 1360632835 -0600 checkout: moving from branch to master
5+
9107b30fe11ff310fec93876469147b263fb958c 8b19fd77de5995e6e502e7c3b82657248f510325 Edward Thomson <ethomson@microsoft.com> 1360633224 -0600 commit: ours
6+
8b19fd77de5995e6e502e7c3b82657248f510325 91116bad97c50a2daa278ca6cffe16d0118befe5 Edward Thomson <ethomson@microsoft.com> 1360633337 -0600 commit: ours
7+
91116bad97c50a2daa278ca6cffe16d0118befe5 8b19fd77de5995e6e502e7c3b82657248f510325 Edward Thomson <ethomson@microsoft.com> 1360633358 -0600 checkout: moving from master to 8b19fd7
8+
8b19fd77de5995e6e502e7c3b82657248f510325 9b2f98b1c086d3929eac387d39fae94425e0115f Edward Thomson <ethomson@microsoft.com> 1360633359 -0600 rebase -i (squash): ours
9+
9b2f98b1c086d3929eac387d39fae94425e0115f 9b2f98b1c086d3929eac387d39fae94425e0115f Edward Thomson <ethomson@microsoft.com> 1360633362 -0600 rebase -i (finish): returning to refs/heads/master
10+
9b2f98b1c086d3929eac387d39fae94425e0115f d4c107581ff54a41fd496e0a1f1b7b3354752103 Edward Thomson <ethomson@microsoft.com> 1360633367 -0600 checkout: moving from master to branch
11+
d4c107581ff54a41fd496e0a1f1b7b3354752103 493209f496e504d63fd78e8c5b800083b442ea34 Edward Thomson <ethomson@microsoft.com> 1360633416 -0600 commit: branch
12+
493209f496e504d63fd78e8c5b800083b442ea34 d4c107581ff54a41fd496e0a1f1b7b3354752103 Edward Thomson <ethomson@microsoft.com> 1360633427 -0600 checkout: moving from branch to d4c1075
13+
d4c107581ff54a41fd496e0a1f1b7b3354752103 8eefb6f8061e4d10a7a59aac8771dc17958d93eb Edward Thomson <ethomson@microsoft.com> 1360633429 -0600 rebase -i (squash): branch
14+
8eefb6f8061e4d10a7a59aac8771dc17958d93eb 8eefb6f8061e4d10a7a59aac8771dc17958d93eb Edward Thomson <ethomson@microsoft.com> 1360633436 -0600 rebase -i (finish): returning to refs/heads/branch
15+
8eefb6f8061e4d10a7a59aac8771dc17958d93eb 9b2f98b1c086d3929eac387d39fae94425e0115f Edward Thomson <ethomson@microsoft.com> 1360633440 -0600 checkout: moving from branch to master
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
0000000000000000000000000000000000000000 9a05ccb4e0f948de03128e095f39dae6976751c5 Edward Thomson <ethomson@edwardthomson.com> 1351371835 -0500 branch: Created from HEAD
2-
9a05ccb4e0f948de03128e095f39dae6976751c5 e2809157a7766f272e4cfe26e61ef2678a5357ff Edward Thomson <ethomson@edwardthomson.com> 1351371872 -0500 commit: branch
1+
0000000000000000000000000000000000000000 9107b30fe11ff310fec93876469147b263fb958c Edward Thomson <ethomson@microsoft.com> 1360632483 -0600 branch: Created from HEAD
2+
9107b30fe11ff310fec93876469147b263fb958c d4c107581ff54a41fd496e0a1f1b7b3354752103 Edward Thomson <ethomson@microsoft.com> 1360632833 -0600 commit: branch
3+
d4c107581ff54a41fd496e0a1f1b7b3354752103 493209f496e504d63fd78e8c5b800083b442ea34 Edward Thomson <ethomson@microsoft.com> 1360633416 -0600 commit: branch
4+
493209f496e504d63fd78e8c5b800083b442ea34 8eefb6f8061e4d10a7a59aac8771dc17958d93eb Edward Thomson <ethomson@microsoft.com> 1360633436 -0600 rebase -i (finish): refs/heads/branch onto d4c1075
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
0000000000000000000000000000000000000000 9a05ccb4e0f948de03128e095f39dae6976751c5 Edward Thomson <ethomson@edwardthomson.com> 1351371828 -0500 commit (initial): initial
2-
9a05ccb4e0f948de03128e095f39dae6976751c5 3a34580a35add43a4cf3 F438 61e8e9a30060a905c876 Edward Thomson <ethomson@edwardthomson.com> 1351372106 -0500 commit: master
1+
0000000000000000000000000000000000000000 9107b30fe11ff310fec93876469147b263fb958c Edward Thomson <ethomson@microsoft.com> 1360632480 -0600 commit (initial): ancestor
2+
9107b30fe11ff310fec93876469147b263fb958c 8b19fd77de5995e6e502e7c3b82657248f510325 Edward Thomson <ethomson@microsoft.com> 1360633224 -0600 commit: ours
3+
8b19fd77de5995e6e502e7c3b82657248f510325 91116bad97c50a2daa278ca6cffe16d0118befe5 Edward Thomson <ethomson@microsoft.com> 1360633337 -0600 commit: ours
4+
91116bad97c50a2daa278ca6cffe16d0118befe5 9b2f98b1c086d3929eac387d39fae94425e0115f Edward Thomson <ethomson@microsoft.com> 1360633362 -0600 rebase -i (finish): refs/heads/master onto 8b19fd7

LibGit2Sharp.Tests/Resources/mergedrepo_wd/dot_git/objects/0c/a3f55d4ac2fa4703c149123b0b31d733112f86

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x��
2+
�0 Cw�D΃Q�'v�!�!I�ߟ�AF<Y��+���Aص .]֡F_�) 1 C��,h�s�2�_A��r����r��sH��pE��a��2�����+��wmk��\a/[

LibGit2Sharp.Tests/Resources/mergedrepo_wd/dot_git/objects/3a/34580a35add43a4cf361e8e9a30060a905c876

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
xE��
2+
� ; ��ùC��Z-����k�t�;.�$�#nZi�&.;H��w���h�ւ�]e�t�e����`vMS�D��)��� �(#�

LibGit2Sharp.Tests/Resources/mergedrepo_wd/dot_git/objects/5d/ee68477001f447f50fa7ee7e6a818370b5c2fb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x%�� �0 Pυ�������H!�&�n/��*V��Stv�,��E`*wNt�X���F6rrn/��Ŏ��Ϝ)�
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
xM��
2+
B1D���!����9yl��& �^�}#r�f��9'�&�5^�,�� ��L�;�F;x��ŅP��O�]�#�2���t�i񮐐Q���8%ޙ�6�Eq3�ZE�7��Z<����*�ͻ70>�

LibGit2Sharp.Tests/Resources/mergedrepo_wd/dot_git/objects/94/3d961e4091cc5a28a90c58a627850a3b567f68

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
xe��
2+
!�|��^�V��������M�E���᳏��j�������S Zq�(�i���ֆ��Ñ&� ����<:��GU��eH��b��7���Q����r:E�4�ꈽ �s x���f*��F#+�Y�Q�����T#�G6��92��R��x��^��Xͳ�
3+
}�4z�df
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
x%�A
2+
�0 Qׅ���3��8��4h*��-�xS�
3+
�u� �f��>b0����u'��\)������I�Iu��]���in<#���!�

LibGit2Sharp.Tests/Resources/mergedrepo_wd/dot_git/objects/9a/05ccb4e0f948de03128e095f39dae6976751c5

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x%�K
2+
�@ C��;�� �D�q��!vHz��t�'���:����Ŏ��p��a�ʧV�"lv����Ė� �8OBH�:3�� �i-+��k������^K��&R�-~�,�Ѝ.�

LibGit2Sharp.Tests/Resources/mergedrepo_wd/dot_git/objects/da/d0664ae617d36e464ec08ed969ff496432b075

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
x=�Q
2+
�0 C��Do0� ��C��K��e� $񴪯x�_�ؤ��2��� �r������]�Q�@�L9�a�C�^ta��
3+
�[S��ST��`V=���b�{�>������ 3)

LibGit2Sharp.Tests/Resources/mergedrepo_wd/dot_git/objects/e2/809157a7766f272e4cfe26e61ef2678a5357ff

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
e2809157a7766f272e4cfe26e61ef2678a5357ff
1+
8eefb6f8061e4d10a7a59aac8771dc17958d93eb
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3a34580a35add43a4cf361e8e9a30060a905c876
1+
9b2f98b1c086d3929eac387d39fae94425e0115f

LibGit2Sharp.Tests/Resources/mergedrepo_wd/one.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This is file one!
1+
This is file one.
22
This is file one.
33
This is file one.
44
This is file one.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<<<<<<< HEAD
2+
this file will exist only
3+
in the "ours" and "theirs"
4+
side to ensure that we can
5+
handle a conflict that is
6+
added in both sides
7+
=======
8+
a file with this name
9+
is added in both the
10+
"ours" and the "theirs"
11+
side, to ensure that we
12+
can read and resolve
13+
add/add conflicts
14+
>>>>>>> branch
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
this file will exist
2+
only in the ancestor side
3+
and will be renamed in
4+
"ours" and "theirs"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
this file will exist
2+
only in the ancestor side
3+
and will be renamed in
4+
"ours" and "theirs"

LibGit2Sharp.Tests/Resources/mergedrepo_wd/two.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
This is file two!
1+
This is file two.
22
This is file two.
33
This is file two.
44
This is file two.

0 commit comments

Comments
 (0)
0