{"record":{"id":"45a10bf32453f17f","repo":"gitbutlerapp/gitbutler","slug":"cannot-cherry-pick-above-a-reference","errorCode":null,"errorMessage":"Cannot cherry-pick above a reference","messagePattern":"Cannot cherry-pick above a reference","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-workspace/src/commit/cherry_pick.rs","lineNumber":40,"sourceCode":"pub fn cherry_pick_commits<'ws, 'meta, M: RefMetadata>(\n    mut editor: Editor<'ws, 'meta, M>,\n    source_commits: impl IntoIterator<Item = gix::ObjectId>,\n    relative_to: RelativeTo,\n    side: InsertSide,\n) -> anyhow::Result<(SuccessfulRebase<'ws, 'meta, M>, Vec<Selector>)> {\n    let mut seen = HashSet::new();\n    let sources = source_commits\n        .into_iter()\n        .filter(|id| seen.insert(*id))\n        .collect::<Vec<_>>();\n    if sources.is_empty() {\n        bail!(\"No commits were provided to cherry-pick\")\n    }\n    if matches!(\n        (&relative_to, side),\n        (RelativeTo::Reference(_), InsertSide::Above)\n    ) {\n        bail!(\"Cannot cherry-pick above a reference\")\n    }\n\n    let target = relative_to.to_selector(&editor)?;\n\n    let mut inserted_selectors = Vec::with_capacity(sources.len());\n    let mut previous_selector = None;\n    for source in sources {\n        // Give the copy its own change ID, retaining all other metadata.\n        let mut template = editor.find_commit(source)?;\n        let mut headers = Headers::try_from_commit(&template.inner).unwrap_or_default();\n        headers.change_id = Headers::from_config(&editor.repo().config_snapshot()).change_id;\n        headers.set_in_commit(&mut template.inner);\n        let template_id = editor.new_commit(template, DateMode::CommitterUpdateAuthorKeep)?;\n\n        let (anchor, insert_side) = match previous_selector {\n            Some(selector) => (selector, InsertSide::Above),\n            None => (target, side),\n        };","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-workspace/src/commit/cherry_pick.rs#L22-L58","documentation":"Insertion 'above' a position is defined relative to a commit/selector, not a named reference. When `relative_to` is `RelativeTo::Reference(_)` and `side` is `InsertSide::Above`, the library cannot compute the target position and rejects the combination.","triggerScenarios":"Calling `cherry_pick_commits` with `relative_to = RelativeTo::Reference(ref_name)` and `side = InsertSide::Above`.","commonSituations":"UI code that lets users pick 'insert above' while targeting a branch reference instead of a specific commit; scripts copying parameters between API variants.","solutions":["Use `InsertSide::Below` with the reference, so commits land on top of it","Resolve the reference to its tip commit and pass `RelativeTo::Commit(selector)` when 'above' is intended","Pass a commit selector instead of a reference for above-insertion"],"exampleFix":"// before\ncherry_pick_commits(repo, meta, commits, &RelativeTo::Reference(ref_name), InsertSide::Above)?;\n// after\nlet tip = reference_tip_selector(repo, &ref_name)?;\ncherry_pick_commits(repo, meta, commits, &RelativeTo::Commit(tip), InsertSide::Above)?;","handlingStrategy":"validation","validationCode":"if matches!(relative_to, RelativeTo::Reference(_)) && side == InsertSide::Above {\n    anyhow::bail!(\"use a commit selector or InsertSide::Below when targeting a reference\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Constrain UI options so 'above' is only offered for commit targets","Document the reference+below-only contract of cherry_pick_commits in caller code"],"tags":["cherry-pick","invalid-argument","api-misuse"],"backgroundTag":"mutually-exclusive-options","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"}