Skip to content

Commit b5feabf

Browse files
committed
enhance: auto-set commit message while rebasing is inprogress (#1003)
Signed-off-by: leo <[email protected]>
1 parent 08da3ac commit b5feabf

File tree

1 file changed

+56
-44
lines changed

1 file changed

+56
-44
lines changed

src/ViewModels/WorkingCopy.cs

Lines changed: 56 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -233,25 +233,10 @@ public void SetData(List<Models.Change> changes)
233233
// Just force refresh selected changes.
234234
Dispatcher.UIThread.Invoke(() =>
235235
{
236-
if (_selectedUnstaged.Count == 1)
237-
SetDetail(_selectedUnstaged[0], true);
238-
else if (_selectedStaged.Count == 1)
239-
SetDetail(_selectedStaged[0], false);
240-
else
241-
SetDetail(null, false);
242-
243-
var inProgress = null as InProgressContext;
244-
if (File.Exists(Path.Combine(_repo.GitDir, "CHERRY_PICK_HEAD")))
245-
inProgress = new CherryPickInProgress(_repo);
246-
else if (Directory.Exists(Path.Combine(_repo.GitDir, "rebase-merge")) || Directory.Exists(Path.Combine(_repo.GitDir, "rebase-apply")))
247-
inProgress = new RebaseInProgress(_repo);
248-
else if (File.Exists(Path.Combine(_repo.GitDir, "REVERT_HEAD")))
249-
inProgress = new RevertInProgress(_repo);
250-
else if (File.Exists(Path.Combine(_repo.GitDir, "MERGE_HEAD")))
251-
inProgress = new MergeInProgress(_repo);
252-
253236
HasUnsolvedConflicts = _cached.Find(x => x.IsConflit) != null;
254-
InProgressContext = inProgress;
237+
238+
UpdateDetail();
239+
UpdateInProgressState();
255240
});
256241

257242
return;
@@ -311,32 +296,8 @@ public void SetData(List<Models.Change> changes)
311296
SelectedStaged = selectedStaged;
312297
_isLoadingData = false;
313298

314-
if (selectedUnstaged.Count == 1)
315-
SetDetail(selectedUnstaged[0], true);
316-
else if (selectedStaged.Count == 1)
317-
SetDetail(selectedStaged[0], false);
318-
else
319-
SetDetail(null, false);
320-
321-
var inProgress = null as InProgressContext;
322-
if (File.Exists(Path.Combine(_repo.GitDir, "CHERRY_PICK_HEAD")))
323-
inProgress = new CherryPickInProgress(_repo);
324-
else if (Directory.Exists(Path.Combine(_repo.GitDir, "rebase-merge")) || Directory.Exists(Path.Combine(_repo.GitDir, "rebase-apply")))
325-
inProgress = new RebaseInProgress(_repo);
326-
else if (File.Exists(Path.Combine(_repo.GitDir, "REVERT_HEAD")))
327-
inProgress = new RevertInProgress(_repo);
328-
else if (File.Exists(Path.Combine(_repo.GitDir, "MERGE_HEAD")))
329-
inProgress = new MergeInProgress(_repo);
330-
331-
InProgressContext = inProgress;
332-
333-
// Try to load merge message from MERGE_MSG
334-
if (string.IsNullOrEmpty(_commitMessage))
335-
{
336-
var mergeMsgFile = Path.Combine(_repo.GitDir, "MERGE_MSG");
337-
if (File.Exists(mergeMsgFile))
338-
CommitMessage = File.ReadAllText(mergeMsgFile);
339-
}
299+
UpdateDetail();
300+
UpdateInProgressState();
340301
});
341302
}
342303

@@ -1488,6 +1449,57 @@ public ContextMenu CreateContextForOpenAI()
14881449
return rs;
14891450
}
14901451

1452+
private void UpdateDetail()
1453+
{
1454+
if (_selectedUnstaged.Count == 1)
1455+
SetDetail(_selectedUnstaged[0], true);
1456+
else if (_selectedStaged.Count == 1)
1457+
SetDetail(_selectedStaged[0], false);
1458+
else
1459+
SetDetail(null, false);
1460+
}
1461+
1462+
private void UpdateInProgressState()
1463+
{
1464+
if (string.IsNullOrEmpty(_commitMessage))
1465+
{
1466+
var mergeMsgFile = Path.Combine(_repo.GitDir, "MERGE_MSG");
1467+
if (File.Exists(mergeMsgFile))
1468+
CommitMessage = File.ReadAllText(mergeMsgFile);
1469+
}
1470+
1471+
if (File.Exists(Path.Combine(_repo.GitDir, "CHERRY_PICK_HEAD")))
1472+
{
1473+
InProgressContext = new CherryPickInProgress(_repo);
1474+
}
1475+
else if (Directory.Exists(Path.Combine(_repo.GitDir, "rebase-merge")) || Directory.Exists(Path.Combine(_repo.GitDir, "rebase-apply")))
1476+
{
1477+
var rebasing = new RebaseInProgress(_repo);
1478+
InProgressContext = rebasing;
1479+
1480+
if (string.IsNullOrEmpty(_commitMessage))
1481+
{
1482+
var rebaseMsgFile = Path.Combine(_repo.GitDir, "rebase-merge", "message");
1483+
if (File.Exists(rebaseMsgFile))
1484+
CommitMessage = File.ReadAllText(rebaseMsgFile);
1485+
else if (rebasing.StoppedAt != null)
1486+
CommitMessage = new Commands.QueryCommitFullMessage(_repo.FullPath, rebasing.StoppedAt.SHA).Result();
1487+
}
1488+
}
1489+
else if (File.Exists(Path.Combine(_repo.GitDir, "REVERT_HEAD")))
1490+
{
1491+
InProgressContext = new RevertInProgress(_repo);
1492+
}
1493+
else if (File.Exists(Path.Combine(_repo.GitDir, "MERGE_HEAD")))
1494+
{
1495+
InProgressContext = new MergeInProgress(_repo);
1496+
}
1497+
else
1498+
{
1499+
InProgressContext = null;
1500+
}
1501+
}
1502+
14911503
private async void StageChanges(List<Models.Change> changes, Models.Change next)
14921504
{
14931505
if (changes.Count == 0)

0 commit comments

Comments
 (0)