Skip to content

Commit ac26d5b

Browse files
committed
fix: can not squash and fixup until first picked/edit/reword commit in interactive rebase exists list (#1362)
Signed-off-by: leo <[email protected]>
1 parent d7c3bb7 commit ac26d5b

File tree

3 files changed

+63
-26
lines changed

3 files changed

+63
-26
lines changed

src/ViewModels/InteractiveRebase.cs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public bool CanSquashOrFixup
3535
public Models.InteractiveRebaseAction Action
3636
{
3737
get => _action;
38-
private set => SetProperty(ref _action, value);
38+
set => SetProperty(ref _action, value);
3939
}
4040

4141
public string Subject
@@ -68,11 +68,6 @@ public InteractiveRebaseItem(Models.Commit c, string message, bool canSquashOrFi
6868
CanSquashOrFixup = canSquashOrFixup;
6969
}
7070

71-
public void SetAction(object param)
72-
{
73-
Action = (Models.InteractiveRebaseAction)param;
74-
}
75-
7671
private Models.InteractiveRebaseAction _action = Models.InteractiveRebaseAction.Pick;
7772
private string _subject;
7873
private string _fullMessage;
@@ -158,10 +153,8 @@ public void MoveItemUp(InteractiveRebaseItem item)
158153
var prev = Items[idx - 1];
159154
Items.RemoveAt(idx - 1);
160155
Items.Insert(idx, prev);
161-
162-
item.CanSquashOrFixup = true;
163-
prev.CanSquashOrFixup = idx < Items.Count - 1;
164156
SelectedItem = item;
157+
UpdateItems();
165158
}
166159
}
167160

@@ -173,11 +166,21 @@ public void MoveItemDown(InteractiveRebaseItem item)
173166
var next = Items[idx + 1];
174167
Items.RemoveAt(idx + 1);
175168
Items.Insert(idx, next);
176-
177-
item.CanSquashOrFixup = idx < Items.Count - 2;
178-
next.CanSquashOrFixup = true;
179169
SelectedItem = item;
170+
UpdateItems();
171+
}
172+
}
173+
174+
public void ChangeAction(InteractiveRebaseItem item, Models.InteractiveRebaseAction action)
175+
{
176+
if (!item.CanSquashOrFixup)
177+
{
178+
if (action == Models.InteractiveRebaseAction.Squash || action == Models.InteractiveRebaseAction.Fixup)
179+
return;
180180
}
181+
182+
item.Action = action;
183+
UpdateItems();
181184
}
182185

183186
public Task<bool> Start()
@@ -210,6 +213,27 @@ public Task<bool> Start()
210213
});
211214
}
212215

216+
private void UpdateItems()
217+
{
218+
if (Items.Count == 0)
219+
return;
220+
221+
var hasValidParent = false;
222+
for (var i = Items.Count - 1; i >= 0; i--)
223+
{
224+
var item = Items[i];
225+
if (hasValidParent)
226+
{
227+
item.CanSquashOrFixup = true;
228+
}
229+
else
230+
{
231+
item.CanSquashOrFixup = false;
232+
hasValidParent = item.Action != Models.InteractiveRebaseAction.Drop;
233+
}
234+
}
235+
}
236+
213237
private Repository _repo = null;
214238
private bool _isLoading = false;
215239
private InteractiveRebaseItem _selectedItem = null;

src/Views/InteractiveRebase.axaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
<Button Grid.Column="1" Opacity="1" Margin="4,0,0,0" Padding="8,2" Background="Transparent">
108108
<Button.Flyout>
109109
<MenuFlyout Placement="BottomEdgeAlignedLeft" VerticalOffset="-4">
110-
<MenuItem InputGesture="P" Command="{Binding SetAction}" CommandParameter="{x:Static m:InteractiveRebaseAction.Pick}">
110+
<MenuItem InputGesture="P" Click="OnChangeRebaseAction" Tag="{x:Static m:InteractiveRebaseAction.Pick}">
111111
<MenuItem.Icon>
112112
<Ellipse Width="14" Height="14" Fill="Green"/>
113113
</MenuItem.Icon>
@@ -119,7 +119,7 @@
119119
</MenuItem.Header>
120120
</MenuItem>
121121

122-
<MenuItem InputGesture="E" Command="{Binding SetAction}" CommandParameter="{x:Static m:InteractiveRebaseAction.Edit}">
122+
<MenuItem InputGesture="E" Click="OnChangeRebaseAction" Tag="{x:Static m:InteractiveRebaseAction.Edit}">
123123
<MenuItem.Icon>
124124
<Ellipse Width="14" Height="14" Fill="Orange"/>
125125
</MenuItem.Icon>
@@ -131,7 +131,7 @@
131131
</MenuItem.Header>
132132
</MenuItem>
133133

