upleb.uk

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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-12-09 15:35:18 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2024-12-09 15:35:18 +0000
commitd8f4f7641312bff32f772cbc070b3f99ced0c8fe (patch)
tree0ca4db7b41d7c191eb91ceb1c8124b5e659a3566
parentf0d0e1ba1cba11d3a98a5ab0c7f1dc72b6bc4e17 (diff)
fix: fetch user relays for `send`,`push` & `init`
get the latest user relay list before pushing patches and repo announcement events
-rw-r--r--src/bin/git_remote_nostr/main.rs13
-rw-r--r--src/bin/git_remote_nostr/push.rs2
-rw-r--r--src/bin/ngit/sub_commands/export_keys.rs1
-rw-r--r--src/bin/ngit/sub_commands/init.rs1
-rw-r--r--src/bin/ngit/sub_commands/login.rs13
-rw-r--r--src/bin/ngit/sub_commands/logout.rs13
-rw-r--r--src/bin/ngit/sub_commands/send.rs1
-rw-r--r--src/lib/login/existing.rs3
-rw-r--r--src/lib/login/fresh.rs3
-rw-r--r--src/lib/login/mod.rs14
-rw-r--r--src/lib/login/user.rs15
-rw-r--r--src/lib/repo_ref.rs2
-rw-r--r--tests/ngit_send.rs3
13 files changed, 73 insertions, 11 deletions
diff --git a/src/bin/git_remote_nostr/main.rs b/src/bin/git_remote_nostr/main.rs
index 8e12d68..5f9f712 100644
--- a/src/bin/git_remote_nostr/main.rs
+++ b/src/bin/git_remote_nostr/main.rs
@@ -36,8 +36,17 @@ async fn main() -> Result<()> {
36 36
37 let mut client = Client::default(); 37 let mut client = Client::default();
38 38
39 if let Ok((signer, _, _)) = 39 if let Ok((signer, _, _)) = load_existing_login(
40 load_existing_login(&Some(&git_repo), &None, &None, &None, None, true, false).await 40 &Some(&git_repo),
41 &None,
42 &None,
43 &None,
44 None,
45 true,
46 false,
47 false,
48 )
49 .await
41 { 50 {
42 // signer for to respond to relay auth request 51 // signer for to respond to relay auth request
43 client.set_signer(signer).await; 52 client.set_signer(signer).await;
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs
index 40e9584..6116fe2 100644
--- a/src/bin/git_remote_nostr/push.rs
+++ b/src/bin/git_remote_nostr/push.rs
@@ -127,7 +127,7 @@ pub async fn run_push(
127 } 127 }
128 128
129 let (signer, user_ref, _) = 129 let (signer, user_ref, _) =
130 login::login_or_signup(&Some(git_repo), &None, &None, Some(client)).await?; 130 login::login_or_signup(&Some(git_repo), &None, &None, Some(client), true).await?;
131 131
132 if !repo_ref.maintainers.contains(&user_ref.public_key) { 132 if !repo_ref.maintainers.contains(&user_ref.public_key) {
133 for refspec in &git_server_refspecs { 133 for refspec in &git_server_refspecs {
diff --git a/src/bin/ngit/sub_commands/export_keys.rs b/src/bin/ngit/sub_commands/export_keys.rs
index 12fc380..54a716f 100644
--- a/src/bin/ngit/sub_commands/export_keys.rs
+++ b/src/bin/ngit/sub_commands/export_keys.rs
@@ -28,6 +28,7 @@ pub async fn launch() -> Result<()> {
28 None, 28 None,
29 true, 29 true,
30 false, 30 false,
31 false,
31 ) 32 )
32 .await 33 .await
33 { 34 {
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs
index 6fc1ec4..7ed98f5 100644
--- a/src/bin/ngit/sub_commands/init.rs
+++ b/src/bin/ngit/sub_commands/init.rs
@@ -84,6 +84,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> {
84 &extract_signer_cli_arguments(cli_args).unwrap_or(None), 84 &extract_signer_cli_arguments(cli_args).unwrap_or(None),
85 &cli_args.password, 85 &cli_args.password,
86 Some(&client), 86 Some(&client),
87 true,
87 ) 88 )
88 .await?; 89 .await?;
89 90
diff --git a/src/bin/ngit/sub_commands/login.rs b/src/bin/ngit/sub_commands/login.rs
index 7670bc3..ccbdf01 100644
--- a/src/bin/ngit/sub_commands/login.rs
+++ b/src/bin/ngit/sub_commands/login.rs
@@ -64,8 +64,17 @@ async fn logout(git_repo: Option<&Repo>, local_only: bool) -> Result<(bool, bool
64 } else { 64 } else {
65 vec![SignerInfoSource::GitLocal, SignerInfoSource::GitGlobal] 65 vec![SignerInfoSource::GitLocal, SignerInfoSource::GitGlobal]
66 } { 66 } {
67 if let Ok((_, user_ref, source)) = 67 if let Ok((_, user_ref, source)) = load_existing_login(
68 load_existing_login(&git_repo, &None, &None, &Some(source), None, true, false).await 68 &git_repo,
69 &None,
70 &None,
71 &Some(source),
72 None,
73 true,
74 false,
75 false,
76 )
77 .await
69 { 78 {
70 match Interactor::default().choice( 79 match Interactor::default().choice(
71 PromptChoiceParms::default() 80 PromptChoiceParms::default()
diff --git a/src/bin/ngit/sub_commands/logout.rs b/src/bin/ngit/sub_commands/logout.rs
index 682c017..f3f9620 100644
--- a/src/bin/ngit/sub_commands/logout.rs
+++ b/src/bin/ngit/sub_commands/logout.rs
@@ -26,8 +26,17 @@ async fn logout(git_repo: Option<&Repo>) -> Result<()> {
26 } else { 26 } else {
27 vec![SignerInfoSource::GitLocal, SignerInfoSource::GitGlobal] 27 vec![SignerInfoSource::GitLocal, SignerInfoSource::GitGlobal]
28 } { 28 } {
29 if let Ok((_, user_ref, source)) = 29 if let Ok((_, user_ref, source)) = load_existing_login(
30 load_existing_login(&git_repo, &None, &None, &Some(source), None, true, false).await 30 &git_repo,
31 &None,
32 &None,
33 &Some(source),
34 None,
35 true,
36 false,
37 false,
38 )
39 .await
31 { 40 {
32 for item in [ 41 for item in [
33 "nostr.nsec", 42 "nostr.nsec",
diff --git a/src/bin/ngit/sub_commands/send.rs b/src/bin/ngit/sub_commands/send.rs
index e19c38b..c6c75c9 100644
--- a/src/bin/ngit/sub_commands/send.rs
+++ b/src/bin/ngit/sub_commands/send.rs
@@ -181,6 +181,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs, no_fetch: bool) -> Re
181 &extract_signer_cli_arguments(cli_args).unwrap_or(None), 181 &extract_signer_cli_arguments(cli_args).unwrap_or(None),
182 &cli_args.password, 182 &cli_args.password,
183 Some(&client), 183 Some(&client),
184 true,
184 ) 185 )
185 .await?; 186 .await?;
186 187
diff --git a/src/lib/login/existing.rs b/src/lib/login/existing.rs
index 45727b0..4606c22 100644
--- a/src/lib/login/existing.rs
+++ b/src/lib/login/existing.rs
@@ -27,6 +27,7 @@ use crate::{
27/// - `client`: include client to fetch profiles from relays that are missing 27/// - `client`: include client to fetch profiles from relays that are missing
28/// from cache 28/// from cache
29/// - `silent`: do not print outcome in termianl 29/// - `silent`: do not print outcome in termianl
30#[allow(clippy::too_many_arguments)]
30pub async fn load_existing_login( 31pub async fn load_existing_login(
31 git_repo: &Option<&Repo>, 32 git_repo: &Option<&Repo>,
32 signer_info: &Option<SignerInfo>, 33 signer_info: &Option<SignerInfo>,
@@ -36,6 +37,7 @@ pub async fn load_existing_login(
36 #[cfg(not(test))] client: Option<&Client>, 37 #[cfg(not(test))] client: Option<&Client>,
37 silent: bool, 38 silent: bool,
38 prompt_for_password: bool, 39 prompt_for_password: bool,
40 fetch_profile_updates: bool,
39) -> Result<(Arc<dyn NostrSigner>, UserRef, SignerInfoSource)> { 41) -> Result<(Arc<dyn NostrSigner>, UserRef, SignerInfoSource)> {
40 let (signer_info, source) = get_signer_info(git_repo, signer_info, password, source)?; 42 let (signer_info, source) = get_signer_info(git_repo, signer_info, password, source)?;
41 43
@@ -50,6 +52,7 @@ pub async fn load_existing_login(
50 None 52 None
51 }, 53 },
52 silent, 54 silent,
55 fetch_profile_updates,
53 ) 56 )
54 .await?; 57 .await?;
55 58
diff --git a/src/lib/login/fresh.rs b/src/lib/login/fresh.rs
index 615c0a6..7cdbde8 100644
--- a/src/lib/login/fresh.rs
+++ b/src/lib/login/fresh.rs
@@ -46,6 +46,7 @@ pub async fn fresh_login_or_signup(
46 client, 46 client,
47 true, 47 true,
48 true, 48 true,
49 false,
49 ) 50 )
50 .await?; 51 .await?;
51 break (signer, user_ref.public_key, signer_info, source); 52 break (signer, user_ref.public_key, signer_info, source);
@@ -102,6 +103,7 @@ pub async fn fresh_login_or_signup(
102 None 103 None
103 }, 104 },
104 false, 105 false,
106 false,
105 ) 107 )
106 .await?; 108 .await?;
107 print_logged_in_as(&user_ref, client.is_none(), &source)?; 109 print_logged_in_as(&user_ref, client.is_none(), &source)?;
@@ -549,6 +551,7 @@ async fn save_to_git_config(
549 None, 551 None,
550 true, 552 true,
551 true, 553 true,
554 false,
552 ) 555 )
553 .await 556 .await
554 { 557 {
diff --git a/src/lib/login/mod.rs b/src/lib/login/mod.rs
index 00dbb17..0be1e5d 100644
--- a/src/lib/login/mod.rs
+++ b/src/lib/login/mod.rs
@@ -24,9 +24,19 @@ pub async fn login_or_signup(
24 password: &Option<String>, 24 password: &Option<String>,
25 #[cfg(test)] client: Option<&MockConnect>, 25 #[cfg(test)] client: Option<&MockConnect>,
26 #[cfg(not(test))] client: Option<&Client>, 26 #[cfg(not(test))] client: Option<&Client>,
27 fetch_profile_updates: bool,
27) -> Result<(Arc<dyn NostrSigner>, UserRef, SignerInfoSource)> { 28) -> Result<(Arc<dyn NostrSigner>, UserRef, SignerInfoSource)> {
28 let res = 29 let res = load_existing_login(
29 load_existing_login(git_repo, signer_info, password, &None, client, false, true).await; 30 git_repo,
31 signer_info,
32 password,
33 &None,
34 client,
35 false,
36 true,
37 fetch_profile_updates,
38 )
39 .await;
30 if res.is_ok() { 40 if res.is_ok() {
31 res 41 res
32 } else { 42 } else {
diff --git a/src/lib/login/user.rs b/src/lib/login/user.rs
index 1898a1f..c13cdf5 100644
--- a/src/lib/login/user.rs
+++ b/src/lib/login/user.rs
@@ -60,8 +60,23 @@ pub async fn get_user_details(
60 #[cfg(not(test))] client: Option<&Client>, 60 #[cfg(not(test))] client: Option<&Client>,
61 git_repo_path: Option<&Path>, 61 git_repo_path: Option<&Path>,
62 cache_only: bool, 62 cache_only: bool,
63 fetch_profile_updates: bool,
63) -> Result<UserRef> { 64) -> Result<UserRef> {
64 if let Ok(user_ref) = get_user_ref_from_cache(git_repo_path, public_key).await { 65 if let Ok(user_ref) = get_user_ref_from_cache(git_repo_path, public_key).await {
66 if fetch_profile_updates {
67 if let Some(client) = client {
68 let term = console::Term::stderr();
69 term.write_line("searching for profile updates...")?;
70 let (reports, progress_reporter) = client
71 .fetch_all(git_repo_path, None, &HashSet::from_iter(vec![*public_key]))
72 .await?;
73 if !reports.iter().any(|r| r.is_err()) {
74 progress_reporter.clear()?;
75 term.clear_last_lines(1)?;
76 }
77 return get_user_ref_from_cache(git_repo_path, public_key).await;
78 }
79 }
65 Ok(user_ref) 80 Ok(user_ref)
66 } else { 81 } else {
67 let empty = UserRef { 82 let empty = UserRef {
diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs
index 1b25ccf..da76182 100644
--- a/src/lib/repo_ref.rs
+++ b/src/lib/repo_ref.rs
@@ -308,7 +308,7 @@ async fn get_nostr_git_remote_selection_labels(
308 for (remote, c) in remote_coordinates { 308 for (remote, c) in remote_coordinates {
309 res.push(format!( 309 res.push(format!(
310 "{remote} - {}/{}", 310 "{remote} - {}/{}",
311 get_user_details(&c.public_key, None, Some(git_repo.get_path()?), true) 311 get_user_details(&c.public_key, None, Some(git_repo.get_path()?), true, false)
312 .await? 312 .await?
313 .metadata 313 .metadata
314 .name, 314 .name,
diff --git a/tests/ngit_send.rs b/tests/ngit_send.rs
index 1d5b308..1ffb515 100644
--- a/tests/ngit_send.rs
+++ b/tests/ngit_send.rs
@@ -1408,7 +1408,8 @@ mod root_proposal_specified_using_in_reply_to_with_range_of_head_2_and_cover_let
1408 p.expect("creating proposal from 2 commits:\r\n")?; 1408 p.expect("creating proposal from 2 commits:\r\n")?;
1409 p.expect("fe973a8 add t4.md\r\n")?; 1409 p.expect("fe973a8 add t4.md\r\n")?;
1410 p.expect("232efb3 add t3.md\r\n")?; 1410 p.expect("232efb3 add t3.md\r\n")?;
1411 p.expect("logged in as fred via cli arguments\r\n")?; 1411 p.expect("searching for profile updates...\r\n")?;
1412 p.expect_after_whitespace("logged in as fred via cli arguments\r\n")?;
1412 p.expect(format!( 1413 p.expect(format!(
1413 "posting 2 patches {} a covering letter...\r\n", 1414 "posting 2 patches {} a covering letter...\r\n",
1414 if include_cover_letter { 1415 if include_cover_letter {