-
Notifications
You must be signed in to change notification settings - Fork 385
Expand file tree
/
Copy pathConflict.cs
More file actions
113 lines (97 loc) · 3.19 KB
/
Conflict.cs
File metadata and controls
113 lines (97 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
namespace SourceGit.ViewModels
{
public class ConflictSourceBranch
{
public string Name { get; private set; }
public string Head { get; private set; }
public Models.Commit Revision { get; private set; }
public ConflictSourceBranch(string name, string head, Models.Commit revision)
{
Name = name;
Head = head;
Revision = revision;
}
public ConflictSourceBranch(Repository repo, Models.Branch branch)
{
Name = branch.Name;
Head = branch.Head;
Revision = new Commands.QuerySingleCommit(repo.FullPath, branch.Head).GetResultAsync().Result ?? new Models.Commit() { SHA = branch.Head };
}
}
public class Conflict
{
public string Marker
{
get => _change.ConflictMarker;
}
public string Description
{
get => _change.ConflictDesc;
}
public object Theirs
{
get;
private set;
}
public object Mine
{
get;
private set;
}
public bool IsResolved
{
get;
private set;
} = false;
public bool CanUseExternalMergeTool
{
get;
private set;
} = false;
public Conflict(Repository repo, WorkingCopy wc, Models.Change change)
{
_wc = wc;
_change = change;
var isSubmodule = repo.Submodules.Find(x => x.Path.Equals(change.Path, StringComparison.Ordinal)) != null;
if (!isSubmodule && (_change.ConflictReason is Models.ConflictReason.BothAdded or Models.ConflictReason.BothModified))
{
CanUseExternalMergeTool = true;
IsResolved = new Commands.IsConflictResolved(repo.FullPath, change).GetResultAsync().Result;
}
if (wc.InProgressContext is RebaseInProgress rebase)
{
var b = repo.Branches.Find(x => x.IsLocal && x.Name == rebase.HeadName);
Theirs = b != null
? new ConflictSourceBranch(b.Name, b.Head, rebase.StoppedAt)
: new ConflictSourceBranch(rebase.HeadName, rebase.StoppedAt?.SHA ?? "----------", rebase.StoppedAt);
Mine = rebase.Onto;
}
else
{
Theirs = wc.InProgressContext switch
{
CherryPickInProgress cherryPick => cherryPick.Head,
RevertInProgress revert => revert.Head,
MergeInProgress merge => merge.Source,
_ => "Stash or Patch"
};
Mine = new ConflictSourceBranch(repo, repo.CurrentBranch);
}
}
public void UseTheirs()
{
_wc.UseTheirs([_change]);
}
public void UseMine()
{
_wc.UseMine([_change]);
}
public async void OpenExternalMergeTool()
{
await _wc.UseExternalMergeTool(_change);
}
private WorkingCopy _wc = null;
private Models.Change _change = null;
}
}