Skip to content

Commit 3e131b4

Browse files
authored
Merge pull request #5244 from gitbutlerapp/fix-incorrect-branch-deletion
Fix for branches incorrectly deleted
2 parents 6ba0bfc + 6ed5434 commit 3e131b4

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

crates/gitbutler-branch-actions/src/actions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ pub fn unapply_without_saving_virtual_branch(project: &Project, branch_id: Stack
252252
let default_target = state.get_default_target()?;
253253
let target_commit = ctx.repository().find_commit(default_target.sha)?;
254254
// NB: unapply_without_saving is also called from save_and_unapply
255-
branch_manager.unapply_without_saving(branch_id, guard.write_permission(), &target_commit)?;
255+
branch_manager.unapply(branch_id, guard.write_permission(), &target_commit, true)?;
256256
state.delete_branch_entry(&branch_id)
257257
}
258258

crates/gitbutler-branch-actions/src/branch_manager/branch_removal.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl BranchManager<'_> {
3939
// Convert the vbranch to a real branch
4040
let real_branch = self.build_real_branch(&mut target_branch)?;
4141

42-
self.unapply_without_saving(branch_id, perm, &target_commit)?;
42+
self.unapply(branch_id, perm, &target_commit, false)?;
4343

4444
vb_state.update_ordering()?;
4545

@@ -53,11 +53,12 @@ impl BranchManager<'_> {
5353
}
5454

5555
#[instrument(level = tracing::Level::DEBUG, skip(self, perm), err(Debug))]
56-
pub(crate) fn unapply_without_saving(
56+
pub(crate) fn unapply(
5757
&self,
5858
branch_id: StackId,
5959
perm: &mut WorktreeWritePermission,
6060
target_commit: &Commit,
61+
delete_vb_state: bool,
6162
) -> Result<()> {
6263
let vb_state = self.ctx.project().virtual_branches();
6364
let Some(branch) = vb_state.try_branch(branch_id)? else {
@@ -128,7 +129,9 @@ impl BranchManager<'_> {
128129
.checkout()
129130
.context("failed to checkout tree")?;
130131

131-
self.ctx.delete_branch_reference(&branch)?;
132+
if delete_vb_state {
133+
self.ctx.delete_branch_reference(&branch)?;
134+
}
132135

133136
vbranch::ensure_selected_for_changes(&vb_state)
134137
.context("failed to ensure selected for changes")?;

0 commit comments

Comments
 (0)