Skip to content

Commit 81f622b

Browse files
committed
enhance: save commit message to .git/MERGE_MSG while closing repo with in-progress state (#1795)
Signed-off-by: leo <longshuang@msn.cn>
1 parent 5c75bb8 commit 81f622b

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/ViewModels/Repository.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,11 @@ public void Close()
567567

568568
if (!_isWorktree)
569569
{
570-
_settings.LastCommitMessage = _workingCopy.CommitMessage;
570+
if (_workingCopy.InProgressContext != null && !string.IsNullOrEmpty(_workingCopy.CommitMessage))
571+
File.WriteAllText(Path.Combine(GitDir, "MERGE_MSG"), _workingCopy.CommitMessage);
572+
else
573+
_settings.LastCommitMessage = _workingCopy.CommitMessage;
574+
571575
using var stream = File.Create(Path.Combine(_gitCommonDir, "sourcegit.settings"));
572576
JsonSerializer.Serialize(stream, _settings, JsonCodeGen.Default.RepositorySettings);
573577
}

src/ViewModels/WorkingCopy.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -796,13 +796,8 @@ private void UpdateInProgressState()
796796
if (LoadCommitMessageFromFile(Path.Combine(_repo.GitDir, "rebase-merge", "message")))
797797
break;
798798

799-
var rebaseProcessingFile = Path.Combine(_repo.GitDir, "rebase-apply", "final-commit");
800-
if (File.Exists(rebaseProcessingFile))
801-
{
802-
var sha = File.ReadAllText(rebaseProcessingFile);
803-
if (!string.IsNullOrEmpty(sha))
804-
CommitMessage = new Commands.QueryCommitFullMessage(_repo.FullPath, sha).GetResult();
805-
}
799+
if (_inProgressContext is RebaseInProgress { StoppedAt: { } stopAt })
800+
CommitMessage = new Commands.QueryCommitFullMessage(_repo.FullPath, stopAt.SHA).GetResult();
806801
} while (false);
807802
}
808803

0 commit comments

Comments
 (0)