upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/bin/ngit/sub_commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/ngit/sub_commands')
-rw-r--r--src/bin/ngit/sub_commands/init.rs32
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() {