Skip to content

Commit 72f0458

Browse files
committed
use new picker during cherry-pick
1 parent bea883e commit 72f0458

2 files changed

Lines changed: 25 additions & 23 deletions

File tree

src/ops/cherry_pick.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ use std::{process::Command, rc::Rc};
22

33
use crate::{
44
Res,
5-
app::{App, PromptParams, State},
6-
item_data::{ItemData, Rev},
5+
app::{App, State},
6+
git,
7+
item_data::ItemData,
78
menu::arg::Arg,
9+
picker::{PickerParams, PickerState},
810
term::Term,
911
};
1012

@@ -52,23 +54,23 @@ impl OpTrait for CherryPickContinue {
5254

5355
pub(crate) struct CherryPick;
5456
impl OpTrait for CherryPick {
55-
fn get_action(&self, _target: &ItemData) -> Option<Action> {
57+
fn get_action(&self, target: &ItemData) -> Option<Action> {
58+
let rev = target.rev();
5659
Some(Rc::new(move |app: &mut App, term: &mut Term| {
57-
let commit = app.prompt(
60+
let result = app.pick(
5861
term,
59-
&PromptParams {
60-
prompt: "Cherry-pick commit",
61-
create_default_value: Box::new(|app| {
62-
selected_rev(app)
63-
.as_ref()
64-
.map(Rev::shorthand)
65-
.map(String::from)
66-
}),
67-
..Default::default()
68-
},
62+
PickerState::with_refs(PickerParams {
63+
prompt: "Cherry-pick".into(),
64+
refs: &git::branches_tags(&app.state.repo)?,
65+
exclude_ref: git::head_ref(&app.state.repo)?,
66+
default: rev.clone().or_else(|| selected_rev(app)),
67+
allow_custom_input: true,
68+
}),
6969
)?;
7070

71-
cherry_pick(app, term, &commit)?;
71+
if let Some(data) = result {
72+
cherry_pick(app, term, data.display())?;
73+
}
7274
Ok(())
7375
}))
7476
}

src/tests/snapshots/gitu__tests__cherry_pick__cherry_pick_prompt.snap

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,24 @@
22
source: src/tests/cherry_pick.rs
33
expression: ctx.redact_buffer()
44
---
5-
b66a0bf main origin/main add initial-file |
6-
|
7-
|
8-
|
9-
|
5+
b66a0bf main origin/main add initial-file |
106
|
117
|
128
|
139
|
1410
|
1511
|
1612
|
13+
────────────────────────────────────────────────────────────────────────────────|
14+
4/4 Cherry-pick › █ |
15+
main |
16+
other-branch |
17+
origin/HEAD |
18+
origin/main |
1719
|
1820
|
1921
|
2022
|
2123
|
2224
|
23-
────────────────────────────────────────────────────────────────────────────────|
24-
? Cherry-pick commit (default main): › █ |
25-
styles_hash: bee94fff2519b82b
25+
styles_hash: f868f120e27e8b1b

0 commit comments

Comments
 (0)