Skip to content

Commit

Permalink
fix: Stash pop removes stash from list even when there are conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
wugeer committed Oct 19, 2024
1 parent 1866bf5 commit 561af4a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
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

0 comments on commit 561af4a

Please sign in to comment.