134-
<MenuItem InputGesture="R" Command="{Binding SetAction}" CommandParameter="{x:Static m:InteractiveRebaseAction.Reword}">
134+
<MenuItem InputGesture="R" Click="OnChangeRebaseAction" Tag="{x:Static m:InteractiveRebaseAction.Reword}">
135135
<MenuItem.Icon>
136136
<Ellipse Width="14" Height="14" Fill="Orange"/>
137137
</MenuItem.Icon>
@@ -143,7 +143,7 @@
143143
</MenuItem.Header>
144144
</MenuItem>
145145

146-
<MenuItem InputGesture="S" Command="{Binding SetAction}" CommandParameter="{x:Static m:InteractiveRebaseAction.Squash}" IsVisible="{Binding CanSquashOrFixup}">
146+
<MenuItem InputGesture="S" Click="OnChangeRebaseAction" Tag="{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}" IsVisible="{Binding CanSquashOrFixup}">
158+
<MenuItem InputGesture="F" Click="OnChangeRebaseAction" Tag="{x:Static m:InteractiveRebaseAction.Fixup}" IsVisible="{Binding CanSquashOrFixup}">
159159
<MenuItem.Icon>
160160
<Ellipse Width="14" Height="14" Fill="LightGray"/>
161161
</MenuItem.Icon>
@@ -167,7 +167,7 @@
167167
</MenuItem.Header>
168168
</MenuItem>
169169

170-
<MenuItem InputGesture="D" Command="{Binding SetAction}" CommandParameter="{x:Static m:InteractiveRebaseAction.Drop}">
170+
<MenuItem InputGesture="D" Click="OnChangeRebaseAction" Tag="{x:Static m:InteractiveRebaseAction.Drop}">
171171
<MenuItem.Icon>
172172
<Ellipse Width="14" Height="14" Fill="Red"/>
173173
</MenuItem.Icon>
@@ -280,7 +280,7 @@
280280
Minimum="0"
281281
Maximum="100"
282282
IsVisible="False"/>
283-
<Button Grid.Column="1" Classes="flat primary" MinWidth="80" Content="{DynamicResource Text.Start}" Click="StartJobs"/>
283+
<Button Grid.Column="1" Classes="flat primary" MinWidth="80" Content="{DynamicResource Text.Start}" Click="OnStartJobs"/>
284284
<Button Grid.Column="2" Classes="flat" Margin="8,0,0,0" MinWidth="80" Content="{DynamicResource Text.Cancel}" Click="CloseWindow"/>
285285
</Grid>
286286
</Grid>

src/Views/InteractiveRebase.axaml.cs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,32 +29,32 @@ protected override void OnKeyDown(KeyEventArgs e)
2929

3030
if (e.Key == Key.P)
3131
{
32-
item.SetAction(Models.InteractiveRebaseAction.Pick);
32+
vm.ChangeAction(item, Models.InteractiveRebaseAction.Pick);
3333
e.Handled = true;
3434
}
3535
else if (e.Key == Key.E)
3636
{
37-
item.SetAction(Models.InteractiveRebaseAction.Edit);
37+
vm.ChangeAction(item, Models.InteractiveRebaseAction.Edit);
3838
e.Handled = true;
3939
}
4040
else if (e.Key == Key.R)
4141
{
42-
item.SetAction(Models.InteractiveRebaseAction.Reword);
42+
vm.ChangeAction(item, Models.InteractiveRebaseAction.Reword);
4343
e.Handled = true;
4444
}
4545
else if (e.Key == Key.S)
4646
{
47-
item.SetAction(Models.InteractiveRebaseAction.Squash);
47+
vm.ChangeAction(item, Models.InteractiveRebaseAction.Squash);
4848
e.Handled = true;
4949
}
5050
else if (e.Key == Key.F)
5151
{
52-
item.SetAction(Models.InteractiveRebaseAction.Fixup);
52+
vm.ChangeAction(item, Models.InteractiveRebaseAction.Fixup);
5353
e.Handled = true;
5454
}
5555
else if (e.Key == Key.D)
5656
{
57-
item.SetAction(Models.InteractiveRebaseAction.Drop);
57+
vm.ChangeAction(item, Models.InteractiveRebaseAction.Drop);
5858
e.Handled = true;
5959
}
6060
else if (e.KeyModifiers == KeyModifiers.Alt && e.Key == Key.Up)
@@ -153,8 +153,21 @@ private void OnMoveItemDown(object sender, RoutedEventArgs e)
153153
e.Handled = true;
154154
}
155155
}
156+
157+
private void OnChangeRebaseAction(object sender, RoutedEventArgs e)
158+
{
159+
if (DataContext is ViewModels.InteractiveRebase vm &&
160+
sender is Control
161+
{
162+
DataContext: ViewModels.InteractiveRebaseItem item,
163+
Tag: Models.InteractiveRebaseAction action
164+
})
165+
vm.ChangeAction(item, action);
166+
167+
e.Handled = true;
168+
}
156169

157-
private async void StartJobs(object _1, RoutedEventArgs _2)
170+
private async void OnStartJobs(object _1, RoutedEventArgs _2)
158171
{
159172
var vm = DataContext as ViewModels.InteractiveRebase;
160173
if (vm == null)

0 commit comments

Comments
 (0)