{"record":{"id":"a393eb7f0c1a285f","repo":"gitbutlerapp/gitbutler","slug":"couldn-t-find-target-branch-to-move-in-workspace-w","errorCode":null,"errorMessage":"Couldn't find target branch to move in workspace with reference name: {target_branch_name}","messagePattern":"Couldn't find target branch to move in workspace with reference name: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/branch/move_branch.rs","lineNumber":505,"sourceCode":"    ///\n    /// ### What the future holds\n    /// In the future, where we're not afraid of complex graphs, we've figured out UX and data wrangling,\n    /// the concept of a segment might not hold, and hence we'll have to figure out a better way of determining\n    /// what to cut (e.g. letting the clients decide what to cut).\n    fn retrieve_branches_and_containers(\n        workspace: &but_graph::Workspace,\n        subject_branch_name: &FullNameRef,\n        target_branch_name: &FullNameRef,\n    ) -> anyhow::Result<(WorkspaceSegmentContext, WorkspaceSegmentContext)> {\n        let Some(source) = workspace.find_segment_and_stack_by_refname(subject_branch_name) else {\n            bail!(\n                \"Couldn't find branch to move in workspace with reference name: {subject_branch_name}\"\n            );\n        };\n\n        let Some(destination) = workspace.find_segment_and_stack_by_refname(target_branch_name)\n        else {\n            bail!(\n                \"Couldn't find target branch to move in workspace with reference name: {target_branch_name}\"\n            );\n        };\n        Ok((own_context(source), own_context(destination)))\n    }\n\n    /// Reorder `subject` to sit directly on top of `target` in the tip-to-base ad-hoc `order`.\n    ///\n    /// Mirrors the [`Position::Above`](crate::branch::create_reference::Position) case of\n    /// `create_reference`'s `insert_into_branch_stack_order`: `subject` is removed and re-inserted\n    /// at `target`'s slot, pushing `target` (and everything below it) down.\n    ///\n    /// If `target` isn't tracked yet (stale or empty metadata) it is appended first, so that a move\n    /// where *both* branches are missing adds them both - `subject` on top of `target` - instead of\n    /// silently clobbering the rest of the ordering down to just `subject`.\n    fn reorder_branch_in_stack_order(\n        mut order: Vec<gix::refs::FullName>,\n        target_branch_name: &FullNameRef,","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/move_branch.rs#L487-L523","documentation":"The counterpart to the subject lookup: move_branch() resolves the target branch's segment/stack in the workspace graph. When find_segment_and_stack_by_refname finds no segment for target_branch_name, the destination is unknown and the function bails.","triggerScenarios":"Calling move_branch() with a target_branch_name that has no segment in the workspace graph - the target ref does not exist in the workspace, was deleted, or was passed unqualified.","commonSituations":"Passing a base/upstream ref or a branch outside the workspace as the move target; target branch renamed or deleted concurrently; UI passing a stale ref name after a refresh.","solutions":["Verify the target branch exists within the workspace and use its fully-qualified ref name","Re-read the workspace graph/stack listing to get valid target ref names","Handle the case where the intended destination is outside the workspace - use a different operation"],"exampleFix":"// before\nmove_branch(editor, subject, \"target\")\n// after\nlet target = \"refs/heads/target\"; // must exist in the workspace graph\nmove_branch(editor, subject, target)","handlingStrategy":"validation","validationCode":"let target_ok = workspace.find_segment_and_stack_by_refname(target_branch_name).is_some();\nif !target_ok { /* target not in workspace: abort or choose another target */ }","typeGuard":null,"tryCatchPattern":"match move_branch(editor, subject, target) {\n    Err(e) if e.to_string().contains(\"Couldn't find target branch\") => refresh_and_pick_target_from_graph(),\n    other => other?,\n}","preventionTips":["Derive move targets from the live workspace graph, not cached UI state","Use fully-qualified refs for targets","Re-validate targets after any concurrent workspace change"],"tags":["git","workspace","not-found"],"backgroundTag":"entity-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"}