|
| 1 | +use std::{process::Command, rc::Rc}; |
| 2 | + |
| 3 | +use crate::{ |
| 4 | + Res, |
| 5 | + app::{App, PromptParams, State}, |
| 6 | + item_data::{ItemData, Rev}, |
| 7 | + menu::arg::Arg, |
| 8 | + term::Term, |
| 9 | +}; |
| 10 | + |
| 11 | +use super::{Action, OpTrait, selected_rev}; |
| 12 | + |
| 13 | +pub(crate) fn init_args() -> Vec<Arg> { |
| 14 | + vec![ |
| 15 | + Arg::new_flag("--no-commit", "Don't commit", false), |
| 16 | + Arg::new_flag("--signoff", "Add Signed-off-by lines", false), |
| 17 | + Arg::new_flag("--edit", "Edit commit message", false), |
| 18 | + ] |
| 19 | +} |
| 20 | + |
| 21 | +pub(crate) struct CherryPickAbort; |
| 22 | +impl OpTrait for CherryPickAbort { |
| 23 | + fn get_action(&self, _target: &ItemData) -> Option<Action> { |
| 24 | + Some(Rc::new(|app: &mut App, term: &mut Term| { |
| 25 | + let mut cmd = Command::new("git"); |
| 26 | + cmd.args(["cherry-pick", "--abort"]); |
| 27 | + app.run_cmd_interactive(term, cmd)?; |
| 28 | + Ok(()) |
| 29 | + })) |
| 30 | + } |
| 31 | + |
| 32 | + fn display(&self, _state: &State) -> String { |
| 33 | + "Abort".into() |
| 34 | + } |
| 35 | +} |
| 36 | + |
| 37 | +pub(crate) struct CherryPickContinue; |
| 38 | +impl OpTrait for CherryPickContinue { |
| 39 | + fn get_action(&self, _target: &ItemData) -> Option<Action> { |
| 40 | + Some(Rc::new(|app: &mut App, term: &mut Term| { |
| 41 | + let mut cmd = Command::new("git"); |
| 42 | + cmd.args(["cherry-pick", "--continue"]); |
| 43 | + app.run_cmd_interactive(term, cmd)?; |
| 44 | + Ok(()) |
| 45 | + })) |
| 46 | + } |
| 47 | + |
| 48 | + fn display(&self, _state: &State) -> String { |
| 49 | + "Continue".into() |
| 50 | + } |
| 51 | +} |
| 52 | + |
| 53 | +pub(crate) struct CherryPick; |
| 54 | +impl OpTrait for CherryPick { |
| 55 | + fn get_action(&self, _target: &ItemData) -> Option<Action> { |
| 56 | + Some(Rc::new(move |app: &mut App, term: &mut Term| { |
| 57 | + let commit = app.prompt( |
| 58 | + 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 | + }, |
| 69 | + )?; |
| 70 | + |
| 71 | + cherry_pick(app, term, &commit)?; |
| 72 | + Ok(()) |
| 73 | + })) |
| 74 | + } |
| 75 | + |
| 76 | + fn display(&self, _state: &State) -> String { |
| 77 | + "Cherry-pick commit(s)".into() |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +fn cherry_pick(app: &mut App, term: &mut Term, input: &str) -> Res<()> { |
| 82 | + let mut cmd = Command::new("git"); |
| 83 | + cmd.arg("cherry-pick"); |
| 84 | + cmd.args(app.state.pending_menu.as_ref().unwrap().args()); |
| 85 | + cmd.arg(input); |
| 86 | + app.run_cmd_interactive(term, cmd) |
| 87 | +} |
0 commit comments