From ad28bd8db1a6e953dce999eea85becda1d90beae Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 6 Sep 2024 13:07:29 +0100 Subject: fix(remote): `fetch` and `list` status copy so that it the filesystem url is shown --- src/bin/git_remote_nostr/fetch.rs | 8 +++-- src/bin/git_remote_nostr/list.rs | 10 +++--- src/lib/git/nostr_url.rs | 9 +++++ tests/git_remote_helper.rs | 73 ++++++++++++++++++++++++++++++++------- 4 files changed, 81 insertions(+), 19 deletions(-) diff --git a/src/bin/git_remote_nostr/fetch.rs b/src/bin/git_remote_nostr/fetch.rs index 0a98db2..c48da85 100644 --- a/src/bin/git_remote_nostr/fetch.rs +++ b/src/bin/git_remote_nostr/fetch.rs @@ -121,7 +121,11 @@ fn fetch_from_git_server( let mut success = false; for protocol in &protocols_to_attempt { term.write_line( - format!("fetching from {} over {protocol}...", server_url.domain(),).as_str(), + format!( + "fetching over {protocol} from {}...", + server_url.short_name(), + ) + .as_str(), )?; let formatted_url = server_url.format_as(protocol, &decoded_nostr_url.user)?; @@ -152,7 +156,7 @@ fn fetch_from_git_server( } else { let error = anyhow!( "{} failed over {}{}", - server_url.domain(), + server_url.short_name(), join_with_and(&failed_protocols), if decoded_nostr_url.protocol.is_some() { " and nostr url contains protocol override so no other protocols were attempted" diff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs index ae76614..3614626 100644 --- a/src/bin/git_remote_nostr/list.rs +++ b/src/bin/git_remote_nostr/list.rs @@ -165,8 +165,8 @@ pub fn list_from_remote( for protocol in &protocols_to_attempt { term.write_line( format!( - "fetching ref list from {} over {protocol}...", - server_url.domain(), + "fetching ref list over {protocol} from {}...", + server_url.short_name(), ) .as_str(), )?; @@ -184,8 +184,8 @@ pub fn list_from_remote( if !failed_protocols.is_empty() { term.write_line( format!( - "list: succeeded over {protocol} for {}", - server_url.domain(), + "list: succeeded over {protocol} from {}", + server_url.short_name(), ) .as_str(), )?; @@ -210,7 +210,7 @@ pub fn list_from_remote( } else { let error = anyhow!( "{} failed over {}{}", - server_url.domain(), + server_url.short_name(), join_with_and(&failed_protocols), if decoded_nostr_url.protocol.is_some() { " and nostr url contains protocol override so no other protocols were attempted" diff --git a/src/lib/git/nostr_url.rs b/src/lib/git/nostr_url.rs index 2717916..d0e6d8a 100644 --- a/src/lib/git/nostr_url.rs +++ b/src/lib/git/nostr_url.rs @@ -324,6 +324,15 @@ impl CloneUrl { pub fn protocol(&self) -> ServerProtocol { self.protocol.clone() } + + pub fn short_name(&self) -> String { + let domain = self.domain(); + if domain.is_empty() { + self.original_string.to_string() + } else { + domain + } + } } fn replace_first_occurrence(s: &str, target: char, replacement: char) -> String { diff --git a/tests/git_remote_helper.rs b/tests/git_remote_helper.rs index 07f9ec8..7251204 100644 --- a/tests/git_remote_helper.rs +++ b/tests/git_remote_helper.rs @@ -314,7 +314,13 @@ mod list { let cli_tester_handle = std::thread::spawn(move || -> Result<()> { let mut p = cli_tester_after_fetch(&git_repo)?; p.send_line("list")?; - p.expect(format!("fetching refs list: {}...\r\n\r", source_path).as_str())?; + p.expect( + format!( + "fetching ref list over filesystem from {}...\r\n", + source_path + ) + .as_str(), + )?; // println!("{}", p.expect_eventually("\r\n\r\n")?); let res = p.expect_eventually("\r\n\r\n")?; p.exit()?; @@ -388,7 +394,13 @@ mod list { let cli_tester_handle = std::thread::spawn(move || -> Result<()> { let mut p = cli_tester_after_fetch(&git_repo)?; p.send_line("list")?; - p.expect(format!("fetching refs list: {}...\r\n\r", source_path).as_str())?; + p.expect( + format!( + "fetching ref list over filesystem from {}...\r\n", + source_path + ) + .as_str(), + )?; // println!("{}", p.expect_eventually("\r\n\r\n")?); let res = p.expect_eventually("\r\n\r\n")?; p.exit()?; @@ -470,7 +482,13 @@ mod list { let cli_tester_handle = std::thread::spawn(move || -> Result<()> { let mut p = cli_tester_after_fetch(&git_repo)?; p.send_line("list")?; - p.expect(format!("fetching refs list: {}...\r\n\r", source_path).as_str())?; + p.expect( + format!( + "fetching ref list over filesystem from {}...\r\n", + source_path + ) + .as_str(), + )?; p.expect( format!( "WARNING: {} refs/heads/main is out of sync with nostr \r\n", @@ -552,7 +570,13 @@ mod list { let mut p = cli_tester_after_fetch(&git_repo)?; p.send_line("list")?; - p.expect(format!("fetching refs list: {}...\r\n\r", source_path).as_str())?; + p.expect( + format!( + "fetching ref list over filesystem from {}...\r\n", + source_path + ) + .as_str(), + )?; // println!("{}", p.expect_eventually("\r\n\r\n")?); let res = p.expect_eventually("\r\n\r\n")?; @@ -659,7 +683,7 @@ mod fetch { p.send_line(format!("fetch {main_commit_id} main").as_str())?; p.send_line(format!("fetch {vnext_commit_id} vnext").as_str())?; p.send_line("")?; - p.expect(format!("fetching from {source_path}...\r\n").as_str())?; + p.expect(format!("fetching over filesystem from {source_path}...\r\n").as_str())?; p.expect_eventually_and_print("\r\n")?; assert!(git_repo.git_repo.find_commit(main_commit_id).is_ok()); @@ -725,9 +749,10 @@ mod fetch { let mut p = cli_tester_after_fetch(&git_repo)?; p.send_line(format!("fetch {main_commit_id} main").as_str())?; p.send_line("")?; - p.expect(format!("fetching from {error_path}...\r\n").as_str())?; + p.expect(format!("fetching over filesystem from {error_path}...\r\n").as_str())?; // not sure why the below isn't appearing - // p.expect(format!("fetching from {source_path}...\r\n").as_str())?; + // p.expect(format!("fetching over filesystem from + // {source_path}...\r\n").as_str())?; p.expect_eventually_and_print("\r\n")?; // p.expect("\r\n")?; @@ -782,7 +807,7 @@ mod fetch { let mut p = cli_tester_after_fetch(&git_repo)?; p.send_line(format!("fetch {proposal_tip} refs/heads/{branch_name}").as_str())?; p.send_line("")?; - p.expect(format!("fetching from {source_path}...\r\n").as_str())?; + p.expect(format!("fetching over filesystem from {source_path}...\r\n").as_str())?; // expect no errors p.expect_after_whitespace("\r\n")?; p.exit()?; @@ -1753,7 +1778,13 @@ mod push { 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 refs list: {}...\r\n\r", source_path).as_str())?; + p.expect( + format!( + "fetching ref list over filesystem from {}...\r\n", + source_path + ) + .as_str(), + )?; p.expect("merge commit ")?; // shorthand merge commit id appears in this gap @@ -1897,7 +1928,13 @@ mod push { 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 refs list: {}...\r\n\r", source_path).as_str())?; + p.expect( + format!( + "fetching ref list over filesystem from {}...\r\n", + source_path + ) + .as_str(), + )?; p.expect(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; let output = p.expect_end_eventually()?; @@ -2051,7 +2088,13 @@ mod push { let mut p = CliTester::new_git_with_remote_helper_from_dir(&git_repo.dir, ["push", "--force"]); cli_expect_nostr_fetch(&mut p)?; - p.expect(format!("fetching refs list: {}...\r\n\r", source_path).as_str())?; + p.expect( + format!( + "fetching ref list over filesystem from {}...\r\n", + source_path + ) + .as_str(), + )?; p.expect(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; let output = p.expect_end_eventually()?; @@ -2201,7 +2244,13 @@ mod push { ["push", "-u", "origin", branch_name], ); cli_expect_nostr_fetch(&mut p)?; - p.expect(format!("fetching refs list: {}...\r\n\r", source_path).as_str())?; + p.expect( + format!( + "fetching ref list over filesystem from {}...\r\n", + source_path + ) + .as_str(), + )?; p.expect(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; let output = p.expect_end_eventually()?; -- cgit v1.2.3