gitbutlerapp/gitbutler · error

Cannot reconcile : branch name ' ' occurs more than once

Error message

Cannot reconcile {source}: branch name '{name}' occurs more than once

What it means

ensure_unique_branch_names validates, during reconciliation of projected stacks, that no branch name appears twice. Duplicates would make reconciliation ambiguous, so the operation bails naming the source. Called from reconcile_projected_stacks.

Solutions

  1. Deduplicate branch names across all projected stacks before calling reconcile
  2. When a branch appears in two stacks, remove it from one or use assignment APIs to move it explicitly
  3. Guard programmatic stack edits with a uniqueness check on refs::FullName

Example fix

// before
reconcile_projected_stacks(stacks)?;
// after
let seen = std::collections::HashSet::<_>::default();
for s in &stacks { assert!(seen.insert(s.branch_name.clone()), "duplicate branch {}", s.branch_name); }
reconcile_projected_stacks(stacks)?;
Defensive patterns

Strategy: validation

Validate before calling

let mut seen = std::collections::HashSet::new();
for name in all_projected_branch_names(&stacks) {
    if !seen.insert(name.as_bstr().to_owned()) {
        return Err(anyhow!("duplicate branch {name} in projected stacks"));
    }
}

Prevention

When it happens

Trigger: Reconciling projected stacks whose combined branch lists contain the same gix::refs::FullName more than once — e.g. the same branch assigned to two stacks or listed twice within one stack.

Common situations: Programmatic stack manipulation adding a branch that is already in another stack; UI bugs assigning one branch to multiple assignments; merging stack data from two sources without deduplication.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/d598ef8d87900f73. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-core/src/ref_metadata.rs:533

    config: &mut gix::config::File,
    key: &str,
    value: Option<impl AsRef<str>>,
) -> anyhow::Result<()> {
    match value {
        Some(value) => git_config::set_config_value(config, key, value.as_ref())?,
        None => git_config::remove_config_value(config, key)?,
    }
    Ok(())
}

fn ensure_unique_branch_names<'a>(
    names: impl IntoIterator<Item = &'a gix::refs::FullNameRef>,
    source: &str,
) -> Result<()> {
    let mut seen = Vec::<gix::refs::FullName>::new();
    for name in names {
        if seen.iter().any(|seen| seen == name) {
            bail!("Cannot reconcile {source}: branch name '{name}' occurs more than once");
        }
        seen.push(name.to_owned());
    }
    Ok(())
}

fn remove_branch_from_stacks(
    stacks: &mut [WorkspaceStack],
    preferred_stack_idx: usize,
    name: &gix::refs::FullNameRef,
) -> Option<WorkspaceStackBranch> {
    if let Some(stack) = stacks.get_mut(preferred_stack_idx)
        && let Some(branch_idx) = stack
            .branches
            .iter()
            .position(|branch| branch.ref_name == name)
    {
        return Some(stack.branches.remove(branch_idx));

View on GitHub (pinned to 58e5313667)