Skip to content

Commit c23a090

Browse files
committed
enhance: quickly drop single commits by prefilling interactive rebase
1 parent a1e0ee5 commit c23a090

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/Resources/Locales/en_US.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
<x:String x:Key="Text.CommitCM.CopySHA" xml:space="preserve">SHA</x:String>
124124
<x:String x:Key="Text.CommitCM.CopySubject" xml:space="preserve">Subject</x:String>
125125
<x:String x:Key="Text.CommitCM.CustomAction" xml:space="preserve">Custom Action</x:String>
126+
<x:String x:Key="Text.CommitCM.Drop" xml:space="preserve">Drop Commit</x:String>
126127
<x:String x:Key="Text.CommitCM.InteractiveRebase" xml:space="preserve">Interactively Rebase ${0}$ on ${1}$</x:String>
127128
<x:String x:Key="Text.CommitCM.Merge" xml:space="preserve">Merge to ${0}$</x:String>
128129
<x:String x:Key="Text.CommitCM.MergeMultiple" xml:space="preserve">Merge ...</x:String>

src/ViewModels/Histories.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,17 @@ public ContextMenu CreateContextMenuForSelectedCommits(List<Models.Commit> selec
617617
e.Handled = true;
618618
};
619619
menu.Items.Add(revert);
620+
621+
var drop = new MenuItem();
622+
drop.Header = App.Text("CommitCM.Drop");
623+
drop.Icon = App.CreateMenuIcon("Icons.Clear");
624+
drop.Click += async (_, e) =>
625+
{
626+
var parent = await new Commands.QuerySingleCommit(_repo.FullPath, commit.Parents[0]).GetResultAsync();
627+
await App.ShowDialog(new InteractiveRebase(_repo, current, parent, Models.InteractiveRebaseAction.Drop));
628+
e.Handled = true;
629+
};
630+
menu.Items.Add(drop);
620631
}
621632

622633
if (current.Head != commit.SHA)

src/ViewModels/InteractiveRebase.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,8 @@ public CommitDetail DetailContext
123123
private set;
124124
}
125125

126-
public InteractiveRebase(Repository repo, Models.Branch current, Models.Commit on)
126+
public InteractiveRebase(Repository repo, Models.Branch current, Models.Commit on, Models.InteractiveRebaseAction lastAction = Models.InteractiveRebaseAction.Pick)
127127
{
128-
var repoPath = repo.FullPath;
129128
_repo = repo;
130129

131130
Current = current;
@@ -135,22 +134,25 @@ public InteractiveRebase(Repository repo, Models.Branch current, Models.Commit o
135134

136135
Task.Run(async () =>
137136
{
138-
var commits = await new Commands.QueryCommitsForInteractiveRebase(repoPath, on.SHA)
137+
var commits = await new Commands.QueryCommitsForInteractiveRebase(repo.FullPath, on.SHA)
139138
.GetResultAsync()
140139
.ConfigureAwait(false);
141140

142141
var list = new List<InteractiveRebaseItem>();
143142
for (var i = 0; i < commits.Count; i++)
144143
{
145144
var c = commits[i];
146-
list.Add(new InteractiveRebaseItem(c.Commit, c.Message, i < commits.Count - 1));
145+
var item = new InteractiveRebaseItem(c.Commit, c.Message, i < commits.Count - 1);
146+
if (i == commits.Count - 1)
147+
item.Action = lastAction;
148+
list.Add(item);
147149
}
148150

149151
Dispatcher.UIThread.Post(() =>
150152
{
151153
Items.AddRange(list);
152154
if (list.Count > 0)
153-
SelectedItem = list[0];
155+
SelectedItem = lastAction == Models.InteractiveRebaseAction.Pick ? list[0] : list[^1];
154156
IsLoading = false;
155157
});
156158
});

0 commit comments

Comments
 (0)