From b7dff8fcd40f3b95edf0ef64ab53335bcee6fc90 Mon Sep 17 00:00:00 2001 From: Daniil Tatianin <99danilt@gmail.com> Date: Wed, 23 Sep 2026 22:52:38 +0300 Subject: [PATCH] fix: clear stale commit message after an external operation ends When a rebase, merge, cherry-pick or revert is in progress, the working copy auto-fills the commit message box from `MERGE_MSG`, `rebase-merge/message` or the commit being replayed. If that operation then finishes or is aborted outside SourceGit (e.g. from the terminal), the loaded text stayed in the box, got persisted as the last commit message on close, and reappeared on every later open of the repository. Remember which message was auto-loaded and clear it once the in-progress state disappears, unless the user has edited the text in the meantime. Signed-off-by: Daniil Tatianin <99danilt@gmail.com> --- src/ViewModels/WorkingCopy.cs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index 8034a6fb4..59e02ef8c 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -807,6 +807,12 @@ private void UpdateInProgressState() if (_inProgressContext != null && _inProgressContext.GetType() == oldType && !string.IsNullOrEmpty(_commitMessage)) return; + // The operation that filled the commit message ended outside SourceGit (for example, a + // rebase or merge finished/aborted from the terminal). Drop the stale message unless the + // user has edited it since it was loaded. + if (_inProgressContext == null && oldType != null && IsAutoLoadedCommitMessage()) + CommitMessage = string.Empty; + if (LoadCommitMessageFromFile(Path.Combine(_repo.GitDir, "MERGE_MSG"))) return; @@ -816,7 +822,7 @@ private void UpdateInProgressState() if (LoadCommitMessageFromFile(Path.Combine(_repo.GitDir, "rebase-merge", "message"))) return; - CommitMessage = new Commands.QueryCommitFullMessage(_repo.FullPath, rebasing.StoppedAt.SHA).GetResult(); + SetAutoLoadedCommitMessage(new Commands.QueryCommitFullMessage(_repo.FullPath, rebasing.StoppedAt.SHA).GetResult()); } private bool LoadCommitMessageFromFile(string file) @@ -828,10 +834,22 @@ private bool LoadCommitMessageFromFile(string file) if (string.IsNullOrEmpty(msg)) return false; - CommitMessage = msg; + SetAutoLoadedCommitMessage(msg); return true; } + private void SetAutoLoadedCommitMessage(string msg) + { + _autoLoadedCommitMessage = msg; + CommitMessage = msg; + } + + private bool IsAutoLoadedCommitMessage() + { + return !string.IsNullOrEmpty(_autoLoadedCommitMessage) && + string.Equals(_autoLoadedCommitMessage, _commitMessage, StringComparison.Ordinal); + } + private void SetDetail(Models.Change change, bool isUnstaged) { if (_isLoadingData) @@ -942,5 +960,6 @@ public ChangeInTree(Models.Change change) private bool _hasUnsolvedConflicts = false; private InProgressContext _inProgressContext = null; + private string _autoLoadedCommitMessage = null; } }