Skip to content
Draft

TMP #10737

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 31 additions & 14 deletions crates/gitbutler-branch-actions/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,13 @@ pub(crate) fn set_base_branch(
r.stash_save2(&sig, None, Some(git2::StashFlags::INCLUDE_UNTRACKED))?;
}

// if target exists, and it is the same as the requested branch, we should go back
if let Ok(target) = default_target(&ctx.project().gb_dir())
&& target.branch.eq(target_branch_ref)
{
return go_back_to_integration(ctx, &target);
if !ctx.app_settings().feature_flags.single_branch {
// // if target exists, and it is the same as the requested branch, we should go back
if let Ok(target) = default_target(&ctx.project().gb_dir())
&& target.branch.eq(target_branch_ref)
{
return go_back_to_integration(ctx, &target);
}
}

// lookup a branch by name
Expand Down Expand Up @@ -169,7 +171,27 @@ pub(crate) fn set_base_branch(
let vb_state = ctx.project().virtual_branches();
vb_state.set_default_target(target.clone())?;

// TODO: make sure this is a real branch
if !ctx.app_settings().feature_flags.single_branch {
maybe_checkout_target(ctx)?;
}

// This is a side effect that should not be here
set_exclude_decoration(ctx)?;
// We almost certainly don't need this here
update_workspace_commit(&vb_state, ctx, true)?;

let base = target_to_base_branch(ctx, &target)?;
Ok(base)
}

fn maybe_checkout_target(ctx: &CommandContext) -> Result<(), anyhow::Error> {
let repo = ctx.repo();
let vb_state = ctx.project().virtual_branches();
let target = vb_state.get_default_target()?;
let target_branch_ref = target.branch;
let current_head = repo.head()?;
let current_head_commit = current_head.peel_to_commit()?;

let head_name: Refname = current_head
.name()
.map(|name| name.parse().expect("libgit2 provides valid refnames"))
Expand Down Expand Up @@ -205,7 +227,7 @@ pub(crate) fn set_base_branch(
let (upstream, upstream_head, branch_matches_target) =
if let Refname::Local(head_name) = &head_name {
let upstream_name = target_branch_ref.with_branch(head_name.branch());
if upstream_name.eq(target_branch_ref) {
if upstream_name.eq(&target_branch_ref) {
(None, None, true)
} else {
match repo.find_reference(&Refname::from(&upstream_name).to_string()) {
Expand Down Expand Up @@ -253,14 +275,9 @@ pub(crate) fn set_base_branch(

vb_state.set_stack(branch)?;
}
}

set_exclude_decoration(ctx)?;

update_workspace_commit(&vb_state, ctx, true)?;
};

let base = target_to_base_branch(ctx, &target)?;
Ok(base)
Ok(())
}

pub(crate) fn set_target_push_remote(ctx: &CommandContext, push_remote_name: &str) -> Result<()> {
Expand Down
Loading