gitbutlerapp/gitbutler · error

Could not turn into a valid reference name

Error message

Could not turn {name:?} into a valid reference name

What it means

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.

Solutions

  1. Provide a longer, alphanumeric input name so sanitization leaves a non-empty result
  2. Check the sanitized result client-side and substitute a fallback name (e.g. a timestamp or hash-based name)
  3. Avoid generating names from purely symbolic/emoji content
  4. Explicitly reject "HEAD" as a user-entered branch name before calling

Example fix

// before
let name = normalize_short_name("///")?;
// after
let name = match normalize_short_name(user_input) {
    Ok(n) => n,
    Err(_) => normalize_short_name(&format!("branch-{}", timestamp()))?,
};
Defensive patterns

Strategy: validation

Validate before calling

fn usable_name(name: &str) -> bool {
    let s: String = name.chars().filter(|c| c.is_alphanumeric() || *c == '-').collect();
    !s.is_empty() && s != "HEAD"
}

Try / catch

match normalize_short_name(name) {
    Ok(n) => n,
    Err(_) => fallback_name(),
}

Prevention

When it happens

Trigger: 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".

Common situations: 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.

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


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/e505aed21ef4b205. Report an issue: GitHub.

Appendix: source

Thrown at crates/but-core/src/branch/normalize.rs:41

            break;
        }
    }

    let mut previous_is_hyphen = false;
    sanitized.retain(|b| {
        if *b == b'-' {
            if previous_is_hyphen {
                return false;
            }
            previous_is_hyphen = true;
        } else {
            previous_is_hyphen = false;
        }
        true
    });

    if sanitized.is_empty() || sanitized == "HEAD" {
        bail!("Could not turn {name:?} into a valid reference name")
    }

    Ok(sanitized)
}

View on GitHub (pinned to 58e5313667)