MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / validate_remote_name

Function validate_remote_name

atomic-repository/src/remote.rs:655–690  ·  view source on GitHub ↗

Validate a remote name. Remote names must: - Not be empty - Contain only alphanumeric characters, hyphens, and underscores - Not start with a hyphen - Not be a reserved name (like "." or "..")

(name: &str)

Source from the content-addressed store, hash-verified

653/// - Not start with a hyphen
654/// - Not be a reserved name (like "." or "..")
655fn validate_remote_name(name: &str) -> RemoteResult<()> {
656 if name.is_empty() {
657 return Err(RemoteError::InvalidName {
658 name: name.to_string(),
659 reason: "name cannot be empty".to_string(),
660 });
661 }
662
663 if name == "." || name == ".." {
664 return Err(RemoteError::InvalidName {
665 name: name.to_string(),
666 reason: "name cannot be '.' or '..'".to_string(),
667 });
668 }
669
670 if name.starts_with('-') {
671 return Err(RemoteError::InvalidName {
672 name: name.to_string(),
673 reason: "name cannot start with a hyphen".to_string(),
674 });
675 }
676
677 for ch in name.chars() {
678 if !ch.is_ascii_alphanumeric() && ch != '-' && ch != '_' {
679 return Err(RemoteError::InvalidName {
680 name: name.to_string(),
681 reason: format!(
682 "name contains invalid character '{}'; only alphanumeric, hyphen, and underscore are allowed",
683 ch
684 ),
685 });
686 }
687 }
688
689 Ok(())
690}
691
692// Tests
693

Callers 2

addMethod · 0.85
renameMethod · 0.85

Calls 1

is_emptyMethod · 0.45

Tested by

no test coverage detected