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

Method rename

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

Rename a remote. # Arguments `old_name` - The current name of the remote `new_name` - The new name for the remote # Errors Returns an error if: - The old remote doesn't exist - The new name is invalid - A remote with the new name already exists

(&mut self, old_name: &str, new_name: &str)

Source from the content-addressed store, hash-verified

607 /// - The new name is invalid
608 /// - A remote with the new name already exists
609 pub fn rename(&mut self, old_name: &str, new_name: &str) -> RemoteResult<()> {
610 // Validate new name
611 validate_remote_name(new_name)?;
612
613 // Check old exists
614 if !self.remotes.contains_key(old_name) {
615 return Err(RemoteError::NotFound {
616 name: old_name.to_string(),
617 });
618 }
619
620 // Check new doesn't exist
621 if self.remotes.contains_key(new_name) {
622 return Err(RemoteError::AlreadyExists {
623 name: new_name.to_string(),
624 });
625 }
626
627 // Perform the rename
628 if let Some(entry) = self.remotes.remove(old_name) {
629 self.remotes.insert(new_name.to_string(), entry);
630 }
631
632 Ok(())
633 }
634
635 /// Iterate over all remotes.
636 pub fn iter(&self) -> impl Iterator<Item = (&str, &RemoteEntry)> {

Calls 4

validate_remote_nameFunction · 0.85
contains_keyMethod · 0.80
removeMethod · 0.65
insertMethod · 0.45