From 2d4f8709cac5c00a37832f2aacd30323d058a24b Mon Sep 17 00:00:00 2001 From: leo Date: Tue, 25 Jun 2024 10:26:31 +0800 Subject: [PATCH] enhance: forbid to reword or squash when there're local changes --- src/ViewModels/Histories.cs | 12 +++++++ src/ViewModels/Squash.cs | 2 +- src/Views/Squash.axaml | 62 ++++++++++++++++++------------------- 3 files changed, 43 insertions(+), 33 deletions(-) diff --git a/src/ViewModels/Histories.cs b/src/ViewModels/Histories.cs index 9f5107b0..af4f555e 100644 --- a/src/ViewModels/Histories.cs +++ b/src/ViewModels/Histories.cs @@ -217,6 +217,12 @@ namespace SourceGit.ViewModels reword.Icon = App.CreateMenuIcon("Icons.Edit"); reword.Click += (o, e) => { + if (_repo.WorkingCopyChangesCount > 0) + { + App.RaiseException(_repo.FullPath, "You have local changes. Please run stash or discard first."); + return; + } + if (PopupHost.CanCreatePopup()) PopupHost.ShowPopup(new Reword(_repo, commit)); e.Handled = true; @@ -229,6 +235,12 @@ namespace SourceGit.ViewModels squash.IsEnabled = commit.Parents.Count == 1; squash.Click += (o, e) => { + if (_repo.WorkingCopyChangesCount > 0) + { + App.RaiseException(_repo.FullPath, "You have local changes. Please run stash or discard first."); + return; + } + if (commit.Parents.Count == 1) { var parent = _commits.Find(x => x.SHA == commit.Parents[0]); diff --git a/src/ViewModels/Squash.cs b/src/ViewModels/Squash.cs index c001dfab..4b35266b 100644 --- a/src/ViewModels/Squash.cs +++ b/src/ViewModels/Squash.cs @@ -27,7 +27,7 @@ namespace SourceGit.ViewModels public Squash(Repository repo, Models.Commit head, Models.Commit parent) { _repo = repo; - _message = new Commands.QueryCommitFullMessage(_repo.FullPath, parent.SHA).Result(); + _message = new Commands.QueryCommitFullMessage(_repo.FullPath, head.SHA).Result(); Head = head; Parent = parent; diff --git a/src/Views/Squash.axaml b/src/Views/Squash.axaml index cdfcac94..38794ce7 100644 --- a/src/Views/Squash.axaml +++ b/src/Views/Squash.axaml @@ -12,40 +12,38 @@ - - - - - - - - - - - - - + + + + + + - - - - + + + + + + +