Skip to content

Commit be6d875

Browse files
committed
Add pop stash command on Staches tab
1 parent 1d90219 commit be6d875

File tree

9 files changed

+84
-7
lines changed

9 files changed

+84
-7
lines changed

Diff for: assets/vim_style_key_config.ron

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161

6262
stash_open: ( code: Char('l'), modifiers: ( bits: 0,),),
6363
stash_drop: ( code: Char('D'), modifiers: ( bits: 1,),),
64+
stash_pop: ( code: Char('P'), modifiers: ( bits: 1,),),
6465

6566
cmd_bar_toggle: ( code: Char('.'), modifiers: ( bits: 0,),),
6667
log_tag_commit: ( code: Char('t'), modifiers: ( bits: 0,),),

Diff for: asyncgit/src/sync/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ pub use remotes::{
5151
};
5252
pub use reset::{reset_stage, reset_workdir};
5353
pub use staging::{discard_lines, stage_lines};
54-
pub use stash::{get_stashes, stash_apply, stash_drop, stash_save};
54+
pub use stash::{
55+
get_stashes, stash_apply, stash_drop, stash_pop, stash_save,
56+
};
5557
pub use state::{repo_state, RepoState};
5658
pub use tags::{get_tags, CommitTags, Tags};
5759
pub use utils::{

Diff for: asyncgit/src/sync/stash.rs

+22
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,28 @@ pub fn stash_drop(repo_path: &str, stash_id: CommitId) -> Result<()> {
4444
Ok(())
4545
}
4646

47+
///
48+
pub fn stash_pop(
49+
repo_path: &str,
50+
stash_id: CommitId,
51+
allow_conflicts: bool,
52+
) -> Result<()> {
53+
scope_time!("stash_pop");
54+
55+
let mut repo = repo(repo_path)?;
56+
57+
let index = get_stash_index(&mut repo, stash_id.into())?;
58+
59+
let mut checkout = CheckoutBuilder::new();
60+
checkout.allow_conflicts(allow_conflicts);
61+
62+
let mut opt = StashApplyOptions::default();
63+
opt.checkout_options(checkout);
64+
repo.stash_pop(index, Some(&mut opt))?;
65+
66+
Ok(())
67+
}
68+
4769
///
4870
pub fn stash_apply(
4971
repo_path: &str,

Diff for: src/app.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,8 @@ impl App {
494494
flags.insert(NeedsUpdate::ALL);
495495
}
496496
}
497-
Action::StashDrop(s) => {
498-
if StashList::drop(s) {
497+
Action::StashDrop(_) | Action::StashPop(_) => {
498+
if StashList::action_confirmed(&action) {
499499
flags.insert(NeedsUpdate::ALL);
500500
}
501501
}

Diff for: src/components/reset.rs

+4
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ impl ResetComponent {
147147
),
148148
strings::confirm_msg_stashdrop(&self.key_config),
149149
),
150+
Action::StashPop(_) => (
151+
strings::confirm_title_stashpop(&self.key_config),
152+
strings::confirm_msg_stashpop(&self.key_config),
153+
),
150154
Action::ResetHunk(_, _) => (
151155
strings::confirm_title_reset(&self.key_config),
152156
strings::confirm_msg_resethunk(&self.key_config),

Diff for: src/keys.rs

+2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ pub struct KeyConfig {
5858
pub stashing_toggle_index: KeyEvent,
5959
pub stash_open: KeyEvent,
6060
pub stash_drop: KeyEvent,
61+
pub stash_pop: KeyEvent,
6162
pub cmd_bar_toggle: KeyEvent,
6263
pub log_tag_commit: KeyEvent,
6364
pub commit_amend: KeyEvent,
@@ -114,6 +115,7 @@ impl Default for KeyConfig {
114115
stashing_toggle_index: KeyEvent { code: KeyCode::Char('i'), modifiers: KeyModifiers::empty()},
115116
stash_open: KeyEvent { code: KeyCode::Right, modifiers: KeyModifiers::empty()},
116117
stash_drop: KeyEvent { code: KeyCode::Char('D'), modifiers: KeyModifiers::SHIFT},
118+
stash_pop: KeyEvent { code: KeyCode::Char('P'), modifiers: KeyModifiers::SHIFT},
117119
cmd_bar_toggle: KeyEvent { code: KeyCode::Char('.'), modifiers: KeyModifiers::empty()},
118120
log_tag_commit: KeyEvent { code: KeyCode::Char('t'), modifiers: KeyModifiers::empty()},
119121
commit_amend: KeyEvent { code: KeyCode::Char('a'), modifiers: KeyModifiers::CONTROL},

Diff for: src/queue.rs

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub enum Action {
2929
ResetHunk(String, u64),
3030
ResetLines(String, Vec<DiffLinePosition>),
3131
StashDrop(CommitId),
32+
StashPop(CommitId),
3233
DeleteBranch(String),
3334
ForcePush(String, bool),
3435
PullMerge { incoming: usize, rebase: bool },

Diff for: src/strings.rs

+21
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,11 @@ pub fn confirm_title_stashdrop(
9696
) -> String {
9797
"Drop".to_string()
9898
}
99+
pub fn confirm_title_stashpop(
100+
_key_config: &SharedKeyConfig,
101+
) -> String {
102+
"Pop".to_string()
103+
}
99104
pub fn confirm_title_merge(
100105
_key_config: &SharedKeyConfig,
101106
rebase: bool,
@@ -134,6 +139,10 @@ pub fn confirm_msg_stashdrop(
134139
) -> String {
135140
"confirm stash drop?".to_string()
136141
}
142+
pub fn confirm_msg_stashpop(_key_config: &SharedKeyConfig) -> String {
143+
"The stash will be applied and then remove from the stash list. Confirm stash pop?"
144+
.to_string()
145+
}
137146
pub fn confirm_msg_resethunk(
138147
_key_config: &SharedKeyConfig,
139148
) -> String {
@@ -766,6 +775,18 @@ pub mod commands {
766775
CMD_GROUP_STASHES,
767776
)
768777
}
778+
pub fn stashlist_pop(
779+
key_config: &SharedKeyConfig,
780+
) -> CommandText {
781+
CommandText::new(
782+
format!(
783+
"Pop [{}]",
784+
key_config.get_hint(key_config.stash_pop),
785+
),
786+
"pop selected stash",
787+
CMD_GROUP_STASHES,
788+
)
789+
}
769790
pub fn stashlist_inspect(
770791
key_config: &SharedKeyConfig,
771792
) -> CommandText {

Diff for: src/tabs/stashlist.rs

+28-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::{
1010
};
1111
use anyhow::Result;
1212
use asyncgit::{
13-
sync::{self, CommitId},
13+
sync::{self},
1414
CWD,
1515
};
1616
use crossterm::event::Event;
@@ -83,6 +83,14 @@ impl StashList {
8383
}
8484
}
8585

86+
fn pop_stash(&mut self) {
87+
if let Some(e) = self.list.selected_entry() {
88+
self.queue.borrow_mut().push_back(
89+
InternalEvent::ConfirmAction(Action::StashPop(e.id)),
90+
);
91+
}
92+
}
93+
8694
fn inspect(&mut self) {
8795
if let Some(e) = self.list.selected_entry() {
8896
self.queue
@@ -91,9 +99,17 @@ impl StashList {
9199
}
92100
}
93101

94-
///
95-
pub fn drop(id: CommitId) -> bool {
96-
sync::stash_drop(CWD, id).is_ok()
102+
/// Called when a pending stash action has been confirmed
103+
pub fn action_confirmed(action: &Action) -> bool {
104+
match *action {
105+
Action::StashDrop(id) => {
106+
sync::stash_drop(CWD, id).is_ok()
107+
}
108+
Action::StashPop(id) => {
109+
sync::stash_pop(CWD, id, false).is_ok()
110+
}
111+
_ => false,
112+
}
97113
}
98114
}
99115

@@ -130,6 +146,12 @@ impl Component for StashList {
130146
selection_valid,
131147
true,
132148
));
149+
150+
out.push(CommandInfo::new(
151+
strings::commands::stashlist_pop(&self.key_config),
152+
selection_valid,
153+
true,
154+
));
133155
out.push(CommandInfo::new(
134156
strings::commands::stashlist_inspect(
135157
&self.key_config,
@@ -151,6 +173,8 @@ impl Component for StashList {
151173
if let Event::Key(k) = ev {
152174
if k == self.key_config.enter {
153175
self.apply_stash()
176+
} else if k == self.key_config.stash_pop {
177+
self.pop_stash()
154178
} else if k == self.key_config.stash_drop {
155179
self.drop_stash()
156180
} else if k == self.key_config.stash_open {

0 commit comments

Comments
 (0)