{"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":1218,"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 its stack ancestors, so those are checked\n/// too. Returns an error if conflicted commits are found.\nfn check_for_conflicted_commits(ctx: &Context, branch_name: &str) -> anyhow::Result<()> {\n    let stacks = crate::legacy::workspace::applied_stacks_with_expensive_commit_info(ctx)?;\n\n    let repo = ctx.repo.get()?.clone().for_commit_shortening();\n    // Find the stack containing this branch.\n    for stack in &stacks {","sourceCodeStart":1200,"sourceCodeEnd":1236,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/caf1f223d3cfb94488c9198ad34487c6006c648f/crates/but/src/command/legacy/push.rs#L1200-L1236","documentation":"In gerrit mode, `gerrit_review_ref` builds the review ref `refs/for/<short-name>` from the workspace target: `ResolvedTarget::resolve_with_perm(...)?.ref_name()` returning `None` triggers this error before any push happens. Without a target ref there is no branch to construct refs/for against.","triggerScenarios":"Running a gerrit push (`gitbutler.gerritMode` enabled) in a workspace whose target branch is unset or unresolvable — target never configured, or target ref missing after a partial clone or restore.","commonSituations":"Gerrit mode enabled before target setup; workspace metadata restored without the target; fresh clone where onboarding was skipped.","solutions":["Set the workspace target branch: `but config target <branch>` (e.g. `but config target origin/main`)","Ensure the target ref exists on a configured remote (`git remote -v`, then `git fetch`)","Re-run the gerrit push"],"exampleFix":"# before\nbut push --wip\n# error: Failed to determine Gerrit target branch\n\n# after\nbut config target origin/main\nbut push --wip","handlingStrategy":"validation","validationCode":"# Gerrit push preflight\n[ \"$(git config --bool gitbutler.gerritMode)\" = \"true\" ] || { echo 'gerrit mode off' >&2; exit 1; }\nbut config target   # must report a target branch before refs/for can be built","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Configure the target branch before enabling gerrit mode workflows","Re-verify workspace config after cloning or restoring a Gerrit repo","Treat this error as a setup gap, not a Gerrit-side failure"],"tags":["gerrit","push","target-branch","workspace"],"backgroundTag":"target-branch-not-configured","analyzedSha":"caf1f223d3cfb94488c9198ad34487c6006c648f","analyzedAt":"2026-08-20T07:55:40.983Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}