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; } }