diff options
Diffstat (limited to 'src/bin/ngit/sub_commands/init.rs')
| -rw-r--r-- | src/bin/ngit/sub_commands/init.rs | 66 |
1 files changed, 23 insertions, 43 deletions
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index bf57769..9d87ba2 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs | |||
| @@ -60,18 +60,17 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 60 | 60 | ||
| 61 | let mut client = Client::default(); | 61 | let mut client = Client::default(); |
| 62 | 62 | ||
| 63 | let repo_coordinates = if let Ok(repo_coordinates) = | 63 | let repo_coordinate = if let Ok(repo_coordinate) = |
| 64 | try_and_get_repo_coordinates(&git_repo, &client, false).await | 64 | try_and_get_repo_coordinates(&git_repo, &client, false).await |
| 65 | { | 65 | { |
| 66 | Some(repo_coordinates) | 66 | Some(repo_coordinate) |
| 67 | } else { | 67 | } else { |
| 68 | None | 68 | None |
| 69 | }; | 69 | }; |
| 70 | 70 | ||
| 71 | let repo_ref = if let Some(repo_coordinates) = repo_coordinates.clone() { | 71 | let repo_ref = if let Some(repo_coordinate) = &repo_coordinate { |
| 72 | fetching_with_report(git_repo_path, &client, &repo_coordinates).await?; | 72 | fetching_with_report(git_repo_path, &client, repo_coordinate).await?; |
| 73 | if let Ok(repo_ref) = get_repo_ref_from_cache(Some(git_repo_path), &repo_coordinates).await | 73 | if let Ok(repo_ref) = get_repo_ref_from_cache(Some(git_repo_path), repo_coordinate).await { |
| 74 | { | ||
| 75 | Some(repo_ref) | 74 | Some(repo_ref) |
| 76 | } else { | 75 | } else { |
| 77 | None | 76 | None |
| @@ -98,12 +97,8 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 98 | .with_prompt("repo name") | 97 | .with_prompt("repo name") |
| 99 | .with_default(if let Some(repo_ref) = &repo_ref { | 98 | .with_default(if let Some(repo_ref) = &repo_ref { |
| 100 | repo_ref.name.clone() | 99 | repo_ref.name.clone() |
| 101 | } else if let Some(repo_coordinates) = repo_coordinates.clone() { | 100 | } else if let Some(coordinate) = &repo_coordinate { |
| 102 | if let Some(coordinate) = repo_coordinates.iter().next() { | 101 | coordinate.identifier.clone() |
| 103 | coordinate.identifier.clone() | ||
| 104 | } else { | ||
| 105 | String::new() | ||
| 106 | } | ||
| 107 | } else { | 102 | } else { |
| 108 | String::new() | 103 | String::new() |
| 109 | }), | 104 | }), |
| @@ -119,12 +114,8 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 119 | ) | 114 | ) |
| 120 | .with_default(if let Some(repo_ref) = &repo_ref { | 115 | .with_default(if let Some(repo_ref) = &repo_ref { |
| 121 | repo_ref.identifier.clone() | 116 | repo_ref.identifier.clone() |
| 122 | } else if let Some(repo_coordinates) = repo_coordinates.clone() { | 117 | } else if let Some(repo_coordinate) = &repo_coordinate { |
| 123 | if let Some(coordinate) = repo_coordinates.iter().next() { | 118 | repo_coordinate.identifier.clone() |
| 124 | coordinate.identifier.clone() | ||
| 125 | } else { | ||
| 126 | String::new() | ||
| 127 | } | ||
| 128 | } else { | 119 | } else { |
| 129 | let fallback = name | 120 | let fallback = name |
| 130 | .clone() | 121 | .clone() |
| @@ -503,32 +494,21 @@ fn prompt_to_set_nostr_url_as_origin(repo_ref: &RepoRef, git_repo: &Repo) -> Res | |||
| 503 | if let Ok(origin_remote) = git_repo.git_repo.find_remote("origin") { | 494 | if let Ok(origin_remote) = git_repo.git_repo.find_remote("origin") { |
| 504 | if let Some(origin_url) = origin_remote.url() { | 495 | if let Some(origin_url) = origin_remote.url() { |
| 505 | if let Ok(nostr_url) = NostrUrlDecoded::from_str(origin_url) { | 496 | if let Ok(nostr_url) = NostrUrlDecoded::from_str(origin_url) { |
| 506 | if let Some(c) = &nostr_url.coordinates.iter().next() { | 497 | if nostr_url.coordinate.identifier == repo_ref.identifier { |
| 507 | if c.identifier == repo_ref.identifier { | 498 | if nostr_url.coordinate.public_key == repo_ref.trusted_maintainer { |
| 508 | if nostr_url | 499 | return Ok(()); |
| 509 | .coordinates | ||
| 510 | .iter() | ||
| 511 | .next() | ||
| 512 | .context( | ||
| 513 | "a decoded nostr url will always have at least one coordinate", | ||
| 514 | )? | ||
| 515 | .public_key | ||
| 516 | == repo_ref.trusted_maintainer | ||
| 517 | { | ||
| 518 | return Ok(()); | ||
| 519 | } | ||
| 520 | // origin is set to a different trusted maintainer | ||
| 521 | println!( | ||
| 522 | "warning: currently git remote 'origin' is set to a different trusted maintainer with the same identifier" | ||
| 523 | ); | ||
| 524 | ask_to_set_origin_remote(repo_ref, git_repo)?; | ||
| 525 | } else { | ||
| 526 | // origin is linked to a different identifier | ||
| 527 | println!( | ||
| 528 | "warning: currently git remote 'origin' is set to a different repository identifier" | ||
| 529 | ); | ||
| 530 | ask_to_set_origin_remote(repo_ref, git_repo)?; | ||
| 531 | } | 500 | } |
| 501 | // origin is set to a different trusted maintainer | ||
| 502 | println!( | ||
| 503 | "warning: currently git remote 'origin' is set to a different trusted maintainer with the same identifier" | ||
| 504 | ); | ||
| 505 | ask_to_set_origin_remote(repo_ref, git_repo)?; | ||
| 506 | } else { | ||
| 507 | // origin is linked to a different identifier | ||
| 508 | println!( | ||
| 509 | "warning: currently git remote 'origin' is set to a different repository identifier" | ||
| 510 | ); | ||
| 511 | ask_to_set_origin_remote(repo_ref, git_repo)?; | ||
| 532 | } | 512 | } |
| 533 | } else { | 513 | } else { |
| 534 | // remote is non-nostr url | 514 | // remote is non-nostr url |