Skip to content

Commit 0ed5a91

Browse files
committed
fix: skip redundant tree removal when branch already unmounted
When a branch had both UnmountBranch (from a closed PR) and DeleteLocalBranch (e.g. SHA seen on remote) in the same sync plan, the delete handler would try to remove it from the tree a second time and fail with 'not found in the git-stack tree'. Check tree membership first and skip the repeat removal.
1 parent 35e68dd commit 0ed5a91

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/sync.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,13 +1360,20 @@ fn apply_local_change(
13601360
// Remove from git-stack tree ONLY if the remote is also gone
13611361
// For AncestorOfRemote, we keep the branch in tree since remote still exists
13621362
if !matches!(reason, DeleteReason::AncestorOfRemote) {
1363-
let repoint_to = state
1364-
.get_parent_branch_of(repo, name)
1365-
.map(|p| p.name.clone())
1366-
.or_else(|| state.get_tree(repo).map(|t| t.name.clone()))
1367-
.unwrap_or_else(|| "main".to_string());
1368-
unmount_branch_from_tree(git_repo, state, repo, name, &repoint_to)?;
1369-
println!(" Removed '{}' from git-stack tree.", name);
1363+
// A prior UnmountBranch in the same plan may have already removed it.
1364+
let still_in_tree = state
1365+
.get_tree(repo)
1366+
.and_then(|t| find_branch_by_name(t, name))
1367+
.is_some();
1368+
if still_in_tree {
1369+
let repoint_to = state
1370+
.get_parent_branch_of(repo, name)
1371+
.map(|p| p.name.clone())
1372+
.or_else(|| state.get_tree(repo).map(|t| t.name.clone()))
1373+
.unwrap_or_else(|| "main".to_string());
1374+
unmount_branch_from_tree(git_repo, state, repo, name, &repoint_to)?;
1375+
println!(" Removed '{}' from git-stack tree.", name);
1376+
}
13701377
}
13711378
}
13721379
}

0 commit comments

Comments
 (0)