Skip to main content

validate_git_ref

Function validate_git_ref 

Source
pub fn validate_git_ref(s: &str) -> Result<&str, String>
Expand description

Validate a user-supplied git ref before passing it to git diff.

Rejects empty strings, refs starting with - (which git would interpret as an option flag), and characters outside the safe allowlist for branch names, tags, SHAs, and reflog expressions (HEAD~N, HEAD@{...}).

Inside @{...} braces, colons and spaces are allowed so reflog timestamps like HEAD@{2025-01-01} and HEAD@{1 week ago} round-trip.

Used by both the CLI (clap value parser) and the LSP (initializationOptions trust boundary) to fail fast with a readable error rather than handing a malformed ref to git.