Skip to content

Commit 13a16fd

Browse files
committed
feat(rebase): use new picker when selecting a rebase target
1 parent 2dc8137 commit 13a16fd

2 files changed

Lines changed: 39 additions & 25 deletions

File tree

src/ops/rebase.rs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
use super::{Action, OpTrait, selected_rev};
1+
use super::{Action, OpTrait};
22
use crate::{
33
Res,
4-
app::{App, PromptParams, State},
5-
item_data::{ItemData, Ref, Rev},
4+
app::{App, State},
5+
git,
6+
item_data::{ItemData, Ref},
67
menu::arg::Arg,
8+
picker::{PickerParams, PickerState},
79
term::Term,
810
};
911
use std::{
@@ -66,23 +68,30 @@ impl OpTrait for RebaseAbort {
6668

6769
pub(crate) struct RebaseElsewhere;
6870
impl OpTrait for RebaseElsewhere {
69-
fn get_action(&self, _target: &ItemData) -> Option<Action> {
71+
fn get_action(&self, target: &ItemData) -> Option<Action> {
72+
let default_ref = if let ItemData::Reference { kind, .. } = target {
73+
Some(kind.clone())
74+
} else {
75+
None
76+
};
77+
7078
Some(Rc::new(move |app: &mut App, term: &mut Term| {
71-
let rev = app.prompt(
79+
let args = app.state.pending_menu.as_ref().unwrap().args();
80+
app.close_menu();
81+
let result = app.pick(
7282
term,
73-
&PromptParams {
74-
prompt: "Rebase onto",
75-
create_default_value: Box::new(|app| {
76-
selected_rev(app)
77-
.as_ref()
78-
.map(Rev::shorthand)
79-
.map(String::from)
80-
}),
81-
..Default::default()
82-
},
83+
PickerState::with_refs(PickerParams {
84+
prompt: "Rebase onto".into(),
85+
refs: &git::branches_tags(&app.state.repo)?,
86+
exclude_ref: git::head_ref(&app.state.repo)?,
87+
default: default_ref.clone().map(crate::item_data::Rev::Ref),
88+
allow_custom_input: true,
89+
}),
8390
)?;
8491

85-
rebase_elsewhere(app, term, &rev)?;
92+
if let Some(data) = result {
93+
rebase_elsewhere(app, term, data.display(), &args)?;
94+
}
8695
Ok(())
8796
}))
8897
}
@@ -92,10 +101,15 @@ impl OpTrait for RebaseElsewhere {
92101
}
93102
}
94103

95-
fn rebase_elsewhere(app: &mut App, term: &mut Term, rev: &str) -> Res<()> {
104+
fn rebase_elsewhere(
105+
app: &mut App,
106+
term: &mut Term,
107+
rev: &str,
108+
args: &[std::ffi::OsString],
109+
) -> Res<()> {
96110
let mut cmd = Command::new("git");
97111
cmd.arg("rebase");
98-
cmd.args(app.state.pending_menu.as_ref().unwrap().args());
112+
cmd.args(args);
99113
cmd.arg(rev);
100114

101115
app.close_menu();

src/tests/snapshots/gitu__tests__rebase__rebase_elsewhere_prompt.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22
source: src/tests/rebase.rs
33
expression: ctx.redact_buffer()
44
---
5-
On branch other-branch |
5+
On branch other-branch |
66
|
77
Recent commits |
88
b66a0bf other-branch origin/main add initial-file |
99
|
1010
|
1111
|
1212
|
13+
────────────────────────────────────────────────────────────────────────────────|
14+
3/3 Rebase onto › █ |
15+
main |
16+
origin/HEAD |
17+
origin/main |
1318
|
1419
|
1520
|
1621
|
1722
|
1823
|
1924
|
20-
|
21-
|
22-
|
23-
────────────────────────────────────────────────────────────────────────────────|
24-
? Rebase onto: › █ |
25-
styles_hash: 53f8a523dd3a4d8a
25+
styles_hash: 65f4fc0ca3a35c1e

0 commit comments

Comments
 (0)