Skip to content

Commit 13a567b

Browse files
committed
fix: disable squash/fixup actions for the first changeable commit
1 parent 22339ab commit 13a567b

2 files changed

Lines changed: 28 additions & 5 deletions

File tree

src/ViewModels/InteractiveRebase.cs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,36 @@ public string FullMessage
4848
}
4949
}
5050

51-
public InteractiveRebaseItem(Models.Commit c, string message)
51+
public bool HasParent
52+
{
53+
get
54+
{
55+
if (_parent?.Items == null || _parent.On == null)
56+
return true;
57+
58+
var isLastCommit = _parent.Items.IndexOf(this) == _parent.Items.Count - 1;
59+
if (!isLastCommit)
60+
return true;
61+
62+
return _parent.On.Parents?.Count > 0;
63+
}
64+
}
65+
66+
private readonly InteractiveRebase _parent;
67+
68+
public InteractiveRebaseItem(Models.Commit c, string message, InteractiveRebase parent)
5269
{
5370
Commit = c;
5471
FullMessage = message;
72+
_parent = parent;
5573
}
5674

5775
public void SetAction(object param)
5876
{
59-
Action = (Models.InteractiveRebaseAction)param;
77+
var action = (Models.InteractiveRebaseAction)param;
78+
if ((action is Models.InteractiveRebaseAction.Squash or Models.InteractiveRebaseAction.Fixup) && !HasParent)
79+
return;
80+
Action = action;
6081
}
6182

6283
private Models.InteractiveRebaseAction _action = Models.InteractiveRebaseAction.Pick;
@@ -122,7 +143,7 @@ public InteractiveRebase(Repository repo, Models.Branch current, Models.Commit o
122143
var list = new List<InteractiveRebaseItem>();
123144

124145
foreach (var c in commits)
125-
list.Add(new InteractiveRebaseItem(c.Commit, c.Message));
146+
list.Add(new InteractiveRebaseItem(c.Commit, c.Message, this));
126147

127148
Dispatcher.UIThread.Invoke(() =>
128149
{

src/Views/InteractiveRebase.axaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@
143143
</MenuItem.Header>
144144
</MenuItem>
145145

146-
<MenuItem InputGesture="S" Command="{Binding SetAction}" CommandParameter="{x:Static m:InteractiveRebaseAction.Squash}">
146+
<MenuItem InputGesture="S" Command="{Binding SetAction}" CommandParameter="{x:Static m:InteractiveRebaseAction.Squash}"
147+
IsVisible="{Binding HasParent}">
147148
<MenuItem.Icon>
148149
<Ellipse Width="14" Height="14" Fill="LightGray"/>
149150
</MenuItem.Icon>
@@ -155,7 +156,8 @@
155156
</MenuItem.Header>
156157
</MenuItem>
157158

158-
<MenuItem InputGesture="F" Command="{Binding SetAction}" CommandParameter="{x:Static m:InteractiveRebaseAction.Fixup}">
159+
<MenuItem InputGesture="F" Command="{Binding SetAction}" CommandParameter="{x:Static m:InteractiveRebaseAction.Fixup}"
160+
IsVisible="{Binding HasParent}">
159161
<MenuItem.Icon>
160162
<Ellipse Width="14" Height="14" Fill="LightGray"/>
161163
</MenuItem.Icon>

0 commit comments

Comments
 (0)