gitdataai/libs/git/ref_utils.rs
ZhenYi 64dc27161b chore(git): minor fixes and improvements across git library modules
Apply small fixes across multiple git ops files: handle errors, improve
type safety, and refine HTTP handler and SSH git operations.
2026-04-27 08:28:09 +08:00

37 lines
976 B
Rust

//! Shared utility functions for reference name validation.
use crate::GitError;
/// # Rules
/// - Must not be empty
/// - Must not start with '.'
/// - Must not end with '/'
/// - Must not contain '..'
/// - Must not contain spaces, '~', '^', ':', '?', '*', '[', or '\'
///
/// # Returns
/// - `Ok(())` if name is valid
/// - `Err(GitError::InvalidRefName)` if name is invalid
pub fn validate_ref_name(name: &str) -> Result<(), GitError> {
if name.is_empty()
|| name.starts_with('.')
|| name.ends_with('/')
|| name.contains("..")
|| name.contains(' ')
|| name.contains('~')
|| name.contains('^')
|| name.contains(':')
|| name.contains('?')
|| name.contains('*')
|| name.contains('[')
|| name.contains('\\')
|| name.contains('@')
{
return Err(GitError::InvalidRefName(format!(
"invalid ref name: {}",
name
)));
}
Ok(())
}