Add a new remote. # Arguments `name` - The name for the new remote `entry` - The remote configuration # Errors Returns an error if: - A remote with the same name already exists - The name is invalid - The URL is invalid # Example ```rust use atomic_repository::remote::{RemoteConfig, RemoteEntry}; let mut config = RemoteConfig::new(); config.add("origin", RemoteEntry::new("https://example.co
(&mut self, name: &str, entry: RemoteEntry)
| 474 | /// assert!(config.contains("origin")); |
| 475 | /// ``` |
| 476 | pub fn add(&mut self, name: &str, entry: RemoteEntry) -> RemoteResult<()> { |
| 477 | // Validate name |
| 478 | validate_remote_name(name)?; |
| 479 | |
| 480 | // Validate URL |
| 481 | if !entry.is_valid_url() { |
| 482 | return Err(RemoteError::InvalidUrl { |
| 483 | url: entry.url.clone(), |
| 484 | reason: "URL must include a scheme (e.g., https://)".to_string(), |
| 485 | }); |
| 486 | } |
| 487 | |
| 488 | // Check for duplicates |
| 489 | if self.remotes.contains_key(name) { |
| 490 | return Err(RemoteError::AlreadyExists { |
| 491 | name: name.to_string(), |
| 492 | }); |
| 493 | } |
| 494 | |
| 495 | // If this is marked as default, unmark any existing default |
| 496 | if entry.default { |
| 497 | for existing in self.remotes.values_mut() { |
| 498 | existing.default = false; |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | self.remotes.insert(name.to_string(), entry); |
| 503 | Ok(()) |
| 504 | } |
| 505 | |
| 506 | /// Remove a remote by name. |
| 507 | /// |