diff --git a/src/ops/cherry_pick.rs b/src/ops/cherry_pick.rs index 12e024084c..53b7847133 100644 --- a/src/ops/cherry_pick.rs +++ b/src/ops/cherry_pick.rs @@ -2,9 +2,11 @@ use std::{process::Command, rc::Rc}; use crate::{ Res, - app::{App, PromptParams, State}, - item_data::{ItemData, Rev}, + app::{App, State}, + git, + item_data::ItemData, menu::arg::Arg, + picker::{PickerParams, PickerState}, term::Term, }; @@ -52,23 +54,23 @@ impl OpTrait for CherryPickContinue { pub(crate) struct CherryPick; impl OpTrait for CherryPick { - fn get_action(&self, _target: &ItemData) -> Option { + fn get_action(&self, target: &ItemData) -> Option { + let rev = target.rev(); Some(Rc::new(move |app: &mut App, term: &mut Term| { - let commit = app.prompt( + let result = app.pick( term, - &PromptParams { - prompt: "Cherry-pick commit", - create_default_value: Box::new(|app| { - selected_rev(app) - .as_ref() - .map(Rev::shorthand) - .map(String::from) - }), - ..Default::default() - }, + PickerState::with_refs(PickerParams { + prompt: "Cherry-pick".into(), + refs: &git::branches_tags(&app.state.repo)?, + exclude_ref: git::head_ref(&app.state.repo)?, + default: rev.clone().or_else(|| selected_rev(app)), + allow_custom_input: true, + }), )?; - cherry_pick(app, term, &commit)?; + if let Some(data) = result { + cherry_pick(app, term, data.display())?; + } Ok(()) })) } diff --git a/src/tests/snapshots/gitu__tests__cherry_pick__cherry_pick_prompt.snap b/src/tests/snapshots/gitu__tests__cherry_pick__cherry_pick_prompt.snap index 7d58d2470f..bd64720487 100644 --- a/src/tests/snapshots/gitu__tests__cherry_pick__cherry_pick_prompt.snap +++ b/src/tests/snapshots/gitu__tests__cherry_pick__cherry_pick_prompt.snap @@ -2,11 +2,7 @@ source: src/tests/cherry_pick.rs expression: ctx.redact_buffer() --- -▌b66a0bf main origin/main add initial-file | - | - | - | - | + b66a0bf main origin/main add initial-file | | | | @@ -14,12 +10,16 @@ expression: ctx.redact_buffer() | | | +────────────────────────────────────────────────────────────────────────────────| + 4/4 Cherry-pick › █ | +▌main | + other-branch | + origin/HEAD | + origin/main | | | | | | | -────────────────────────────────────────────────────────────────────────────────| -? Cherry-pick commit (default main): › █ | -styles_hash: bee94fff2519b82b +styles_hash: f868f120e27e8b1b