Fix for branches incorrectly deleted

If a branch is being "unapplied' due to conflicts - dont delete the state
This commit is contained in:
Kiril Videlov 2024-10-21 14:42:24 +02:00
parent dfec47a962
commit 6ed54349d0
2 changed files with 7 additions and 4 deletions

View File

@ -252,7 +252,7 @@ pub fn unapply_without_saving_virtual_branch(project: &Project, branch_id: Stack
let default_target = state.get_default_target()?; let default_target = state.get_default_target()?;
let target_commit = ctx.repository().find_commit(default_target.sha)?; let target_commit = ctx.repository().find_commit(default_target.sha)?;
// NB: unapply_without_saving is also called from save_and_unapply // NB: unapply_without_saving is also called from save_and_unapply
branch_manager.unapply_without_saving(branch_id, guard.write_permission(), &target_commit)?; branch_manager.unapply(branch_id, guard.write_permission(), &target_commit, true)?;
state.delete_branch_entry(&branch_id) state.delete_branch_entry(&branch_id)
} }

View File

@ -39,7 +39,7 @@ impl BranchManager<'_> {
// Convert the vbranch to a real branch // Convert the vbranch to a real branch
let real_branch = self.build_real_branch(&mut target_branch)?; let real_branch = self.build_real_branch(&mut target_branch)?;
self.unapply_without_saving(branch_id, perm, &target_commit)?; self.unapply(branch_id, perm, &target_commit, false)?;
vb_state.update_ordering()?; vb_state.update_ordering()?;
@ -53,11 +53,12 @@ impl BranchManager<'_> {
} }
#[instrument(level = tracing::Level::DEBUG, skip(self, perm), err(Debug))] #[instrument(level = tracing::Level::DEBUG, skip(self, perm), err(Debug))]
pub(crate) fn unapply_without_saving( pub(crate) fn unapply(
&self, &self,
branch_id: StackId, branch_id: StackId,
perm: &mut WorktreeWritePermission, perm: &mut WorktreeWritePermission,
target_commit: &Commit, target_commit: &Commit,
delete_vb_state: bool,
) -> Result<()> { ) -> Result<()> {
let vb_state = self.ctx.project().virtual_branches(); let vb_state = self.ctx.project().virtual_branches();
let Some(branch) = vb_state.try_branch(branch_id)? else { let Some(branch) = vb_state.try_branch(branch_id)? else {
@ -128,7 +129,9 @@ impl BranchManager<'_> {
.checkout() .checkout()
.context("failed to checkout tree")?; .context("failed to checkout tree")?;
self.ctx.delete_branch_reference(&branch)?; if delete_vb_state {
self.ctx.delete_branch_reference(&branch)?;
}
vbranch::ensure_selected_for_changes(&vb_state) vbranch::ensure_selected_for_changes(&vb_state)
.context("failed to ensure selected for changes")?; .context("failed to ensure selected for changes")?;