Skip to main content

validate_ref_name

Function validate_ref_name 

Source
pub fn validate_ref_name(name: &str) -> bool
Expand description

Validate a ref name per SPEC-REFS §3. Used at every transport boundary; transports MUST NOT silently lower-case or canonicalise.

Grammar:

  • Non-empty.
  • Segments split on /, each segment matches [A-Za-z0-9._-]+.
  • No segment may start with . (this also rejects the exact . and .. segments) — git’s check-ref-format rule, kept for parity: a dot-leading component is invalid in both grammars, so nothing on-disk under a dot-leading directory (e.g. crash debris from a temp-directory rename, or an in-flight atomic::write_atomic temp file) can ever surface as a ref in collect_refs / listings. No empty segments (no //, no leading /, no trailing /).
  • No \\ or NUL bytes.
  • No segment may end in .lock (the canonical lock-file suffix).
  • The final segment may not be the literal HEAD, since that would shadow the repo-level HEAD pointer.