Skip to content
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

fix: Stash pop removes stash from list even when there are conflicts #2382

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* use default shell instead of bash on Unix-like OS [[@yerke](https://github.com/yerke)] ([#2343](https://github.com/extrawurst/gitui/pull/2343))

### Fixes
* Stash pop removes stash from list even when there are conflicts([#2372](https://github.com/extrawurst/gitui/issues/2372))
* respect env vars like `GIT_CONFIG_GLOBAL` ([#2298](https://github.com/extrawurst/gitui/issues/2298))
* Set `CREATE_NO_WINDOW` flag when executing Git hooks on Windows ([#2371](https://github.com/extrawurst/gitui/pull/2371))

Expand Down
4 changes: 4 additions & 0 deletions asyncgit/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ pub enum Error {
#[error("git: conflict during rebase")]
RebaseConflict,

///
#[error("git: conflict during stash apply")]
StashApplyConflict,

///
#[error("git: remote url not found")]
UnknownRemote,
Expand Down
16 changes: 15 additions & 1 deletion asyncgit/src/sync/stash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,21 @@ pub fn stash_pop(

let index = get_stash_index(&mut repo, stash_id.into())?;

repo.stash_pop(index, None)?;
// todo: The allow_conflicts parameter set in CheckoutBuilder is not actually taking effect.
let mut checkout = CheckoutBuilder::new();
checkout.allow_conflicts(false);

let mut opt = StashApplyOptions::default();
opt.checkout_options(checkout);
repo.stash_apply(index, None)?;

// check for merge conflicts
if repo.index()?.has_conflicts() {
return Err(Error::StashApplyConflict);
}

// remove the entry at the specified index from the stash list
repo.stash_drop(index)?;

Ok(())
}
Expand Down