Skip to content

Commit b09d7b8

Browse files
committed
refactor: rewrite in-progress context and clear commit message to reload it from MERGE_MSG
Signed-off-by: leo <longshuang@msn.cn>
1 parent caff332 commit b09d7b8

File tree

2 files changed

+100
-62
lines changed

2 files changed

+100
-62
lines changed

src/ViewModels/InProgressContexts.cs

Lines changed: 94 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,45 +5,27 @@ namespace SourceGit.ViewModels
55
{
66
public abstract class InProgressContext
77
{
8-
protected InProgressContext(string repo, string cmd)
8+
public async Task ContinueAsync()
99
{
10-
_repo = repo;
11-
_cmd = cmd;
10+
if (_continueCmd != null)
11+
await _continueCmd.ExecAsync();
1212
}
1313

14-
public async Task<bool> AbortAsync()
14+
public async Task SkipAsync()
1515
{
16-
return await new Commands.Command()
17-
{
18-
WorkingDirectory = _repo,
19-
Context = _repo,
20-
Args = $"{_cmd} --abort",
21-
}.ExecAsync();
22-
}
23-
24-
public virtual async Task<bool> SkipAsync()
25-
{
26-
return await new Commands.Command()
27-
{
28-
WorkingDirectory = _repo,
29-
Context = _repo,
30-
Args = $"{_cmd} --skip",
31-
}.ExecAsync();
16+
if (_skipCmd != null)
17+
await _skipCmd.ExecAsync();
3218
}
3319

34-
public virtual async Task<bool> ContinueAsync()
20+
public async Task AbortAsync()
3521
{
36-
return await new Commands.Command()
37-
{
38-
WorkingDirectory = _repo,
39-
Context = _repo,
40-
Editor = Commands.Command.EditorType.None,
41-
Args = $"{_cmd} --continue",
42-
}.ExecAsync();
22+
if (_abortCmd != null)
23+
await _abortCmd.ExecAsync();
4324
}
4425

45-
protected string _repo = string.Empty;
46-
protected string _cmd = string.Empty;
26+
protected Commands.Command _continueCmd = null;
27+
protected Commands.Command _skipCmd = null;
28+
protected Commands.Command _abortCmd = null;
4729
}
4830

4931
public class CherryPickInProgress : InProgressContext
@@ -58,8 +40,29 @@ public string HeadName
5840
get;
5941
}
6042

61-
public CherryPickInProgress(Repository repo) : base(repo.FullPath, "cherry-pick")
43+
public CherryPickInProgress(Repository repo)
6244
{
45+
_continueCmd = new Commands.Command
46+
{
47+
WorkingDirectory = repo.FullPath,
48+
Context = repo.FullPath,
49+
Args = "cherry-pick --continue",
50+
};
51+
52+
_skipCmd = new Commands.Command
53+
{
54+
WorkingDirectory = repo.FullPath,
55+
Context = repo.FullPath,
56+
Args = "cherry-pick --skip",
57+
};
58+
59+
_abortCmd = new Commands.Command
60+
{
61+
WorkingDirectory = repo.FullPath,
62+
Context = repo.FullPath,
63+
Args = "cherry-pick --abort",
64+
};
65+
6366
var headSHA = File.ReadAllText(Path.Combine(repo.GitDir, "CHERRY_PICK_HEAD")).Trim();
6467
Head = new Commands.QuerySingleCommit(repo.FullPath, headSHA).GetResult() ?? new Models.Commit() { SHA = headSHA };
6568
HeadName = Head.GetFriendlyName();
@@ -88,8 +91,30 @@ public Models.Commit Onto
8891
get;
8992
}
9093

91-
public RebaseInProgress(Repository repo) : base(repo.FullPath, "rebase")
94+
public RebaseInProgress(Repository repo)
9295
{
96+
_continueCmd = new Commands.Command
97+
{
98+
WorkingDirectory = repo.FullPath,
99+
Context = repo.FullPath,
100+
Editor = Commands.Command.EditorType.RebaseEditor,
101+
Args = "rebase --continue",
102+
};
103+
104+
_skipCmd = new Commands.Command
105+
{
106+
WorkingDirectory = repo.FullPath,
107+
Context = repo.FullPath,
108+
Args = "rebase --skip",
109+
};
110+
111+
_abortCmd = new Commands.Command
112+
{
113+
WorkingDirectory = repo.FullPath,
114+
Context = repo.FullPath,
115+
Args = "rebase --abort",
116+
};
117+
93118
HeadName = File.ReadAllText(Path.Combine(repo.GitDir, "rebase-merge", "head-name")).Trim();
94119
if (HeadName.StartsWith("refs/heads/"))
95120
HeadName = HeadName.Substring(11);
@@ -108,17 +133,6 @@ public RebaseInProgress(Repository repo) : base(repo.FullPath, "rebase")
108133
Onto = new Commands.QuerySingleCommit(repo.FullPath, ontoSHA).GetResult() ?? new Models.Commit() { SHA = ontoSHA };
109134
BaseName = Onto.GetFriendlyName();
110135
}
111-
112-
public override async Task<bool> ContinueAsync()
113-
{
114-
return await new Commands.Command()
115-
{
116-
WorkingDirectory = _repo,
117-
Context = _repo,
118-
Editor = Commands.Command.EditorType.RebaseEditor,
119-
Args = "rebase --continue",
120-
}.ExecAsync();
121-
}
122136
}
123137

