{"record":{"id":"cb2604d6e38da547","repo":"gitbutlerapp/gitbutler","slug":"cannot-move-branch-subject-branch-name-onto-itse","errorCode":null,"errorMessage":"Cannot move branch {subject_branch_name} onto itself","messagePattern":"Cannot move branch (.+?) onto itself","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/but-workspace/src/branch/move_branch.rs","lineNumber":186,"sourceCode":"    /// `editor` is assumed to have been generated from the given `workspace`\n    /// and therefore aligned.\n    ///\n    /// `workspace` - Used for getting the surrounding context of the branch being moved.\n    ///     In the future, we should not rely on the projection and do it fully on the graph.\n    ///\n    /// `subject_branch_name` is the full reference name of the branch to move.\n    ///\n    /// `target_branch_name` is the full reference name of the branch to move the subject\n    /// branch on top of.\n    ///\n    /// Returns an [outcome](Outcome) for potential materialisation.\n    pub fn move_branch<'ws, 'meta, M: RefMetadata>(\n        editor: Editor<'ws, 'meta, M>,\n        subject_branch_name: &FullNameRef,\n        target_branch_name: &FullNameRef,\n    ) -> anyhow::Result<Outcome<'ws, 'meta, M>> {\n        if subject_branch_name == target_branch_name {\n            bail!(\"Cannot move branch {subject_branch_name} onto itself\");\n        }\n\n        let successful_rebase = editor.rebase()?;\n        let workspace = successful_rebase.overlayed_graph()?.into_workspace()?;\n\n        let (source, destination) =\n            retrieve_branches_and_containers(&workspace, subject_branch_name, target_branch_name)?;\n\n        // Each kind of workspace has a very different notion of what \"moving a branch\" means, so we\n        // dispatch into a dedicated handler for each one.\n        match &workspace.kind {\n            WorkspaceKind::AdHoc => move_branch_in_single_branch_mode(\n                successful_rebase,\n                workspace,\n                source,\n                destination,\n                subject_branch_name,\n                target_branch_name,","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/branch/move_branch.rs#L168-L204","documentation":"move_branch() refuses to move a branch onto itself: subject_branch_name and target_branch_name are equal, which is a no-op with ambiguous semantics (source and destination would be the same segment). The check happens before any rebase or graph work.","triggerScenarios":"Calling move_branch(editor, \"gitbutler/workspace/foo\", \"gitbutler/workspace/foo\") - the same fully-qualified ref passed as both subject and target.","commonSituations":"UI/CLI bugs where the user drags a branch onto itself; building target branch name from user input without dedup check; automated scripts iterating over stacks and accidentally pairing a ref with itself.","solutions":["Compare subject and target branch names before calling move_branch and skip identical pairs","Use fully-qualified ref names for the comparison to avoid false equality/inequality","Return a no-op success instead of an error when names match, in the caller"],"exampleFix":"// before\nmove_branch(editor, name, target)\n// after\nif name != target {\n    move_branch(editor, name, target)\n}","handlingStrategy":"validation","validationCode":"if subject_branch_name == target_branch_name {\n    return Ok(()); // no-op\n}","typeGuard":null,"tryCatchPattern":"match move_branch(editor, subject, target) {\n    Err(e) if e.to_string().contains(\"onto itself\") => return Ok(()),\n    other => other?,\n}","preventionTips":["Compare fully-qualified ref names before invoking move_branch","Skip self-moves in UI drag-and-drop handlers","Deduplicate (subject, target) pairs in automated scripts"],"tags":["git","workspace","invalid-argument"],"backgroundTag":"invalid-argument-value","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"}