gitbutlerapp/gitbutler · error
Invalid branch_ref_bytes in assignment request for
Error message
Invalid branch_ref_bytes in assignment request for '{}': {err} What it means
requests_to_assignments converts user-submitted HunkAssignmentRequest entries into resolvable assignments; when a request targets a Branch, its branch_ref_bytes must parse as a gix::refs::FullName. Malformed ref bytes in the request produce this error naming the file path involved.
Solutions
- Send branch_ref_bytes as a full ref name like refs/heads/my-branch
- Use gix::refs::FullName::try_from on the client side to validate before submitting
- Update the calling client/SDK to the current assignment API format
Example fix
// before
HunkAssignmentTarget::Branch { branch_ref_bytes: BString::from("my-branch") }
// after
HunkAssignmentTarget::Branch { branch_ref_bytes: BString::from("refs/heads/my-branch") } Defensive patterns
Strategy: validation
Validate before calling
if let HunkAssignmentTarget::Branch { branch_ref_bytes } = &req.target {
if gix::refs::FullName::try_from(branch_ref_bytes.clone()).is_err() {
eprintln!("Invalid ref for {} — use refs/heads/<name>", req.path_bytes.to_str_lossy());
continue;
}
} Type guard
fn valid_branch_target(t: &HunkAssignmentTarget) -> bool {
match t {
HunkAssignmentTarget::Branch { branch_ref_bytes } =>
gix::refs::FullName::try_from(branch_ref_bytes.clone()).is_ok(),
_ => true,
}
} Prevention
- Construct branch targets via gix::refs::FullName, not raw bytes
- Validate all request targets before calling assign
- Keep client SDK versions in sync with the assignment API format
When it happens
Trigger: Calling assign (crates/but-hunk-assignment/src/lib.rs:619) with a HunkAssignmentTarget::Branch whose branch_ref_bytes is not a valid ref name — clients sending raw bytes that lack the refs/... form.
Common situations: SDK/UI clients constructing targets by hand; stale clients from before the bytes-based API; copy-pasted branch names without the refs/heads/ prefix.
Understand the failure class
Background: "invalid id" errors: invalid identifier format — why libraries reject IDs before lookup, and how to fix them — this error's family across 37 libraries.
Related errors
- Can only delete local branches under refs/heads, got
- Expected ' ' to be a remote tracking branch, but was
- target ref ' ' must be a remote tracking branch
- Aborting due to empty branch name
- Branch name ' ' collides with existing branch
AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18).
Data as JSON: /api/errors/b5d9306f1b634e3d.
Report an issue: GitHub.
Appendix: source
Thrown at crates/but-hunk-assignment/src/lib.rs:619
}
}
fn requests_to_assignments(
request: Vec<HunkAssignmentRequest>,
workspace: &but_graph::Workspace,
) -> Result<Vec<HunkAssignment>> {
let mut assignments = vec![];
for req in request {
let HunkAssignmentRequest {
hunk_header,
path_bytes,
target,
} = req;
let branch_ref_bytes = match target {
None => None,
Some(HunkAssignmentTarget::Branch { branch_ref_bytes }) => Some(
gix::refs::FullName::try_from(branch_ref_bytes).map_err(|err| {
anyhow::anyhow!(
"Invalid branch_ref_bytes in assignment request for '{}': {err}",
path_bytes.to_str_lossy()
)
})?,
),
Some(HunkAssignmentTarget::Stack { stack_id }) => Some(
workspace
.find_stack_by_id(stack_id)
.and_then(|stack| stack.ref_name())
.map(|ref_name| ref_name.to_owned())
.ok_or_else(|| {
anyhow::anyhow!(
"Unknown stack_id {stack_id} in assignment request for '{}'",
path_bytes.to_str_lossy()
)
})?,
),
};View on GitHub (pinned to 58e5313667)