From 8c012449255001ff78b54371d38c649dce186f56 Mon Sep 17 00:00:00 2001 From: Caleb Owens Date: Mon, 7 Oct 2024 11:01:30 +0200 Subject: [PATCH] Fix upstream integration when there are no new branches This is important as it will otherwise look like you've got the inverse diff in your uncommited changes. --- .../src/upstream_integration.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/gitbutler-branch-actions/src/upstream_integration.rs b/crates/gitbutler-branch-actions/src/upstream_integration.rs index 95a852b41..e271e2e42 100644 --- a/crates/gitbutler-branch-actions/src/upstream_integration.rs +++ b/crates/gitbutler-branch-actions/src/upstream_integration.rs @@ -326,9 +326,22 @@ pub(crate) fn integrate_upstream( virtual_branches_state.set_branch(branch.clone())?; } - // Now that we've potentially updated the branch trees, lets checkout - // the result of merging them all together. - checkout_branch_trees(command_context, permission)?; + // checkout_branch_trees won't checkout anything if there are no + // applied branches, and returns the current_wd_tree as its result. + // This is very sensible, but in this case, we want to checkout the + // new target sha. + if branches.is_empty() { + context + .repository + .checkout_tree_builder(&context.new_target.tree()?) + .force() + .remove_untracked() + .checkout()?; + } else { + // Now that we've potentially updated the branch trees, lets checkout + // the result of merging them all together. + checkout_branch_trees(command_context, permission)?; + } virtual_branches_state.set_default_target(Target { sha: context.new_target.id(),