From 561af4ae40dca3f56b8b7cc37cf8b6e4ee08d98e Mon Sep 17 00:00:00 2001 From: wugeer <1284057728@qq.com> Date: Sat, 19 Oct 2024 15:31:44 +0800 Subject: [PATCH] fix: Stash pop removes stash from list even when there are conflicts --- CHANGELOG.md | 1 + asyncgit/src/error.rs | 4 ++++ asyncgit/src/sync/stash.rs | 16 +++++++++++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 59b1710c60..d273395f93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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)) diff --git a/asyncgit/src/error.rs b/asyncgit/src/error.rs index 37fba9fa91..bea455f5ab 100644 --- a/asyncgit/src/error.rs +++ b/asyncgit/src/error.rs @@ -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, diff --git a/asyncgit/src/sync/stash.rs b/asyncgit/src/sync/stash.rs index c496168116..48a9d066d9 100644 --- a/asyncgit/src/sync/stash.rs +++ b/asyncgit/src/sync/stash.rs @@ -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(()) }