{"record":{"id":"69b8a7be52ee9158","repo":"gitbutlerapp/gitbutler","slug":"invalid-branch-name-err","errorCode":null,"errorMessage":"Invalid branch name: {err}","messagePattern":"Invalid branch name: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/branch/update.rs","lineNumber":164,"sourceCode":"                reference.name.shorten()\n            )\n        }\n        _ => bail!(\n            \"Expected a local branch, but '{}' is not under refs/heads/\",\n            reference.name.shorten()\n        ),\n    }\n}\n\nfn normalize_local_branch_ref(branch: &str) -> anyhow::Result<FullName> {\n    let full = if branch.starts_with(\"refs/heads/\") {\n        branch.to_owned()\n    } else if branch.starts_with(\"refs/\") {\n        bail!(\"Only local branches under refs/heads/ are supported\");\n    } else {\n        format!(\"refs/heads/{branch}\")\n    };\n    FullName::try_from(full).map_err(|err| anyhow::anyhow!(\"Invalid branch name: {err}\"))\n}\n\nfn output_apply_result(\n    branch_ref: &FullNameRef,\n    divergence: &but_workspace::branch::IntegrationDivergenceDisplay,\n    dry_run: bool,\n    verbose: bool,\n    result: IntegrateBranchResult,\n    out: &mut OutputChannel,\n) -> anyhow::Result<()> {\n    if let Some(out) = out.for_human() {\n        if dry_run {\n            write!(\n                out,\n                \"{}\",\n                format_dry_run(divergence, branch_ref, &result, verbose)\n            )?;\n        } else {","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/branch/update.rs#L146-L182","documentation":"Raised by `normalize_local_branch_ref` (crates/but/src/command/branch/update.rs:164) when the normalized branch name fails `FullName::try_from`. Only local branches under `refs/heads/` are supported; any other syntax produces an invalid full reference name and the underlying git validation error is interpolated into the message.","triggerScenarios":"Calling the branch update command with a name that normalizes to an invalid ref — containing spaces, `..`, `~`, `^`, `:`, control characters, or starting with `refs/` but pointing outside `refs/heads/` (which is rejected earlier).","commonSituations":"Typing a branch name with illegal characters in the CLI; passing `refs/remotes/origin/foo` or other non-heads refs; shell quoting issues injecting stray characters; overly long branch names.","solutions":["Check the branch name against `git check-ref-format --branch <name>` and fix invalid characters","Use the short branch name (e.g. `feature/foo`) rather than a full ref path","For remote branches, create a matching local branch first — only `refs/heads/` refs are supported","Quote the branch name in the shell to avoid stray characters being injected"],"exampleFix":"// before\nbut branch update \"feature..foo\"   // invalid ref name\n// after\nbut branch update \"feature-foo\"","handlingStrategy":"validation","validationCode":"// validate like git does before invoking the command\nlet out = std::process::Command::new(\"git\")\n    .args([\"check-ref-format\", \"--branch\", branch])\n    .status()?;\nif !out.success() { return Err(format!(\"invalid branch name: {branch}\")); }","typeGuard":"fn is_valid_local_branch_name(name: &str) -> bool {\n    !name.starts_with(\"refs/\") && gix::refs::FullName::try_from(format!(\"refs/heads/{name}\")).is_ok()\n}","tryCatchPattern":"match cmd_branch_update(branch) {\n    Err(e) if e.to_string().contains(\"Invalid branch name\") => eprintln!(\"use a valid branch name: git check-ref-format --branch\"),\n    other => other?,\n}","preventionTips":["Validate branch names with git check-ref-format before use","Pass short names, never refs/remotes/... paths","Quote branch names in shell scripts"],"tags":["git","cli","branch-name"],"backgroundTag":"invalid-identifier-format","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"}