{"record":{"id":"e505aed21ef4b205","repo":"gitbutlerapp/gitbutler","slug":"could-not-turn-name-into-a-valid-reference-nam","errorCode":null,"errorMessage":"Could not turn {name:?} into a valid reference name","messagePattern":"Could not turn (.+?) into a valid reference name","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but-core/src/branch/normalize.rs","lineNumber":41,"sourceCode":"            break;\n        }\n    }\n\n    let mut previous_is_hyphen = false;\n    sanitized.retain(|b| {\n        if *b == b'-' {\n            if previous_is_hyphen {\n                return false;\n            }\n            previous_is_hyphen = true;\n        } else {\n            previous_is_hyphen = false;\n        }\n        true\n    });\n\n    if sanitized.is_empty() || sanitized == \"HEAD\" {\n        bail!(\"Could not turn {name:?} into a valid reference name\")\n    }\n\n    Ok(sanitized)\n}\n","sourceCodeStart":23,"sourceCodeEnd":46,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but-core/src/branch/normalize.rs#L23-L46","documentation":"normalize_short_name() sanitizes a candidate branch name into a valid git reference short name. If, after stripping invalid characters, the result is empty or equals \"HEAD\" (which is reserved and cannot be a branch), the function bails because no valid ref name can be produced.","triggerScenarios":"Calling generate_short_name_from_signature (or normalize_short_name directly) with input consisting only of characters removed by sanitization (e.g. all slashes/spaces), or with the literal string \"HEAD\".","commonSituations":"Auto-generating branch names from commit messages or user signatures that are mostly emoji/punctuation; a template that yields \"HEAD\"; localized input reduced to nothing after sanitization.","solutions":["Provide a longer, alphanumeric input name so sanitization leaves a non-empty result","Check the sanitized result client-side and substitute a fallback name (e.g. a timestamp or hash-based name)","Avoid generating names from purely symbolic/emoji content","Explicitly reject \"HEAD\" as a user-entered branch name before calling"],"exampleFix":"// before\nlet name = normalize_short_name(\"///\")?;\n// after\nlet name = match normalize_short_name(user_input) {\n    Ok(n) => n,\n    Err(_) => normalize_short_name(&format!(\"branch-{}\", timestamp()))?,\n};","handlingStrategy":"validation","validationCode":"fn usable_name(name: &str) -> bool {\n    let s: String = name.chars().filter(|c| c.is_alphanumeric() || *c == '-').collect();\n    !s.is_empty() && s != \"HEAD\"\n}","typeGuard":null,"tryCatchPattern":"match normalize_short_name(name) {\n    Ok(n) => n,\n    Err(_) => fallback_name(),\n}","preventionTips":["Generate branch names from alphanumeric sources","Always include a deterministic fallback (hash/timestamp) in generated names","Reject \"HEAD\" and empty names in user input validation","Preview the sanitized name before creating the branch"],"tags":["git","branches","naming"],"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"}