upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/git_remote_nostr/main.rs12
-rw-r--r--src/bin/ngit/sub_commands/init.rs66
2 files changed, 31 insertions, 47 deletions
diff --git a/src/bin/git_remote_nostr/main.rs b/src/bin/git_remote_nostr/main.rs
index 54fb7cf..8e12d68 100644
--- a/src/bin/git_remote_nostr/main.rs
+++ b/src/bin/git_remote_nostr/main.rs
@@ -43,10 +43,10 @@ async fn main() -> Result<()> {
43 client.set_signer(signer).await; 43 client.set_signer(signer).await;
44 } 44 }
45 45
46 fetching_with_report_for_helper(git_repo_path, &client, &decoded_nostr_url.coordinates).await?; 46 fetching_with_report_for_helper(git_repo_path, &client, &decoded_nostr_url.coordinate).await?;
47 47
48 let repo_ref = 48 let repo_ref =
49 get_repo_ref_from_cache(Some(git_repo_path), &decoded_nostr_url.coordinates).await?; 49 get_repo_ref_from_cache(Some(git_repo_path), &decoded_nostr_url.coordinate).await?;
50 50
51 let stdin = io::stdin(); 51 let stdin = io::stdin();
52 let mut line = String::new(); 52 let mut line = String::new();
@@ -148,12 +148,16 @@ fn process_args() -> Result<Option<(NostrUrlDecoded, Repo)>> {
148async fn fetching_with_report_for_helper( 148async fn fetching_with_report_for_helper(
149 git_repo_path: &Path, 149 git_repo_path: &Path,
150 client: &Client, 150 client: &Client,
151 repo_coordinates: &HashSet<Coordinate>, 151 trusted_maintainer_coordinate: &Coordinate,
152) -> Result<()> { 152) -> Result<()> {
153 let term = console::Term::stderr(); 153 let term = console::Term::stderr();
154 term.write_line("nostr: fetching...")?; 154 term.write_line("nostr: fetching...")?;
155 let (relay_reports, progress_reporter) = client 155 let (relay_reports, progress_reporter) = client
156 .fetch_all(Some(git_repo_path), repo_coordinates, &HashSet::new()) 156 .fetch_all(
157 Some(git_repo_path),
158 Some(trusted_maintainer_coordinate),
159 &HashSet::new(),
160 )
157 .await?; 161 .await?;
158 if !relay_reports.iter().any(std::result::Result::is_err) { 162 if !relay_reports.iter().any(std::result::Result::is_err) {
159 let _ = progress_reporter.clear(); 163 let _ = progress_reporter.clear();
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