gitbutlerapp/gitbutler · error
Unexpectedly failed to apply
Error message
Unexpectedly failed to apply {branches} which is/are still not in the workspace What it means
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.
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
Defensive patterns
Strategy: retry
Try / catch
for attempt in 0..2 {
match apply(...) {
Ok(_) => break,
Err(e) if attempt == 0 && e.to_string().contains("still not in the workspace") => continue,
Err(e) => return Err(e.into()),
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: Merge conflicts or graph inconsistencies that dropped a branch during re-application; applying branches that share commits; bugs in the multi-branch adhoc path.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Ad-hoc (single-branch) branch moves are not supported…
- Branch ' ' cannot be created: the target commit ( ) already…
- BranchNotFound
- BUG: failed to apply head ref
- Cannot add the target
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/55601c96d37f4e21.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-workspace/src/branch/apply.rs:754
}
new_head_id = merge_result.workspace_commit_id;
conflicting_stacks = correlate_conflicting_stacks(&ws_md, &merge_result.conflicting_stacks);
remove_conflicting_stacks_from_workspace(&mut ws_md, &conflicting_stacks);
let ws_md_override = Some((workspace_ref_name_to_update.clone(), (*ws_md).clone()));
ws = ws
.graph
.redo_traversal_with_overlay(
&in_memory_repo,
meta,
overlay
.with_entrypoint(new_head_id, Some(workspace_ref_name_to_update.clone()))
.with_workspace_metadata_override(ws_md_override),
)?
.into_workspace()?;
let unapplied_branches = collect_unapplied_branches(&ws);
if !unapplied_branches.is_empty() {
bail!(
"Unexpectedly failed to apply {branches} which is/are still not in the workspace",
branches = unapplied_branches
.iter()
.map(|rn| rn.shorten().to_string())
.collect::<Vec<_>>()
.join(", ")
)
}
}
// All work is done, persist and exit.
// Note that it could be that some stacks aren't merged in,
// while being present in the workspace metadata.
// This is OK for us. We also trust that the hero-branch was merged in, no matter what.
if let Some(storage) = in_memory_repo.objects.take_object_memory() {
storage.persist(repo)?;
drop(in_memory_repo);
}View on GitHub (pinned to 58e5313667)