Skip to content

Commit 4981030

Browse files
Edward Thomsonethomson
Edward Thomson
authored andcommitted
Introduce FileStatus.Conflicted
Introduce conflict data to status and diff information. Introduce staging of conflicts.
1 parent 70e7d72 commit 4981030

File tree

6 files changed

+59
-3
lines changed

6 files changed

+59
-3
lines changed

LibGit2Sharp/ChangeKind.cs

+5
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,10 @@ public enum ChangeKind
5555
/// Entry is unreadable.
5656
/// </summary>
5757
Unreadable = 9,
58+
59+
/// <summary>
60+
/// Entry is currently in conflict.
61+
/// </summary>
62+
Conflicted = 10,
5863
}
5964
}

LibGit2Sharp/Core/GitDiff.cs

+1
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ internal enum GitDiffFlags
231231
GIT_DIFF_FLAG_BINARY = (1 << 0),
232232
GIT_DIFF_FLAG_NOT_BINARY = (1 << 1),
233233
GIT_DIFF_FLAG_VALID_ID = (1 << 2),
234+
GIT_DIFF_FLAG_EXISTS = (1 << 3),
234235
}
235236

236237
[StructLayout(LayoutKind.Sequential)]

LibGit2Sharp/FileStatus.cs

+5
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,10 @@ public enum FileStatus
125125
/// The file is <see cref="NewInWorkdir"/> but its name and/or path matches an exclude pattern in a <c>gitignore</c> file.
126126
/// </summary>
127127
Ignored = (1 << 14), /* GIT_STATUS_IGNORED */
128+
129+
/// <summary>
130+
/// The file is <see cref="Conflicted"/> due to a merge.
131+
/// </summary>
132+
Conflicted = (1 << 15), /* GIT_STATUS_CONFLICTED */
128133
}
129134
}

LibGit2Sharp/Repository.cs

+26-3
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,7 @@ public void Stage(IEnumerable<string> paths, StageOptions stageOptions)
16561656
.Where(
16571657
tec => tec.Status != ChangeKind.Added &&
16581658
tec.Status != ChangeKind.Modified &&
1659+
tec.Status != ChangeKind.Conflicted &&
16591660
tec.Status != ChangeKind.Unmodified &&
16601661
tec.Status != ChangeKind.Deleted).ToList();
16611662

@@ -1667,10 +1668,25 @@ public void Stage(IEnumerable<string> paths, StageOptions stageOptions)
16671668
unexpectedTypesOfChanges[0].Path, unexpectedTypesOfChanges[0].Status));
16681669
}
16691670

1670-
foreach (TreeEntryChanges treeEntryChanges in changes
1671-
.Where(tec => tec.Status == ChangeKind.Deleted))
1671+
/* Remove files from the index that don't exist on disk */
1672+
foreach (TreeEntryChanges treeEntryChanges in changes)
16721673
{
1673-
RemoveFromIndex(treeEntryChanges.Path);
1674+
switch (treeEntryChanges.Status)
1675+
{
1676+
case ChangeKind.Conflicted:
1677+
if (!treeEntryChanges.Exists)
1678+
{
1679+
RemoveFromIndex(treeEntryChanges.Path);
1680+
}
1681+
break;
1682+
1683+
case ChangeKind.Deleted:
1684+
RemoveFromIndex(treeEntryChanges.Path);
1685+
break;
1686+
1687+
default:
1688+
continue;
1689+
}
16741690
}
16751691

16761692
foreach (TreeEntryChanges treeEntryChanges in changes)
@@ -1682,6 +1698,13 @@ public void Stage(IEnumerable<string> paths, StageOptions stageOptions)
16821698
AddToIndex(treeEntryChanges.Path);
16831699
break;
16841700

1701+
case ChangeKind.Conflicted:
1702+
if (treeEntryChanges.Exists)
1703+
{
1704+
AddToIndex(treeEntryChanges.Path);
1705+
}
1706+
break;
1707+
16851708
default:
16861709
continue;
16871710
}

LibGit2Sharp/TreeChanges.cs

+10
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class TreeChanges : IEnumerable<TreeEntryChanges>
2525
private readonly List<TreeEntryChanges> unmodified = new List<TreeEntryChanges>();
2626
private readonly List<TreeEntryChanges> renamed = new List<TreeEntryChanges>();
2727
private readonly List<TreeEntryChanges> copied = new List<TreeEntryChanges>();
28+
private readonly List<TreeEntryChanges> conflicted = new List<TreeEntryChanges>();
2829

2930
private readonly IDictionary<ChangeKind, Action<TreeChanges, TreeEntryChanges>> fileDispatcher = Build();
3031

@@ -39,6 +40,7 @@ private static IDictionary<ChangeKind, Action<TreeChanges, TreeEntryChanges>> Bu
3940
{ ChangeKind.Unmodified, (de, d) => de.unmodified.Add(d) },
4041
{ ChangeKind.Renamed, (de, d) => de.renamed.Add(d) },
4142
{ ChangeKind.Copied, (de, d) => de.copied.Add(d) },
43+
{ ChangeKind.Conflicted, (de, d) => de.conflicted.Add(d) },
4244
};
4345
}
4446

@@ -146,6 +148,14 @@ public virtual IEnumerable<TreeEntryChanges> Unmodified
146148
get { return unmodified; }
147149
}
148150

151+
/// <summary>
152+
/// List of <see cref="TreeEntryChanges"/> which are conflicted
153+
/// </summary>
154+
public virtual IEnumerable<TreeEntryChanges> Conflicted
155+
{
156+
get { return conflicted; }
157+
}
158+
149159
private string DebuggerDisplay
150160
{
151161
get

LibGit2Sharp/TreeEntryChanges.cs

+12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ internal TreeEntryChanges(GitDiffDelta delta)
2525
OldMode = (Mode)delta.OldFile.Mode;
2626
Oid = delta.NewFile.Id;
2727
OldOid = delta.OldFile.Id;
28+
Exists = (delta.NewFile.Flags & GitDiffFlags.GIT_DIFF_FLAG_EXISTS) != 0;
29+
OldExists = (delta.OldFile.Flags & GitDiffFlags.GIT_DIFF_FLAG_EXISTS) != 0;
2830

2931
Status = (delta.Status == ChangeKind.Untracked || delta.Status == ChangeKind.Ignored)
3032
? ChangeKind.Added
@@ -46,6 +48,11 @@ internal TreeEntryChanges(GitDiffDelta delta)
4648
/// </summary>
4749
public virtual ObjectId Oid { get; private set; }
4850

51+
/// <summary>
52+
/// The file exists (this is not a deletion.)
53+
/// </summary>
54+
public virtual bool Exists { get; private set; }
55+
4956
/// <summary>
5057
/// The kind of change that has been done (added, deleted, modified ...).
5158
/// </summary>
@@ -66,6 +73,11 @@ internal TreeEntryChanges(GitDiffDelta delta)
6673
/// </summary>
6774
public virtual ObjectId OldOid { get; private set; }
6875

76+
/// <summary>
77+
/// The old side exists (this is not an add, or an add/add conflict.)
78+
/// </summary>
79+
public virtual bool OldExists { get; private set; }
80+
6981
private string DebuggerDisplay
7082
{
7183
get

0 commit comments

Comments
 (0)