From 52370f542dad87ab029a5d701cc46658d5aef91b Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Tue, 11 Nov 2025 07:21:08 +0000 Subject: fix: cli output line deletion during fetch also reduce the clutter in the cli output for grasp servers. --- src/bin/git_remote_nostr/list.rs | 1 - src/bin/git_remote_nostr/push.rs | 1 - src/bin/ngit/sub_commands/sync.rs | 9 ++------- src/lib/list.rs | 38 +++++++++++++++++++------------------- tests/git_remote_nostr/list.rs | 8 ++++---- 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( git_repo, &repo_ref.git_server, &repo_ref.to_nostr_git_url(&None), - &repo_ref.grasp_servers(), ); 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( git_repo, &repo_ref.git_server, &repo_ref.to_nostr_git_url(&None), - &repo_ref.grasp_servers(), ) }); 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<()> { let term = console::Term::stderr(); - let remote_states = list_from_remotes( - &term, - &git_repo, - &repo_ref.git_server, - &decoded_nostr_url, - &repo_ref.grasp_servers(), - ); + let remote_states = + list_from_remotes(&term, &git_repo, &repo_ref.git_server, &decoded_nostr_url); let missing_refs = 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::{ Repo, RepoActions, nostr_url::{CloneUrl, NostrUrlDecoded, ServerProtocol}, }, - repo_ref::is_grasp_server_in_list, + repo_ref::is_grasp_server_clone_url, utils::{Direction, get_read_protocols_to_try, join_with_and, set_protocol_preference}, }; @@ -18,12 +18,11 @@ pub fn list_from_remotes( git_repo: &Repo, git_servers: &Vec, decoded_nostr_url: &NostrUrlDecoded, - grasp_servers: &[String], ) -> HashMap, bool)> { let mut remote_states = HashMap::new(); let mut errors = HashMap::new(); for url in git_servers { - let is_grasp_server = is_grasp_server_in_list(url, grasp_servers); + let is_grasp_server = is_grasp_server_clone_url(url); match list_from_remote(term, git_repo, url, decoded_nostr_url, is_grasp_server) { Err(error) => { errors.insert(url, error); @@ -72,8 +71,7 @@ pub fn list_from_remote( match res { Ok(state) => { remote_state = Some(state); - term.clear_last_lines(1)?; - if !failed_protocols.is_empty() { + if !is_grasp_server && !failed_protocols.is_empty() { term.write_line( format!( "list: succeeded over {protocol} from {}", @@ -87,27 +85,27 @@ pub fn list_from_remote( break; } Err(error) => { - term.clear_last_lines(1)?; - term.write_line(&format!( - "list: {formatted_url} failed over {protocol}{}: {error}", - if protocol == &ServerProtocol::Ssh { - if let Some(ssh_key_file) = &decoded_nostr_url.ssh_key_file_path() { - format!(" with ssh key from {ssh_key_file}") + if is_grasp_server { + term.write_line(&format!("list: failed: {error}"))?; + } else { + term.write_line(&format!( + "list: {formatted_url} failed over {protocol}{}: {error}", + if protocol == &ServerProtocol::Ssh { + if let Some(ssh_key_file) = &decoded_nostr_url.ssh_key_file_path() { + format!(" with ssh key from {ssh_key_file}") + } else { + String::new() + } } else { String::new() } - } else { - String::new() - } - ))?; + ))?; + } failed_protocols.push(protocol); } } } if let Some(remote_state) = remote_state { - if failed_protocols.is_empty() { - term.clear_last_lines(1)?; - } Ok(remote_state) } else { let error = anyhow!( @@ -120,7 +118,9 @@ pub fn list_from_remote( "" }, ); - term.write_line(format!("list: {error}").as_str())?; + if !is_grasp_server { + term.write_line(format!("list: {error}").as_str())?; + } Err(error) } } 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 { let mut p = cli_tester_after_fetch(&git_repo)?; p.send_line("list")?; p.expect(format!("fetching {source_path} ref list over filesystem...\r\n").as_str())?; - p.expect("list: connecting...\r\n\r\r\r")?; + p.expect("list: connecting...\r\n\r")?; // println!("{}", p.expect_eventually("\r\n\r\n")?); let res = p.expect_eventually("\r\n\r\n")?; p.exit()?; @@ -122,7 +122,7 @@ mod with_state_announcement { p.expect( format!("fetching {source_path} ref list over filesystem...\r\n").as_str(), )?; - p.expect("list: connecting...\r\n\r\r\r")?; + p.expect("list: connecting...\r\n\r")?; // println!("{}", p.expect_eventually("\r\n\r\n")?); let res = p.expect_eventually("\r\n\r\n")?; p.exit()?; @@ -206,7 +206,7 @@ mod with_state_announcement { p.expect( format!("fetching {source_path} ref list over filesystem...\r\n").as_str(), )?; - p.expect("list: connecting...\r\n\r\r\r")?; + p.expect("list: connecting...\r\n\r")?; p.expect( format!( "WARNING: {source_path} refs/heads/main is out of sync with nostr \r\n" @@ -293,7 +293,7 @@ mod with_state_announcement { p.expect( format!("fetching {source_path} ref list over filesystem...\r\n").as_str(), )?; - p.expect("list: connecting...\r\n\r\r\r")?; + p.expect("list: connecting...\r\n\r")?; // println!("{}", p.expect_eventually("\r\n\r\n")?); let res = p.expect_eventually("\r\n\r\n")?; 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<()> { let mut p = CliTester::new_git_with_remote_helper_from_dir(&git_repo.dir, ["push"]); cli_expect_nostr_fetch(&mut p)?; p.expect(format!("fetching {source_path} ref list over filesystem...\r\n").as_str())?; - p.expect("list: connecting...\r\n\r\r\r")?; + p.expect("list: connecting...\r\n\r")?; p.expect_eventually_and_print(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; let output = p.expect_end_eventually()?; @@ -1694,7 +1694,7 @@ async fn push_new_pr_branch_creates_proposal() -> Result<()> { ); cli_expect_nostr_fetch(&mut p)?; p.expect(format!("fetching {source_path} ref list over filesystem...\r\n").as_str())?; - p.expect("list: connecting...\r\n\r\r\r")?; + p.expect("list: connecting...\r\n\r")?; p.expect_eventually_and_print(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; let output = p.expect_end_eventually()?; -- cgit v1.2.3