124138
public class RevertInProgress : InProgressContext
@@ -128,8 +142,29 @@ public Models.Commit Head
128142
get;
129143
}
130144

131-
public RevertInProgress(Repository repo) : base(repo.FullPath, "revert")
145+
public RevertInProgress(Repository repo)
132146
{
147+
_continueCmd = new Commands.Command
148+
{
149+
WorkingDirectory = repo.FullPath,
150+
Context = repo.FullPath,
151+
Args = "revert --continue",
152+
};
153+
154+
_skipCmd = new Commands.Command
155+
{
156+
WorkingDirectory = repo.FullPath,
157+
Context = repo.FullPath,
158+
Args = "revert --skip",
159+
};
160+
161+
_abortCmd = new Commands.Command
162+
{
163+
WorkingDirectory = repo.FullPath,
164+
Context = repo.FullPath,
165+
Args = "revert --abort",
166+
};
167+
133168
var headSHA = File.ReadAllText(Path.Combine(repo.GitDir, "REVERT_HEAD")).Trim();
134169
Head = new Commands.QuerySingleCommit(repo.FullPath, headSHA).GetResult() ?? new Models.Commit() { SHA = headSHA };
135170
}
@@ -152,18 +187,27 @@ public string SourceName
152187
get;
153188
}
154189

155-
public MergeInProgress(Repository repo) : base(repo.FullPath, "merge")
190+
public MergeInProgress(Repository repo)
156191
{
192+
_continueCmd = new Commands.Command
193+
{
194+
WorkingDirectory = repo.FullPath,
195+
Context = repo.FullPath,
196+
Args = "merge --continue",
197+
};
198+
199+
_abortCmd = new Commands.Command
200+
{
201+
WorkingDirectory = repo.FullPath,
202+
Context = repo.FullPath,
203+
Args = "merge --abort",
204+
};
205+
157206
Current = new Commands.QueryCurrentBranch(repo.FullPath).GetResult();
158207

159208
var sourceSHA = File.ReadAllText(Path.Combine(repo.GitDir, "MERGE_HEAD")).Trim();
160209
Source = new Commands.QuerySingleCommit(repo.FullPath, sourceSHA).GetResult() ?? new Models.Commit() { SHA = sourceSHA };
161210
SourceName = Source.GetFriendlyName();
162211
}
163-
164-
public override async Task<bool> SkipAsync()
165-
{
166-
return await Task.FromResult(true);
167-
}
168212
}
169213
}

src/ViewModels/WorkingCopy.cs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,8 @@ public async Task ContinueMergeAsync()
540540
if (File.Exists(mergeMsgFile) && !string.IsNullOrWhiteSpace(_commitMessage))
541541
await File.WriteAllTextAsync(mergeMsgFile, _commitMessage);
542542

543-
var succ = await _inProgressContext.ContinueAsync();
544-
if (succ)
545-
CommitMessage = string.Empty;
546-
543+
await _inProgressContext.ContinueAsync();
544+
CommitMessage = string.Empty;
547545
IsCommitting = false;
548546
}
549547
else
@@ -559,10 +557,8 @@ public async Task SkipMergeAsync()
559557
using var lockWatcher = _repo.LockWatcher();
560558
IsCommitting = true;
561559

562-
var succ = await _inProgressContext.SkipAsync();
563-
if (succ)
564-
CommitMessage = string.Empty;
565-
560+
await _inProgressContext.SkipAsync();
561+
CommitMessage = string.Empty;
566562
IsCommitting = false;
567563
}
568564
else
@@ -578,10 +574,8 @@ public async Task AbortMergeAsync()
578574
using var lockWatcher = _repo.LockWatcher();
579575
IsCommitting = true;
580576

581-
var succ = await _inProgressContext.AbortAsync();
582-
if (succ)
583-
CommitMessage = string.Empty;
584-
577+
await _inProgressContext.AbortAsync();
578+
CommitMessage = string.Empty;
585579
IsCommitting = false;
586580
}
587581
else

0 commit comments

Comments
 (0)