{"record":{"id":"d598ef8d87900f73","repo":"gitbutlerapp/gitbutler","slug":"cannot-reconcile-source-branch-name-name-oc","errorCode":null,"errorMessage":"Cannot reconcile {source}: branch name '{name}' occurs more than once","messagePattern":"Cannot reconcile (.+?): branch name '(.+?)' occurs more than once","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-core/src/ref_metadata.rs","lineNumber":533,"sourceCode":"    config: &mut gix::config::File,\n    key: &str,\n    value: Option<impl AsRef<str>>,\n) -> anyhow::Result<()> {\n    match value {\n        Some(value) => git_config::set_config_value(config, key, value.as_ref())?,\n        None => git_config::remove_config_value(config, key)?,\n    }\n    Ok(())\n}\n\nfn ensure_unique_branch_names<'a>(\n    names: impl IntoIterator<Item = &'a gix::refs::FullNameRef>,\n    source: &str,\n) -> Result<()> {\n    let mut seen = Vec::<gix::refs::FullName>::new();\n    for name in names {\n        if seen.iter().any(|seen| seen == name) {\n            bail!(\"Cannot reconcile {source}: branch name '{name}' occurs more than once\");\n        }\n        seen.push(name.to_owned());\n    }\n    Ok(())\n}\n\nfn remove_branch_from_stacks(\n    stacks: &mut [WorkspaceStack],\n    preferred_stack_idx: usize,\n    name: &gix::refs::FullNameRef,\n) -> Option<WorkspaceStackBranch> {\n    if let Some(stack) = stacks.get_mut(preferred_stack_idx)\n        && let Some(branch_idx) = stack\n            .branches\n            .iter()\n            .position(|branch| branch.ref_name == name)\n    {\n        return Some(stack.branches.remove(branch_idx));","sourceCodeStart":515,"sourceCodeEnd":551,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-core/src/ref_metadata.rs#L515-L551","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Deduplicate branch names across all projected stacks before calling reconcile","When a branch appears in two stacks, remove it from one or use assignment APIs to move it explicitly","Guard programmatic stack edits with a uniqueness check on refs::FullName"],"exampleFix":"// before\nreconcile_projected_stacks(stacks)?;\n// after\nlet seen = std::collections::HashSet::<_>::default();\nfor s in &stacks { assert!(seen.insert(s.branch_name.clone()), \"duplicate branch {}\", s.branch_name); }\nreconcile_projected_stacks(stacks)?;","handlingStrategy":"validation","validationCode":"let mut seen = std::collections::HashSet::new();\nfor name in all_projected_branch_names(&stacks) {\n    if !seen.insert(name.as_bstr().to_owned()) {\n        return Err(anyhow!(\"duplicate branch {name} in projected stacks\"));\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Deduplicate branches across stacks before reconciliation","Move (not copy) branches between stacks via assignment APIs","Add uniqueness assertions in code that mutates stack membership"],"tags":["rust","git","validation","duplicate"],"backgroundTag":"schema-validation-failed","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}