Skip to content

Add pop stash command on Staches tab #628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 11, 2021

Conversation

brunogouveia
Copy link
Contributor

As an alternative to asking whether the stash should be removed every time the user applies it, I added the stash pop command to the Stashes tab.

I personally prefer having two commands: one for quick apply and one for pop.

Let me know what you think.

Closes #574

@brunogouveia
Copy link
Contributor Author

brunogouveia commented Apr 9, 2021

This is what it looks like

Screenshot 2021-04-10 at 00 00 06

@brunogouveia brunogouveia force-pushed the stash-pop branch 2 times, most recently from 5312e1f to be6d875 Compare April 9, 2021 23:46
Copy link
Collaborator

@extrawurst extrawurst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really cool! Just a few smaller comments

@@ -44,6 +44,28 @@ pub fn stash_drop(repo_path: &str, stash_id: CommitId) -> Result<()> {
Ok(())
}

///
pub fn stash_pop(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add matching unittests for this new method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

pub fn stash_pop(
repo_path: &str,
stash_id: CommitId,
allow_conflicts: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets simplify the signature as long as we do not make use of allow_conflicts to be false anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reasoning was to follow how we implemented stash_apply, which also is only called with allow_conflicts: false. Tbh I assumed there was plans to eventually use this flag, but I can remove it for now.

src/keys.rs Outdated
@@ -114,6 +115,7 @@ impl Default for KeyConfig {
stashing_toggle_index: KeyEvent { code: KeyCode::Char('i'), modifiers: KeyModifiers::empty()},
stash_open: KeyEvent { code: KeyCode::Right, modifiers: KeyModifiers::empty()},
stash_drop: KeyEvent { code: KeyCode::Char('D'), modifiers: KeyModifiers::SHIFT},
stash_pop: KeyEvent { code: KeyCode::Char('P'), modifiers: KeyModifiers::SHIFT},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue that pop should be the default: using enter as the key and apply should be the new key (maybe even a)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way is fine IMHO, but I slightly prefer apply to be the default (since is the action I mostly use); I only use pop or drop when I'm absolutely sure I don't need that stash anymore.

The reason I decided to create a new key is to not implicitly change the current user experience (e.g., I usually don't check the action bar in order to figure out which key combination triggers an action) and have users accidentally dropping stashes because enter used to be git apply. We could make the default action configurable (and we could extend this concept to any other tab), although I don't think that is currently supported (?).

Let me know if I should make pop the default.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a fan of config files - there is none in gitui (aside keys and theme)

I was thinking about the same and I would agree if the new action was implicit but it is not it introduces a confirmation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I changed stash pop to be the default and changed stash apply to key a

sync::stash_drop(CWD, id).is_ok()
}

fn pop(&self, id: CommitId) -> bool {
match sync::stash_pop(CWD, id) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pattern seems pretty common: we run a git command synchronously and queue a InternalEvent when it succeeds or a ShowErrorMsg otherwise. I will take a look in a more DRY approach for the common cases. I don't want to make it part of this PR though.

@brunogouveia brunogouveia requested a review from extrawurst April 10, 2021 18:27
@extrawurst extrawurst merged commit 79a38a7 into gitui-org:master Apr 11, 2021
@extrawurst
Copy link
Collaborator

@brunogouveia Really cool, thanks for this!❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ask to delete stash after apply
2 participants