Skip to content

Commit 0e35c56

Browse files
committed
enhance: disable squash and fixup for the first commit in interactive rebase list (#1362)
Signed-off-by: leo <[email protected]>
1 parent 22339ab commit 0e35c56

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

src/ViewModels/InteractiveRebase.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,19 @@ public Models.Commit Commit
1919
private set;
2020
}
2121

22+
public bool CanSquashOrFixup
23+
{
24+
get => _canSquashOrFixup;
25+
set
26+
{
27+
if (SetProperty(ref _canSquashOrFixup, value))
28+
{
29+
if (_action == Models.InteractiveRebaseAction.Squash || _action == Models.InteractiveRebaseAction.Fixup)
30+
Action = Models.InteractiveRebaseAction.Pick;
31+
}
32+
}
33+
}
34+
2235
public Models.InteractiveRebaseAction Action
2336
{
2437
get => _action;
@@ -48,10 +61,11 @@ public string FullMessage
4861
}
4962
}
5063

51-
public InteractiveRebaseItem(Models.Commit c, string message)
64+
public InteractiveRebaseItem(Models.Commit c, string message, bool canSquashOrFixup)
5265
{
5366
Commit = c;
5467
FullMessage = message;
68+
CanSquashOrFixup = canSquashOrFixup;
5569
}
5670

5771
public void SetAction(object param)
@@ -62,6 +76,7 @@ public void SetAction(object param)
6276
private Models.InteractiveRebaseAction _action = Models.InteractiveRebaseAction.Pick;
6377
private string _subject;
6478
private string _fullMessage;
79+
private bool _canSquashOrFixup = true;
6580
}
6681

6782
public class InteractiveRebase : ObservableObject
@@ -88,7 +103,7 @@ public AvaloniaList<InteractiveRebaseItem> Items
88103
{
89104
get;
90105
private set;
91-
} = new AvaloniaList<InteractiveRebaseItem>();
106+
} = [];
92107

93108
public InteractiveRebaseItem SelectedItem
94109
{
@@ -121,8 +136,11 @@ public InteractiveRebase(Repository repo, Models.Branch current, Models.Commit o
121136
var commits = new Commands.QueryCommitsForInteractiveRebase(repoPath, on.SHA).Result();
122137
var list = new List<InteractiveRebaseItem>();
123138

124-
foreach (var c in commits)
125-
list.Add(new InteractiveRebaseItem(c.Commit, c.Message));
139+
for (var i = 0; i < commits.Count; i++)
140+
{
141+
var c = commits[i];
142+
list.Add(new InteractiveRebaseItem(c.Commit, c.Message, i < commits.Count - 1));
143+
}
126144

127145
Dispatcher.UIThread.Invoke(() =>
128146
{
@@ -140,6 +158,9 @@ public void MoveItemUp(InteractiveRebaseItem item)
140158
var prev = Items[idx - 1];
141159
Items.RemoveAt(idx - 1);
142160
Items.Insert(idx, prev);
161+
162+
item.CanSquashOrFixup = true;
163+
prev.CanSquashOrFixup = idx < Items.Count - 1;
143164
SelectedItem = item;
144165
}
145166
}
@@ -152,6 +173,9 @@ public void MoveItemDown(InteractiveRebaseItem item)
152173
var next = Items[idx + 1];
153174
Items.RemoveAt(idx + 1);
154175
Items.Insert(idx, next);
176+
177+
item.CanSquashOrFixup = idx < Items.Count - 2;
178+
next.CanSquashOrFixup = true;
155179
SelectedItem = item;
156180
}
157181
}

src/Views/InteractiveRebase.axaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@
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}" IsVisible="{Binding CanSquashOrFixup}">
147147
<MenuItem.Icon>
148148
<Ellipse Width="14" Height="14" Fill="LightGray"/>
149149
</MenuItem.Icon>
@@ -155,7 +155,7 @@
155155
</MenuItem.Header>
156156
</MenuItem>
157157

158-
<MenuItem InputGesture="F" Command="{Binding SetAction}" CommandParameter="{x:Static m:InteractiveRebaseAction.Fixup}">
158+
<MenuItem InputGesture="F" Command="{Binding SetAction}" CommandParameter="{x:Static m:InteractiveRebaseAction.Fixup}" IsVisible="{Binding CanSquashOrFixup}">
159159
<MenuItem.Icon>
160160
<Ellipse Width="14" Height="14" Fill="LightGray"/>
161161
</MenuItem.Icon>

0 commit comments

Comments
 (0)