diff --git a/src/default_config.toml b/src/default_config.toml index 5848e7e476..0ec410d881 100644 --- a/src/default_config.toml +++ b/src/default_config.toml @@ -214,4 +214,5 @@ stash_menu.stash_keep_index = ["x"] stash_menu.stash_pop = ["p"] stash_menu.stash_apply = ["a"] stash_menu.stash_drop = ["k"] +stash_menu.stash_clear = ["c"] stash_menu.quit = ["q", "esc"] diff --git a/src/ops/mod.rs b/src/ops/mod.rs index 1f748452bc..9d70d73120 100644 --- a/src/ops/mod.rs +++ b/src/ops/mod.rs @@ -78,6 +78,7 @@ pub(crate) enum Op { StashKeepIndex, StashPop, StashDrop, + StashClear, CommitFixup, CommitInstantFixup, LogOther, @@ -165,6 +166,7 @@ impl Op { Op::StashKeepIndex => Box::new(stash::StashKeepIndex), Op::StashPop => Box::new(stash::StashPop), Op::StashDrop => Box::new(stash::StashDrop), + Op::StashClear => Box::new(stash::StashClear), Op::CommitFixup => Box::new(commit::CommitFixup), Op::CommitInstantFixup => Box::new(commit::CommitInstantFixup), diff --git a/src/ops/stash.rs b/src/ops/stash.rs index 7dc47f0665..a61052cfa0 100644 --- a/src/ops/stash.rs +++ b/src/ops/stash.rs @@ -319,6 +319,29 @@ fn stash_drop(app: &mut App, term: &mut Term, input: &str) -> Res<()> { Ok(()) } +pub(crate) struct StashClear; +impl OpTrait for StashClear { + fn get_action(&self, _target: &ItemData) -> Option { + Some(Rc::new(move |app: &mut App, term: &mut Term| { + stash_clear(app, term)?; + Ok(()) + })) + } + + fn display(&self, _state: &State) -> String { + "clear".into() + } +} + +fn stash_clear(app: &mut App, term: &mut Term) -> Res<()> { + let mut cmd = Command::new("git"); + cmd.args(["stash", "clear"]); + + app.close_menu(); + app.run_cmd(term, &[], cmd)?; + Ok(()) +} + fn selected_stash(app: &App) -> Option { match app.screen().get_selected_item().data { ItemData::Stash { id, .. } => Some(id.to_string()),