{"record":{"id":"55601c96d37f4e21","repo":"gitbutlerapp/gitbutler","slug":"unexpectedly-failed-to-apply-branches-which-is-a","errorCode":null,"errorMessage":"Unexpectedly failed to apply {branches} which is/are still not in the workspace","messagePattern":"Unexpectedly failed to apply (.+?) which is/are still not in the workspace","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/branch/apply.rs","lineNumber":754,"sourceCode":"        }\n        new_head_id = merge_result.workspace_commit_id;\n        conflicting_stacks = correlate_conflicting_stacks(&ws_md, &merge_result.conflicting_stacks);\n        remove_conflicting_stacks_from_workspace(&mut ws_md, &conflicting_stacks);\n        let ws_md_override = Some((workspace_ref_name_to_update.clone(), (*ws_md).clone()));\n        ws = ws\n            .graph\n            .redo_traversal_with_overlay(\n                &in_memory_repo,\n                meta,\n                overlay\n                    .with_entrypoint(new_head_id, Some(workspace_ref_name_to_update.clone()))\n                    .with_workspace_metadata_override(ws_md_override),\n            )?\n            .into_workspace()?;\n        let unapplied_branches = collect_unapplied_branches(&ws);\n\n        if !unapplied_branches.is_empty() {\n            bail!(\n                \"Unexpectedly failed to apply {branches} which is/are still not in the workspace\",\n                branches = unapplied_branches\n                    .iter()\n                    .map(|rn| rn.shorten().to_string())\n                    .collect::<Vec<_>>()\n                    .join(\", \")\n            )\n        }\n    }\n\n    // All work is done, persist and exit.\n    // Note that it could be that some stacks aren't merged in,\n    // while being present in the workspace metadata.\n    // This is OK for us. We also trust that the hero-branch was merged in, no matter what.\n    if let Some(storage) = in_memory_repo.objects.take_object_memory() {\n        storage.persist(repo)?;\n        drop(in_memory_repo);\n    }","sourceCodeStart":736,"sourceCodeEnd":772,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/apply.rs#L736-L772","documentation":"After applying, the code rebuilds the workspace and collects branches that are still unapplied. If any of the requested branches are still missing from the resulting workspace, apply failed silently somewhere and this bail reports exactly which branches did not land.","triggerScenarios":"Calling apply with multiple branches (adhoc workspace case) where one or more branches failed to be incorporated during merge/workspace rebuild — detected by post-apply verification.","commonSituations":"Merge conflicts or graph inconsistencies that dropped a branch during re-application; applying branches that share commits; bugs in the multi-branch adhoc path.","solutions":["Re-run the apply operation for the listed branches individually","Check the listed branch names for conflicts or invalid states (e.g. ref already moved)","Inspect workspace state after apply and manually integrate any leftover branches"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for attempt in 0..2 {\n    match apply(...) {\n        Ok(_) => break,\n        Err(e) if attempt == 0 && e.to_string().contains(\"still not in the workspace\") => continue,\n        Err(e) => return Err(e.into()),\n    }\n}","preventionTips":["Apply branches one at a time when possible to simplify failure modes","Inspect workspace state after multi-branch applies","Resolve merge conflicts before applying additional branches"],"tags":["git","workspace","post-condition"],"backgroundTag":"internal-invariant-violation","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"}