Skip to content

Commit fe743bd

Browse files
committed
fix: Stash pop removes stash from list even when there are conflicts
1 parent 1866bf5 commit fe743bd

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111
* use default shell instead of bash on Unix-like OS [[@yerke](https://github.com/yerke)] ([#2343](https://github.com/extrawurst/gitui/pull/2343))
1212

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

asyncgit/src/error.rs

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ pub enum Error {
2121
#[error("git: conflict during rebase")]
2222
RebaseConflict,
2323

24+
///
25+
#[error("git: conflict during stash apply")]
26+
StashApplyConflict,
27+
2428
///
2529
#[error("git: remote url not found")]
2630
UnknownRemote,

asyncgit/src/sync/stash.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,21 @@ pub fn stash_pop(
5050

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

53-
repo.stash_pop(index, None)?;
53+
// todo: The allow_conflicts parameter set in CheckoutBuilder is not actually taking effect.
54+
let mut checkout = CheckoutBuilder::new();
55+
checkout.allow_conflicts(false);
56+
57+
let mut opt = StashApplyOptions::default();
58+
opt.checkout_options(checkout);
59+
repo.stash_apply(index, None)?;
60+
61+
// check for merge conflicts
62+
if repo.index()?.has_conflicts() {
63+
return Err(Error::StashApplyConflict);
64+
}
65+
66+
// remove the entry at the specified index from the stash list
67+
repo.stash_drop(index)?;
5468

5569
Ok(())
5670
}

0 commit comments

Comments
 (0)