diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-11 07:21:08 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2025-11-13 14:40:09 +0000 |
| commit | 52370f542dad87ab029a5d701cc46658d5aef91b (patch) | |
| tree | fb7f6283850f528aaeca8aec606dd5bd41906d9a | |
| parent | be1a8e53383dc495ede773a76131fad81f04d101 (diff) | |
fix: cli output line deletion during fetch
also reduce the clutter in the cli output for grasp servers.
| -rw-r--r-- | src/bin/git_remote_nostr/list.rs | 1 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 1 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/sync.rs | 9 | ||||
| -rw-r--r-- | src/lib/list.rs | 38 | ||||
| -rw-r--r-- | tests/git_remote_nostr/list.rs | 8 | ||||
| -rw-r--r-- | tests/git_remote_nostr/push.rs | 4 |
6 files changed, 27 insertions, 34 deletions
diff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs index b3ef2f6..803cc8f 100644 --- a/src/bin/git_remote_nostr/list.rs +++ b/src/bin/git_remote_nostr/list.rs | |||
| @@ -31,7 +31,6 @@ pub async fn run_list( | |||
| 31 | git_repo, | 31 | git_repo, |
| 32 | &repo_ref.git_server, | 32 | &repo_ref.git_server, |
| 33 | &repo_ref.to_nostr_git_url(&None), | 33 | &repo_ref.to_nostr_git_url(&None), |
| 34 | &repo_ref.grasp_servers(), | ||
| 35 | ); | 34 | ); |
| 36 | 35 | ||
| 37 | let mut state = if let Some(nostr_state) = nostr_state { | 36 | let mut state = if let Some(nostr_state) = nostr_state { |
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index e880f0d..c35699d 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs | |||
| @@ -75,7 +75,6 @@ pub async fn run_push( | |||
| 75 | git_repo, | 75 | git_repo, |
| 76 | &repo_ref.git_server, | 76 | &repo_ref.git_server, |
| 77 | &repo_ref.to_nostr_git_url(&None), | 77 | &repo_ref.to_nostr_git_url(&None), |
| 78 | &repo_ref.grasp_servers(), | ||
| 79 | ) | 78 | ) |
| 80 | }); | 79 | }); |
| 81 | 80 | ||
diff --git a/src/bin/ngit/sub_commands/sync.rs b/src/bin/ngit/sub_commands/sync.rs index b7eb812..2722da2 100644 --- a/src/bin/ngit/sub_commands/sync.rs +++ b/src/bin/ngit/sub_commands/sync.rs | |||
| @@ -77,13 +77,8 @@ pub async fn launch(args: &SubCommandArgs) -> Result<()> { | |||
| 77 | 77 | ||
| 78 | let term = console::Term::stderr(); | 78 | let term = console::Term::stderr(); |
| 79 | 79 | ||
| 80 | let remote_states = list_from_remotes( | 80 | let remote_states = |
| 81 | &term, | 81 | list_from_remotes(&term, &git_repo, &repo_ref.git_server, &decoded_nostr_url); |
| 82 | &git_repo, | ||
| 83 | &repo_ref.git_server, | ||
| 84 | &decoded_nostr_url, | ||
| 85 | &repo_ref.grasp_servers(), | ||
| 86 | ); | ||
| 87 | 82 | ||
| 88 | let missing_refs = | 83 | let missing_refs = |
| 89 | fetch_missing_refs(&git_repo, &nostr_state, &remote_states, &decoded_nostr_url); | 84 | fetch_missing_refs(&git_repo, &nostr_state, &remote_states, &decoded_nostr_url); |
diff --git a/src/lib/list.rs b/src/lib/list.rs index 639140e..733936a 100644 --- a/src/lib/list.rs +++ b/src/lib/list.rs | |||
| @@ -9,7 +9,7 @@ use crate::{ | |||
| 9 | Repo, RepoActions, | 9 | Repo, RepoActions, |
| 10 | nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, | 10 | nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, |
| 11 | }, | 11 | }, |
| 12 | repo_ref::is_grasp_server_in_list, | 12 | repo_ref::is_grasp_server_clone_url, |
| 13 | utils::{Direction, get_read_protocols_to_try, join_with_and, set_protocol_preference}, | 13 | utils::{Direction, get_read_protocols_to_try, join_with_and, set_protocol_preference}, |
| 14 | }; | 14 | }; |
| 15 | 15 | ||
| @@ -18,12 +18,11 @@ pub fn list_from_remotes( | |||
| 18 | git_repo: &Repo, | 18 | git_repo: &Repo, |
| 19 | git_servers: &Vec<String>, | 19 | git_servers: &Vec<String>, |
| 20 | decoded_nostr_url: &NostrUrlDecoded, | 20 | decoded_nostr_url: &NostrUrlDecoded, |
| 21 | grasp_servers: &[String], | ||
| 22 | ) -> HashMap<String, (HashMap<String, String>, bool)> { | 21 | ) -> HashMap<String, (HashMap<String, String>, bool)> { |
| 23 | let mut remote_states = HashMap::new(); | 22 | let mut remote_states = HashMap::new(); |
| 24 | let mut errors = HashMap::new(); | 23 | let mut errors = HashMap::new(); |
| 25 | for url in git_servers { | 24 | for url in git_servers { |
| 26 | let is_grasp_server = is_grasp_server_in_list(url, grasp_servers); | 25 | let is_grasp_server = is_grasp_server_clone_url(url); |
| 27 | match list_from_remote(term, git_repo, url, decoded_nostr_url, is_grasp_server) { | 26 | match list_from_remote(term, git_repo, url, decoded_nostr_url, is_grasp_server) { |
| 28 | Err(error) => { | 27 | Err(error) => { |
| 29 | errors.insert(url, error); | 28 | errors.insert(url, error); |
| @@ -72,8 +71,7 @@ pub fn list_from_remote( | |||
| 72 | match res { | 71 | match res { |
| 73 | Ok(state) => { | 72 | Ok(state) => { |
| 74 | remote_state = Some(state); | 73 | remote_state = Some(state); |
| 75 | term.clear_last_lines(1)?; | 74 | if !is_grasp_server && !failed_protocols.is_empty() { |
| 76 | if !failed_protocols.is_empty() { | ||
| 77 | term.write_line( | 75 | term.write_line( |
| 78 | format!( | 76 | format!( |
| 79 | "list: succeeded over {protocol} from {}", | 77 | "list: succeeded over {protocol} from {}", |
| @@ -87,27 +85,27 @@ pub fn list_from_remote( | |||
| 87 | break; | 85 | break; |
| 88 | } | 86 | } |
| 89 | Err(error) => { | 87 | Err(error) => { |
| 90 | term.clear_last_lines(1)?; | 88 | if is_grasp_server { |
| 91 | term.write_line(&format!( | 89 | term.write_line(&format!("list: failed: {error}"))?; |
| 92 | "list: {formatted_url} failed over {protocol}{}: {error}", | 90 | } else { |
| 93 | if protocol == &ServerProtocol::Ssh { | 91 | term.write_line(&format!( |
| 94 | if let Some(ssh_key_file) = &decoded_nostr_url.ssh_key_file_path() { | 92 | "list: {formatted_url} failed over {protocol}{}: {error}", |
| 95 | format!(" with ssh key from {ssh_key_file}") | 93 | if protocol == &ServerProtocol::Ssh { |
| 94 | if let Some(ssh_key_file) = &decoded_nostr_url.ssh_key_file_path() { | ||
| 95 | format!(" with ssh key from {ssh_key_file}") | ||
| 96 | } else { | ||
| 97 | String::new() | ||
| 98 | } | ||
| 96 | } else { | 99 | } else { |
| 97 | String::new() | 100 | String::new() |
| 98 | } | 101 | } |
| 99 | } else { | 102 | ))?; |
| 100 | String::new() | 103 | } |
| 101 | } | ||
| 102 | ))?; | ||
| 103 | failed_protocols.push(protocol); | 104 | failed_protocols.push(protocol); |
| 104 | } | 105 | } |
| 105 | } | 106 | } |
| 106 | } | 107 | } |
| 107 | if let Some(remote_state) = remote_state { | 108 | if let Some(remote_state) = remote_state { |
| 108 | if failed_protocols.is_empty() { | ||
| 109 | term.clear_last_lines(1)?; | ||
| 110 | } | ||
| 111 | Ok(remote_state) | 109 | Ok(remote_state) |
| 112 | } else { | 110 | } else { |
| 113 | let error = anyhow!( | 111 | let error = anyhow!( |
| @@ -120,7 +118,9 @@ pub fn list_from_remote( | |||
| 120 | "" | 118 | "" |
| 121 | }, | 119 | }, |
| 122 | ); | 120 | ); |
| 123 | term.write_line(format!("list: {error}").as_str())?; | 121 | if !is_grasp_server { |
| 122 | term.write_line(format!("list: {error}").as_str())?; | ||
| 123 | } | ||
| 124 | Err(error) | 124 | Err(error) |
| 125 | } | 125 | } |
| 126 | } | 126 | } |
diff --git a/tests/git_remote_nostr/list.rs b/tests/git_remote_nostr/list.rs index 1972cd5..530e022 100644 --- a/tests/git_remote_nostr/list.rs +++ b/tests/git_remote_nostr/list.rs | |||
| @@ -42,7 +42,7 @@ mod without_state_announcement { | |||
| 42 | let mut p = cli_tester_after_fetch(&git_repo)?; | 42 | let mut p = cli_tester_after_fetch(&git_repo)?; |
| 43 | p.send_line("list")?; | 43 | p.send_line("list")?; |
| 44 | p.expect(format!("fetching {source_path} ref list over filesystem...\r\n").as_str())?; | 44 | p.expect(format!("fetching {source_path} ref list over filesystem...\r\n").as_str())?; |
| 45 | p.expect("list: connecting...\r\n\r\r\r")?; | 45 | p.expect("list: connecting...\r\n\r")?; |
| 46 | // println!("{}", p.expect_eventually("\r\n\r\n")?); | 46 | // println!("{}", p.expect_eventually("\r\n\r\n")?); |
| 47 | let res = p.expect_eventually("\r\n\r\n")?; | 47 | let res = p.expect_eventually("\r\n\r\n")?; |
| 48 | p.exit()?; | 48 | p.exit()?; |
| @@ -122,7 +122,7 @@ mod with_state_announcement { | |||
| 122 | p.expect( | 122 | p.expect( |
| 123 | format!("fetching {source_path} ref list over filesystem...\r\n").as_str(), | 123 | format!("fetching {source_path} ref list over filesystem...\r\n").as_str(), |
| 124 | )?; | 124 | )?; |
| 125 | p.expect("list: connecting...\r\n\r\r\r")?; | 125 | p.expect("list: connecting...\r\n\r")?; |
| 126 | // println!("{}", p.expect_eventually("\r\n\r\n")?); | 126 | // println!("{}", p.expect_eventually("\r\n\r\n")?); |
| 127 | let res = p.expect_eventually("\r\n\r\n")?; | 127 | let res = p.expect_eventually("\r\n\r\n")?; |
| 128 | p.exit()?; | 128 | p.exit()?; |
| @@ -206,7 +206,7 @@ mod with_state_announcement { | |||
| 206 | p.expect( | 206 | p.expect( |
| 207 | format!("fetching {source_path} ref list over filesystem...\r\n").as_str(), | 207 | format!("fetching {source_path} ref list over filesystem...\r\n").as_str(), |
| 208 | )?; | 208 | )?; |
| 209 | p.expect("list: connecting...\r\n\r\r\r")?; | 209 | p.expect("list: connecting...\r\n\r")?; |
| 210 | p.expect( | 210 | p.expect( |
| 211 | format!( | 211 | format!( |
| 212 | "WARNING: {source_path} refs/heads/main is out of sync with nostr \r\n" | 212 | "WARNING: {source_path} refs/heads/main is out of sync with nostr \r\n" |
| @@ -293,7 +293,7 @@ mod with_state_announcement { | |||
| 293 | p.expect( | 293 | p.expect( |
| 294 | format!("fetching {source_path} ref list over filesystem...\r\n").as_str(), | 294 | format!("fetching {source_path} ref list over filesystem...\r\n").as_str(), |
| 295 | )?; | 295 | )?; |
| 296 | p.expect("list: connecting...\r\n\r\r\r")?; | 296 | p.expect("list: connecting...\r\n\r")?; |
| 297 | // println!("{}", p.expect_eventually("\r\n\r\n")?); | 297 | // println!("{}", p.expect_eventually("\r\n\r\n")?); |
| 298 | let res = p.expect_eventually("\r\n\r\n")?; | 298 | let res = p.expect_eventually("\r\n\r\n")?; |
| 299 | 299 | ||
diff --git a/tests/git_remote_nostr/push.rs b/tests/git_remote_nostr/push.rs index 91a20d8..647a2f3 100644 --- a/tests/git_remote_nostr/push.rs +++ b/tests/git_remote_nostr/push.rs | |||
| @@ -1385,7 +1385,7 @@ async fn push_2_commits_to_existing_proposal() -> Result<()> { | |||
| 1385 | let mut p = CliTester::new_git_with_remote_helper_from_dir(&git_repo.dir, ["push"]); | 1385 | let mut p = CliTester::new_git_with_remote_helper_from_dir(&git_repo.dir, ["push"]); |
| 1386 | cli_expect_nostr_fetch(&mut p)?; | 1386 | cli_expect_nostr_fetch(&mut p)?; |
| 1387 | p.expect(format!("fetching {source_path} ref list over filesystem...\r\n").as_str())?; | 1387 | p.expect(format!("fetching {source_path} ref list over filesystem...\r\n").as_str())?; |
| 1388 | p.expect("list: connecting...\r\n\r\r\r")?; | 1388 | p.expect("list: connecting...\r\n\r")?; |
| 1389 | p.expect_eventually_and_print(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; | 1389 | p.expect_eventually_and_print(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; |
| 1390 | let output = p.expect_end_eventually()?; | 1390 | let output = p.expect_end_eventually()?; |
| 1391 | 1391 | ||
| @@ -1694,7 +1694,7 @@ async fn push_new_pr_branch_creates_proposal() -> Result<()> { | |||
| 1694 | ); | 1694 | ); |
| 1695 | cli_expect_nostr_fetch(&mut p)?; | 1695 | cli_expect_nostr_fetch(&mut p)?; |
| 1696 | p.expect(format!("fetching {source_path} ref list over filesystem...\r\n").as_str())?; | 1696 | p.expect(format!("fetching {source_path} ref list over filesystem...\r\n").as_str())?; |
| 1697 | p.expect("list: connecting...\r\n\r\r\r")?; | 1697 | p.expect("list: connecting...\r\n\r")?; |
| 1698 | p.expect_eventually_and_print(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; | 1698 | p.expect_eventually_and_print(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; |
| 1699 | let output = p.expect_end_eventually()?; | 1699 | let output = p.expect_end_eventually()?; |
| 1700 | 1700 | ||