mirror of
https://github.com/sourcegit-scm/sourcegit
synced 2025-06-05 11:05:00 +00:00
enhance: disable squash and fixup for the first commit in interactive rebase list (#1362)
Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
parent
22339ab619
commit
0e35c56529
2 changed files with 30 additions and 6 deletions
|
@ -19,6 +19,19 @@ namespace SourceGit.ViewModels
|
||||||
private set;
|
private set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool CanSquashOrFixup
|
||||||
|
{
|
||||||
|
get => _canSquashOrFixup;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (SetProperty(ref _canSquashOrFixup, value))
|
||||||
|
{
|
||||||
|
if (_action == Models.InteractiveRebaseAction.Squash || _action == Models.InteractiveRebaseAction.Fixup)
|
||||||
|
Action = Models.InteractiveRebaseAction.Pick;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Models.InteractiveRebaseAction Action
|
public Models.InteractiveRebaseAction Action
|
||||||
{
|
{
|
||||||
get => _action;
|
get => _action;
|
||||||
|
@ -48,10 +61,11 @@ namespace SourceGit.ViewModels
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public InteractiveRebaseItem(Models.Commit c, string message)
|
public InteractiveRebaseItem(Models.Commit c, string message, bool canSquashOrFixup)
|
||||||
{
|
{
|
||||||
Commit = c;
|
Commit = c;
|
||||||
FullMessage = message;
|
FullMessage = message;
|
||||||
|
CanSquashOrFixup = canSquashOrFixup;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetAction(object param)
|
public void SetAction(object param)
|
||||||
|
@ -62,6 +76,7 @@ namespace SourceGit.ViewModels
|
||||||
private Models.InteractiveRebaseAction _action = Models.InteractiveRebaseAction.Pick;
|
private Models.InteractiveRebaseAction _action = Models.InteractiveRebaseAction.Pick;
|
||||||
private string _subject;
|
private string _subject;
|
||||||
private string _fullMessage;
|
private string _fullMessage;
|
||||||
|
private bool _canSquashOrFixup = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class InteractiveRebase : ObservableObject
|
public class InteractiveRebase : ObservableObject
|
||||||
|
@ -88,7 +103,7 @@ namespace SourceGit.ViewModels
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
private set;
|
private set;
|
||||||
} = new AvaloniaList<InteractiveRebaseItem>();
|
} = [];
|
||||||
|
|
||||||
public InteractiveRebaseItem SelectedItem
|
public InteractiveRebaseItem SelectedItem
|
||||||
{
|
{
|
||||||
|
@ -121,8 +136,11 @@ namespace SourceGit.ViewModels
|
||||||
var commits = new Commands.QueryCommitsForInteractiveRebase(repoPath, on.SHA).Result();
|
var commits = new Commands.QueryCommitsForInteractiveRebase(repoPath, on.SHA).Result();
|
||||||
var list = new List<InteractiveRebaseItem>();
|
var list = new List<InteractiveRebaseItem>();
|
||||||
|
|
||||||
foreach (var c in commits)
|
for (var i = 0; i < commits.Count; i++)
|
||||||
list.Add(new InteractiveRebaseItem(c.Commit, c.Message));
|
{
|
||||||
|
var c = commits[i];
|
||||||
|
list.Add(new InteractiveRebaseItem(c.Commit, c.Message, i < commits.Count - 1));
|
||||||
|
}
|
||||||
|
|
||||||
Dispatcher.UIThread.Invoke(() =>
|
Dispatcher.UIThread.Invoke(() =>
|
||||||
{
|
{
|
||||||
|
@ -140,6 +158,9 @@ namespace SourceGit.ViewModels
|
||||||
var prev = Items[idx - 1];
|
var prev = Items[idx - 1];
|
||||||
Items.RemoveAt(idx - 1);
|
Items.RemoveAt(idx - 1);
|
||||||
Items.Insert(idx, prev);
|
Items.Insert(idx, prev);
|
||||||
|
|
||||||
|
item.CanSquashOrFixup = true;
|
||||||
|
prev.CanSquashOrFixup = idx < Items.Count - 1;
|
||||||
SelectedItem = item;
|
SelectedItem = item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,6 +173,9 @@ namespace SourceGit.ViewModels
|
||||||
var next = Items[idx + 1];
|
var next = Items[idx + 1];
|
||||||
Items.RemoveAt(idx + 1);
|
Items.RemoveAt(idx + 1);
|
||||||
Items.Insert(idx, next);
|
Items.Insert(idx, next);
|
||||||
|
|
||||||
|
item.CanSquashOrFixup = idx < Items.Count - 2;
|
||||||
|
next.CanSquashOrFixup = true;
|
||||||
SelectedItem = item;
|
SelectedItem = item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,7 +143,7 @@
|
||||||
</MenuItem.Header>
|
</MenuItem.Header>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|
||||||
<MenuItem InputGesture="S" Command="{Binding SetAction}" CommandParameter="{x:Static m:InteractiveRebaseAction.Squash}">
|
<MenuItem InputGesture="S" Command="{Binding SetAction}" CommandParameter="{x:Static m:InteractiveRebaseAction.Squash}" IsVisible="{Binding CanSquashOrFixup}">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<Ellipse Width="14" Height="14" Fill="LightGray"/>
|
<Ellipse Width="14" Height="14" Fill="LightGray"/>
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
|
@ -155,7 +155,7 @@
|
||||||
</MenuItem.Header>
|
</MenuItem.Header>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
|
|
||||||
<MenuItem InputGesture="F" Command="{Binding SetAction}" CommandParameter="{x:Static m:InteractiveRebaseAction.Fixup}">
|
<MenuItem InputGesture="F" Command="{Binding SetAction}" CommandParameter="{x:Static m:InteractiveRebaseAction.Fixup}" IsVisible="{Binding CanSquashOrFixup}">
|
||||||
<MenuItem.Icon>
|
<MenuItem.Icon>
|
||||||
<Ellipse Width="14" Height="14" Fill="LightGray"/>
|
<Ellipse Width="14" Height="14" Fill="LightGray"/>
|
||||||
</MenuItem.Icon>
|
</MenuItem.Icon>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue