{"record":{"id":"b1bff1b5c2693bd4","repo":"gitbutlerapp/gitbutler","slug":"failed-to-determine-gerrit-target-branch","errorCode":null,"errorMessage":"Failed to determine Gerrit target branch","messagePattern":"Failed to determine Gerrit target branch","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/legacy/push.rs","lineNumber":1215,"sourceCode":"        writeln!(\n            out,\n            \"{} Push succeeded, but review synchronization failed: {}\",\n            t.sym().warning,\n            t.hint.paint(message)\n        )?;\n    }\n    Ok(())\n}\n\nfn gerrit_review_ref(\n    ctx: &Context,\n    perm: &RepoShared,\n    repo: &gix::Repository,\n) -> anyhow::Result<String> {\n    let target_ref_name = workspace_target::ResolvedTarget::resolve_with_perm(ctx, perm)?\n        .ref_name()\n        .map(ToOwned::to_owned)\n        .ok_or_else(|| anyhow::anyhow!(\"Failed to determine Gerrit target branch\"))?;\n    let remote_names = repo.remote_names();\n    let target_branch =\n        but_core::extract_remote_name_and_short_name(target_ref_name.as_ref(), &remote_names)\n            .map(|(_, short_name)| short_name.to_string())\n            .unwrap_or_else(|| target_ref_name.shorten().to_string());\n\n    Ok(format!(\"refs/for/{target_branch}\"))\n}\n\n/// Check if a push of this branch would include any conflicted commits.\n/// The push covers the branch and everything beneath it, named by a branch\n/// or not, so all of that is checked. Returns an error if conflicted commits\n/// are found.\nfn check_for_conflicted_commits(ctx: &Context, branch_name: &str) -> anyhow::Result<()> {\n    let branch = gix::refs::Category::LocalBranch.to_full_name(branch_name)?;\n    let Some(commits) =\n        crate::legacy::workspace::push_scope_with_expensive_commit_info(ctx, branch.as_ref())?\n    else {","sourceCodeStart":1197,"sourceCodeEnd":1233,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/legacy/push.rs#L1197-L1233","documentation":"This error is thrown by the `gerrit_review_ref` helper in GitButler's legacy push command when the resolved workspace target has no associated ref name. `ResolvedTarget::resolve_with_perm` resolves the destination for the push (typically the base/target branch the stack builds on), and if `ref_name()` returns None there is no way to derive the Gerrit target branch, so the push for Gerrit review cannot proceed.","triggerScenarios":"Running `but push` (via push_single_branch or push_all_branches) in a workspace configured for Gerrit review where the workspace target resolves to a target without a ref name — e.g. an unborn/unset target branch, a target pointing at a symbolic/detached state, or a workspace whose target metadata was not fully initialized.","commonSituations":"Cloned repository where the upstream tracking/target branch was never set; user deleted or renamed the target branch; workspace metadata from an older GitButler version lacking complete target info; pushing before assigning the branch to a target branch.","solutions":["Verify the workspace target branch is set and exists on the remote (e.g. `but branch list` / check .git/gitbutler workspace target metadata)","Re-assign the branch to a valid target branch (e.g. `but branch --assign <target>` or re-initialize the workspace on the intended base branch)","Fetch the remote so the target ref exists locally, then retry the push","If the repo is not intended for Gerrit, disable Gerrit push mode (e.g. remove push.gerrit review config / use normal push)"],"exampleFix":"// before (conceptual CLI misuse)\nbut push --gerrit   # workspace has no resolved target ref\n// after\nbut branch --assign origin/main\nbut push --gerrit","handlingStrategy":"validation","validationCode":"// shell: ensure a target ref resolves before pushing\nbut branch list 2>/dev/null | grep -q . || { echo 'No workspace/target configured'; exit 1; }\ngit rev-parse --verify --quiet refs/remotes/origin/HEAD || { echo 'No remote target branch'; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always assign branches to a target branch before pushing","Keep the remote tracking/target branch fetched locally","Avoid renaming/deleting the workspace target branch","Check Gerrit push config only in repos that actually use Gerrit"],"tags":["gerrit","git-push","target-branch","cli"],"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"}