-
Notifications
You must be signed in to change notification settings - Fork 498
Expand file tree
/
Copy pathConflict.cs
More file actions
101 lines (86 loc) · 3.13 KB
/
Copy pathConflict.cs
File metadata and controls
101 lines (86 loc) · 3.13 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
using System.IO;
using System.Threading.Tasks;
using Avalonia.Threading;
using CommunityToolkit.Mvvm.ComponentModel;
namespace SourceGit.ViewModels
{
public class Conflict : ObservableObject
{
public string Marker
{
get => _change.ConflictMarker;
}
public string Description
{
get => _change.ConflictDesc;
}
public Models.ConflictFileState State
{
get => _state;
private set => SetProperty(ref _state, value);
}
public object Theirs
{
get => _theirs;
private set => SetProperty(ref _theirs, value);
}
public object Mine
{
get => _mine;
private set => SetProperty(ref _mine, value);
}
public Conflict(Repository repo, WorkingCopy wc, Models.Change change)
{
_repo = repo;
_wc = wc;
_change = change;
Task.Run(async () =>
{
_head = new Commands.QuerySingleCommit(repo.FullPath, "HEAD").GetResult();
var (mine, theirs) = wc.InProgressContext switch
{
CherryPickInProgress cherryPick => (_head, cherryPick.Head),
RebaseInProgress rebase => (rebase.Onto, rebase.StoppedAt),
RevertInProgress revert => (_head, revert.Head),
MergeInProgress merge => (_head, merge.Source),
_ => (_head, (object)"Stash or Patch"),
};
var state = Models.ConflictFileState.Unknown;
if ((_change.ConflictReason is Models.ConflictReason.BothAdded or Models.ConflictReason.BothModified) && !Directory.Exists(Path.Combine(_repo.FullPath, _change.Path)))
state = await new Commands.QueryConflictFileState(repo.FullPath, change)
.GetResultAsync()
.ConfigureAwait(false);
Dispatcher.UIThread.Post(() =>
{
State = state;
Mine = mine;
Theirs = theirs;
});
});
}
public async Task UseTheirsAsync()
{
await _wc.UseTheirsAsync([_change]);
}
public async Task UseMineAsync()
{
await _wc.UseMineAsync([_change]);
}
public MergeConflictEditor CreateOpenMergeEditorRequest()
{
return _state == Models.ConflictFileState.UnmergedText ? new MergeConflictEditor(_repo, _head, _change.Path) : null;
}
public async Task MergeExternalAsync()
{
if (_state == Models.ConflictFileState.UnmergedText)
await _wc.UseExternalMergeToolAsync(_change);
}
private Repository _repo = null;
private WorkingCopy _wc = null;
private Models.Change _change = null;
private Models.Commit _head = null;
private Models.ConflictFileState _state = Models.ConflictFileState.Unknown;
private object _mine = null;
private object _theirs = null;
}
}