From 13a567b353bc6defcc99bc4f26dbab1ad150d0c9 Mon Sep 17 00:00:00 2001 From: Gadfly Date: Sat, 24 May 2025 21:37:26 +0800 Subject: [PATCH] fix: disable squash/fixup actions for the first changeable commit --- src/ViewModels/InteractiveRebase.cs | 27 ++++++++++++++++++++++++--- src/Views/InteractiveRebase.axaml | 6 ++++-- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/ViewModels/InteractiveRebase.cs b/src/ViewModels/InteractiveRebase.cs index 0e77eecf6..f56a610bc 100644 --- a/src/ViewModels/InteractiveRebase.cs +++ b/src/ViewModels/InteractiveRebase.cs @@ -48,15 +48,36 @@ public string FullMessage } } - public InteractiveRebaseItem(Models.Commit c, string message) + public bool HasParent + { + get + { + if (_parent?.Items == null || _parent.On == null) + return true; + + var isLastCommit = _parent.Items.IndexOf(this) == _parent.Items.Count - 1; + if (!isLastCommit) + return true; + + return _parent.On.Parents?.Count > 0; + } + } + + private readonly InteractiveRebase _parent; + + public InteractiveRebaseItem(Models.Commit c, string message, InteractiveRebase parent) { Commit = c; FullMessage = message; + _parent = parent; } public void SetAction(object param) { - Action = (Models.InteractiveRebaseAction)param; + var action = (Models.InteractiveRebaseAction)param; + if ((action is Models.InteractiveRebaseAction.Squash or Models.InteractiveRebaseAction.Fixup) && !HasParent) + return; + Action = action; } private Models.InteractiveRebaseAction _action = Models.InteractiveRebaseAction.Pick; @@ -122,7 +143,7 @@ public InteractiveRebase(Repository repo, Models.Branch current, Models.Commit o var list = new List(); foreach (var c in commits) - list.Add(new InteractiveRebaseItem(c.Commit, c.Message)); + list.Add(new InteractiveRebaseItem(c.Commit, c.Message, this)); Dispatcher.UIThread.Invoke(() => { diff --git a/src/Views/InteractiveRebase.axaml b/src/Views/InteractiveRebase.axaml index 0883c9dca..8cd3ccff1 100644 --- a/src/Views/InteractiveRebase.axaml +++ b/src/Views/InteractiveRebase.axaml @@ -143,7 +143,8 @@ - + @@ -155,7 +156,8 @@ - +