|
1 | | -using System; |
| 1 | +using System.IO; |
2 | 2 | using System.Threading.Tasks; |
3 | 3 |
|
4 | 4 | namespace SourceGit.ViewModels |
5 | 5 | { |
6 | | - public class ConflictSourceBranch |
7 | | - { |
8 | | - public string Name { get; private set; } |
9 | | - public string Head { get; private set; } |
10 | | - public Models.Commit Revision { get; private set; } |
11 | | - |
12 | | - public ConflictSourceBranch(string name, string head, Models.Commit revision) |
13 | | - { |
14 | | - Name = name; |
15 | | - Head = head; |
16 | | - Revision = revision; |
17 | | - } |
18 | | - |
19 | | - public ConflictSourceBranch(Repository repo, Models.Branch branch) |
20 | | - { |
21 | | - Name = branch.Name; |
22 | | - Head = branch.Head; |
23 | | - Revision = new Commands.QuerySingleCommit(repo.FullPath, branch.Head).GetResult() ?? new Models.Commit() { SHA = branch.Head }; |
24 | | - } |
25 | | - } |
26 | | - |
27 | 6 | public class Conflict |
28 | 7 | { |
29 | 8 | public string Marker |
@@ -60,52 +39,28 @@ public bool CanMerge |
60 | 39 | private set; |
61 | 40 | } = false; |
62 | 41 |
|
63 | | - public string FilePath |
64 | | - { |
65 | | - get => _change.Path; |
66 | | - } |
67 | | - |
68 | 42 | public Conflict(Repository repo, WorkingCopy wc, Models.Change change) |
69 | 43 | { |
70 | 44 | _repo = repo; |
71 | 45 | _wc = wc; |
72 | 46 | _change = change; |
73 | 47 |
|
74 | | - var isSubmodule = repo.Submodules.Find(x => x.Path.Equals(change.Path, StringComparison.Ordinal)) != null; |
75 | | - if (!isSubmodule && (_change.ConflictReason is Models.ConflictReason.BothAdded or Models.ConflictReason.BothModified)) |
76 | | - { |
77 | | - CanMerge = true; |
| 48 | + CanMerge = _change.ConflictReason is Models.ConflictReason.BothAdded or Models.ConflictReason.BothModified; |
| 49 | + if (CanMerge) |
| 50 | + CanMerge = !Directory.Exists(Path.Combine(repo.FullPath, change.Path)); // Cannot merge directories (submodules) |
| 51 | + |
| 52 | + if (CanMerge) |
78 | 53 | IsResolved = new Commands.IsConflictResolved(repo.FullPath, change).GetResult(); |
79 | | - } |
80 | 54 |
|
81 | | - switch (wc.InProgressContext) |
| 55 | + var head = new Commands.QuerySingleCommit(repo.FullPath, "HEAD").GetResult(); |
| 56 | + (Mine, Theirs) = wc.InProgressContext switch |
82 | 57 | { |
83 | | - case CherryPickInProgress cherryPick: |
84 | | - Theirs = cherryPick.Head; |
85 | | - Mine = new ConflictSourceBranch(repo, repo.CurrentBranch); |
86 | | - break; |
87 | | - case RebaseInProgress rebase: |
88 | | - var b = repo.Branches.Find(x => x.IsLocal && x.Name == rebase.HeadName); |
89 | | - if (b != null) |
90 | | - Theirs = new ConflictSourceBranch(b.Name, b.Head, rebase.StoppedAt); |
91 | | - else |
92 | | - Theirs = new ConflictSourceBranch(rebase.HeadName, rebase.StoppedAt?.SHA ?? "----------", rebase.StoppedAt); |
93 | | - |
94 | | - Mine = rebase.Onto; |
95 | | - break; |
96 | | - case RevertInProgress revert: |
97 | | - Theirs = revert.Head; |
98 | | - Mine = new ConflictSourceBranch(repo, repo.CurrentBranch); |
99 | | - break; |
100 | | - case MergeInProgress merge: |
101 | | - Theirs = merge.Source; |
102 | | - Mine = new ConflictSourceBranch(repo, repo.CurrentBranch); |
103 | | - break; |
104 | | - default: |
105 | | - Theirs = "Stash or Patch"; |
106 | | - Mine = new ConflictSourceBranch(repo, repo.CurrentBranch); |
107 | | - break; |
108 | | - } |
| 58 | + CherryPickInProgress cherryPick => (head, cherryPick.Head), |
| 59 | + RebaseInProgress rebase => (rebase.Onto, rebase.StoppedAt), |
| 60 | + RevertInProgress revert => (head, revert.Head), |
| 61 | + MergeInProgress merge => (head, merge.Source), |
| 62 | + _ => (head, (object)"Stash or Patch"), |
| 63 | + }; |
109 | 64 | } |
110 | 65 |
|
111 | 66 | public async Task UseTheirsAsync() |
|
0 commit comments