diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-05-31 15:56:27 +0100 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-05-31 19:50:07 +0100 |
| commit | cea93cee5edf67499cbd4be0843b67f68265be3e (patch) | |
| tree | 4dfc66b74fd9ef661fdeb51d5439e8ddd41d2216 /src | |
| parent | 5f45edbebe310decb06f955d95665a6ad387c6cb (diff) | |
feat(init): only use one ngit-relay git server url
that of the current users pubkey. ngit will push to the git servers of
other maintainers anyway.
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/ngit/sub_commands/init.rs | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index aea4f8b..cd94a5a 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs | |||
| @@ -297,8 +297,38 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 297 | if args.clone_url.is_empty() { | 297 | if args.clone_url.is_empty() { |
| 298 | let clone_url = | 298 | let clone_url = |
| 299 | format_ngit_relay_url_as_clone_url(ngit_relay, &user_ref.public_key, &identifier)?; | 299 | format_ngit_relay_url_as_clone_url(ngit_relay, &user_ref.public_key, &identifier)?; |
| 300 | if !git_server_defaults.contains(&clone_url) { | 300 | |
| 301 | let ngit_relay_clone_root = if clone_url.contains("https://") { | ||
| 302 | format!("https://{ngit_relay}") | ||
| 303 | } else { | ||
| 304 | ngit_relay.to_string() | ||
| 305 | }; | ||
| 306 | |||
| 307 | // Find all positions of entries containing the relay root | ||
| 308 | let matching_positions: Vec<usize> = git_server_defaults | ||
| 309 | .iter() | ||
| 310 | .enumerate() | ||
| 311 | .filter_map(|(idx, url)| { | ||
| 312 | if url.contains(&ngit_relay_clone_root) { | ||
| 313 | Some(idx) | ||
| 314 | } else { | ||
| 315 | None | ||
| 316 | } | ||
| 317 | }) | ||
| 318 | .collect(); | ||
| 319 | |||
| 320 | // If we found any matches | ||
| 321 | if matching_positions.is_empty() { | ||
| 322 | // No existing entries found, so add a new one | ||
| 301 | git_server_defaults.push(clone_url); | 323 | git_server_defaults.push(clone_url); |
| 324 | } else { | ||
| 325 | // Replace the first occurrence | ||
| 326 | git_server_defaults[matching_positions[0]] = clone_url; | ||
| 327 | |||
| 328 | // Remove any subsequent occurrences (in reverse order to avoid index issues) | ||
| 329 | for &position in matching_positions.iter().skip(1).rev() { | ||
| 330 | git_server_defaults.remove(position); | ||
| 331 | } | ||
| 302 | } | 332 | } |
| 303 | } | 333 | } |
| 304 | if args.relays.is_empty() { | 334 | if args.relays.is_empty() { |