{"record":{"id":"4c2850a4f6adb6bb","repo":"gitbutlerapp/gitbutler","slug":"cannot-unapply-non-existing-branch-branch","errorCode":null,"errorMessage":"Cannot unapply non-existing branch '{branch}'","messagePattern":"Cannot unapply non-existing branch '(.+?)'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/branch/unapply.rs","lineNumber":238,"sourceCode":"            );\n        }\n\n        if let Some(workspace_ref_name) = workspace_ref_name.as_ref()\n            && workspace_ref_name == branch\n        {\n            return unapply_workspace_reference(\n                ws,\n                repo,\n                meta,\n                workspace_ref_name.as_ref(),\n                workspace_disposition,\n            );\n        }\n\n        let branch_in_ws = ws.find_segment_and_stack_by_refname(branch);\n        if branch_in_ws.is_none() {\n            if branch_ref.is_none() {\n                bail!(\n                    \"Cannot unapply non-existing branch '{branch}'\",\n                    branch = branch.shorten()\n                );\n            }\n            // The branch exists in Git, but does not in the workspace: Nothing to do.\n            return Ok(Outcome::new(Cow::Borrowed(workspace)));\n        }\n        let Some(workspace_ref_name) = workspace_ref_name else {\n            // This is an ad-hoc workspace by merit of being unnamed.\n            bail!(\"Cannot unapply a branch from an ad-hoc detached workspace\");\n        };\n        let mut ws_md = meta.workspace(workspace_ref_name.as_ref())?;\n        if ws.kind.has_managed_ref() || ws.has_metadata() {\n            ws.reconcile_metadata(&mut ws_md)?;\n        }\n        let branch_removed_from_ws_meta = ws_md.unapply_branch(branch);\n        if !branch_removed_from_ws_meta {\n            // The branch wasn't in workspace metadata, yet it was present, so also delete its branch metadata","sourceCodeStart":220,"sourceCodeEnd":256,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/unapply.rs#L220-L256","documentation":"Raised by unapply when the requested branch is neither the workspace reference nor found as a segment/stack in the workspace, and no branch ref exists for it either. It means there is nothing to unapply — the branch name likely was mistyped or the branch was already removed. Verify with but status that the branch is part of the workspace.","triggerScenarios":"Calling `unapply` with a `branch` refname that was already deleted (or never existed) and is not found by `ws.find_segment_and_stack_by_refname`, with `branch_ref.is_none()` (no git ref exists).","commonSituations":"Stale UI state pointing at a branch deleted in another window; typos in ref names in scripts; racing with a concurrent unapply/apply that already removed the branch.","solutions":["Verify the branch exists (`git rev-parse --verify <ref>`) before calling unapply","Refresh workspace state and retry; if the branch is gone the unapply already happened","Treat branch-not-found as a no-op in your caller if idempotency is desired"],"exampleFix":"// before\nunapply(repo, meta, &ws, branch, ...)?;\n// after\nif repo.try_find_reference(&branch)?.is_some() {\n    unapply(repo, meta, &ws, branch, ...)?;\n}","handlingStrategy":"validation","validationCode":"fn branch_exists(repo: &gix::Repository, branch: &gix::refs::FullNameRef) -> bool {\n    repo.try_find_reference(branch).map_or(false, |r| r.is_some())\n}","typeGuard":null,"tryCatchPattern":"match err {\n    e if e.to_string().contains(\"non-existing branch\") => return Ok(Outcome::noop()), // already gone\n    e => return Err(e),\n}","preventionTips":["Refresh workspace/branch state before operating on user-selected branches","Make unapply flows idempotent by checking ref existence first"],"tags":["git","branch","not-found"],"backgroundTag":"resource-not-found","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"}