Skip to content

Commit b7dff8f

Browse files
committed
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>
1 parent a4ae633 commit b7dff8f

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

‎src/ViewModels/WorkingCopy.cs‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,12 @@ private void UpdateInProgressState()
807807
if (_inProgressContext != null && _inProgressContext.GetType() == oldType && !string.IsNullOrEmpty(_commitMessage))
808808
return;
809809

810+
// The operation that filled the commit message ended outside SourceGit (for example, a
811+
// rebase or merge finished/aborted from the terminal). Drop the stale message unless the
812+
// user has edited it since it was loaded.
813+
if (_inProgressContext == null && oldType != null && IsAutoLoadedCommitMessage())
814+
CommitMessage = string.Empty;
815+
810816
if (LoadCommitMessageFromFile(Path.Combine(_repo.GitDir, "MERGE_MSG")))
811817
return;
812818

@@ -816,7 +822,7 @@ private void UpdateInProgressState()
816822
if (LoadCommitMessageFromFile(Path.Combine(_repo.GitDir, "rebase-merge", "message")))
817823
return;
818824

819-
CommitMessage = new Commands.QueryCommitFullMessage(_repo.FullPath, rebasing.StoppedAt.SHA).GetResult();
825+
SetAutoLoadedCommitMessage(new Commands.QueryCommitFullMessage(_repo.FullPath, rebasing.StoppedAt.SHA).GetResult());
820826
}
821827

822828
private bool LoadCommitMessageFromFile(string file)
@@ -828,10 +834,22 @@ private bool LoadCommitMessageFromFile(string file)
828834
if (string.IsNullOrEmpty(msg))
829835
return false;
830836

831-
CommitMessage = msg;
837+
SetAutoLoadedCommitMessage(msg);
832838
return true;
833839
}
834840

841+
private void SetAutoLoadedCommitMessage(string msg)
842+
{
843+
_autoLoadedCommitMessage = msg;
844+
CommitMessage = msg;
845+
}
846+
847+
private bool IsAutoLoadedCommitMessage()
848+
{
849+
return !string.IsNullOrEmpty(_autoLoadedCommitMessage) &&
850+
string.Equals(_autoLoadedCommitMessage, _commitMessage, StringComparison.Ordinal);
851+
}
852+
835853
private void SetDetail(Models.Change change, bool isUnstaged)
836854
{
837855
if (_isLoadingData)
@@ -942,5 +960,6 @@ public ChangeInTree(Models.Change change)
942960

943961
private bool _hasUnsolvedConflicts = false;
944962
private InProgressContext _inProgressContext = null;
963+
private string _autoLoadedCommitMessage = null;
945964
}
946965
}

0 commit comments

Comments
 (0)