diff options
| -rw-r--r-- | src/bin/git_remote_nostr/fetch.rs | 8 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/list.rs | 10 | ||||
| -rw-r--r-- | src/lib/git/nostr_url.rs | 9 | ||||
| -rw-r--r-- | 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( | |||
| 121 | let mut success = false; | 121 | let mut success = false; |
| 122 | for protocol in &protocols_to_attempt { | 122 | for protocol in &protocols_to_attempt { |
| 123 | term.write_line( | 123 | term.write_line( |
| 124 | format!("fetching from {} over {protocol}...", server_url.domain(),).as_str(), | 124 | format!( |
| 125 | "fetching over {protocol} from {}...", | ||
| 126 | server_url.short_name(), | ||
| 127 | ) | ||
| 128 | .as_str(), | ||
| 125 | )?; | 129 | )?; |
| 126 | 130 | ||
| 127 | let formatted_url = server_url.format_as(protocol, &decoded_nostr_url.user)?; | 131 | let formatted_url = server_url.format_as(protocol, &decoded_nostr_url.user)?; |
| @@ -152,7 +156,7 @@ fn fetch_from_git_server( | |||
| 152 | } else { | 156 | } else { |
| 153 | let error = anyhow!( | 157 | let error = anyhow!( |
| 154 | "{} failed over {}{}", | 158 | "{} failed over {}{}", |
| 155 | server_url.domain(), | 159 | server_url.short_name(), |
| 156 | join_with_and(&failed_protocols), | 160 | join_with_and(&failed_protocols), |
| 157 | if decoded_nostr_url.protocol.is_some() { | 161 | if decoded_nostr_url.protocol.is_some() { |
| 158 | " and nostr url contains protocol override so no other protocols were attempted" | 162 | " 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( | |||
| 165 | for protocol in &protocols_to_attempt { | 165 | for protocol in &protocols_to_attempt { |
| 166 | term.write_line( | 166 | term.write_line( |
| 167 | format!( | 167 | format!( |
| 168 | "fetching ref list from {} over {protocol}...", | 168 | "fetching ref list over {protocol} from {}...", |
| 169 | server_url.domain(), | 169 | server_url.short_name(), |
| 170 | ) | 170 | ) |
| 171 | .as_str(), | 171 | .as_str(), |
| 172 | )?; | 172 | )?; |
| @@ -184,8 +184,8 @@ pub fn list_from_remote( | |||
| 184 | if !failed_protocols.is_empty() { | 184 | if !failed_protocols.is_empty() { |
| 185 | term.write_line( | 185 | term.write_line( |
| 186 | format!( | 186 | format!( |
| 187 | "list: succeeded over {protocol} for {}", | 187 | "list: succeeded over {protocol} from {}", |
| 188 | server_url.domain(), | 188 | server_url.short_name(), |
| 189 | ) | 189 | ) |
| 190 | .as_str(), | 190 | .as_str(), |
| 191 | )?; | 191 | )?; |
| @@ -210,7 +210,7 @@ pub fn list_from_remote( | |||
| 210 | } else { | 210 | } else { |
| 211 | let error = anyhow!( | 211 | let error = anyhow!( |
| 212 | "{} failed over {}{}", | 212 | "{} failed over {}{}", |
| 213 | server_url.domain(), | 213 | server_url.short_name(), |
| 214 | join_with_and(&failed_protocols), | 214 | join_with_and(&failed_protocols), |
| 215 | if decoded_nostr_url.protocol.is_some() { | 215 | if decoded_nostr_url.protocol.is_some() { |
| 216 | " and nostr url contains protocol override so no other protocols were attempted" | 216 | " 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 { | |||
| 324 | pub fn protocol(&self) -> ServerProtocol { | 324 | pub fn protocol(&self) -> ServerProtocol { |
| 325 | self.protocol.clone() | 325 | self.protocol.clone() |
| 326 | } | 326 | } |
| 327 | |||
| 328 | pub fn short_name(&self) -> String { | ||
| 329 | let domain = self.domain(); | ||
| 330 | if domain.is_empty() { | ||
| 331 | self.original_string.to_string() | ||
| 332 | } else { | ||
| 333 | domain | ||
| 334 | } | ||
| 335 | } | ||
| 327 | } | 336 | } |
| 328 | 337 | ||
| 329 | fn replace_first_occurrence(s: &str, target: char, replacement: char) -> String { | 338 | 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 { | |||
| 314 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 314 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 315 | let mut p = cli_tester_after_fetch(&git_repo)?; | 315 | let mut p = cli_tester_after_fetch(&git_repo)?; |
| 316 | p.send_line("list")?; | 316 | p.send_line("list")?; |
| 317 | p.expect(format!("fetching refs list: {}...\r\n\r", source_path).as_str())?; | 317 | p.expect( |
| 318 | format!( | ||
| 319 | "fetching ref list over filesystem from {}...\r\n", | ||
| 320 | source_path | ||
| 321 | ) | ||
| 322 | .as_str(), | ||
| 323 | )?; | ||
| 318 | // println!("{}", p.expect_eventually("\r\n\r\n")?); | 324 | // println!("{}", p.expect_eventually("\r\n\r\n")?); |
| 319 | let res = p.expect_eventually("\r\n\r\n")?; | 325 | let res = p.expect_eventually("\r\n\r\n")?; |
| 320 | p.exit()?; | 326 | p.exit()?; |
| @@ -388,7 +394,13 @@ mod list { | |||
| 388 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 394 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 389 | let mut p = cli_tester_after_fetch(&git_repo)?; | 395 | let mut p = cli_tester_after_fetch(&git_repo)?; |
| 390 | p.send_line("list")?; | 396 | p.send_line("list")?; |
| 391 | p.expect(format!("fetching refs list: {}...\r\n\r", source_path).as_str())?; | 397 | p.expect( |
| 398 | format!( | ||
| 399 | "fetching ref list over filesystem from {}...\r\n", | ||
| 400 | source_path | ||
| 401 | ) | ||
| 402 | .as_str(), | ||
| 403 | )?; | ||
| 392 | // println!("{}", p.expect_eventually("\r\n\r\n")?); | 404 | // println!("{}", p.expect_eventually("\r\n\r\n")?); |
| 393 | let res = p.expect_eventually("\r\n\r\n")?; | 405 | let res = p.expect_eventually("\r\n\r\n")?; |
| 394 | p.exit()?; | 406 | p.exit()?; |
| @@ -470,7 +482,13 @@ mod list { | |||
| 470 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { | 482 | let cli_tester_handle = std::thread::spawn(move || -> Result<()> { |
| 471 | let mut p = cli_tester_after_fetch(&git_repo)?; | 483 | let mut p = cli_tester_after_fetch(&git_repo)?; |
| 472 | p.send_line("list")?; | 484 | p.send_line("list")?; |
| 473 | p.expect(format!("fetching refs list: {}...\r\n\r", source_path).as_str())?; | 485 | p.expect( |
| 486 | format!( | ||
| 487 | "fetching ref list over filesystem from {}...\r\n", | ||
| 488 | source_path | ||
| 489 | ) | ||
| 490 | .as_str(), | ||
| 491 | )?; | ||
| 474 | p.expect( | 492 | p.expect( |
| 475 | format!( | 493 | format!( |
| 476 | "WARNING: {} refs/heads/main is out of sync with nostr \r\n", | 494 | "WARNING: {} refs/heads/main is out of sync with nostr \r\n", |
| @@ -552,7 +570,13 @@ mod list { | |||
| 552 | 570 | ||
| 553 | let mut p = cli_tester_after_fetch(&git_repo)?; | 571 | let mut p = cli_tester_after_fetch(&git_repo)?; |
| 554 | p.send_line("list")?; | 572 | p.send_line("list")?; |
| 555 | p.expect(format!("fetching refs list: {}...\r\n\r", source_path).as_str())?; | 573 | p.expect( |
| 574 | format!( | ||
| 575 | "fetching ref list over filesystem from {}...\r\n", | ||
| 576 | source_path | ||
| 577 | ) | ||
| 578 | .as_str(), | ||
| 579 | )?; | ||
| 556 | // println!("{}", p.expect_eventually("\r\n\r\n")?); | 580 | // println!("{}", p.expect_eventually("\r\n\r\n")?); |
| 557 | let res = p.expect_eventually("\r\n\r\n")?; | 581 | let res = p.expect_eventually("\r\n\r\n")?; |
| 558 | 582 | ||
| @@ -659,7 +683,7 @@ mod fetch { | |||
| 659 | p.send_line(format!("fetch {main_commit_id} main").as_str())?; | 683 | p.send_line(format!("fetch {main_commit_id} main").as_str())?; |
| 660 | p.send_line(format!("fetch {vnext_commit_id} vnext").as_str())?; | 684 | p.send_line(format!("fetch {vnext_commit_id} vnext").as_str())?; |
| 661 | p.send_line("")?; | 685 | p.send_line("")?; |
| 662 | p.expect(format!("fetching from {source_path}...\r\n").as_str())?; | 686 | p.expect(format!("fetching over filesystem from {source_path}...\r\n").as_str())?; |
| 663 | p.expect_eventually_and_print("\r\n")?; | 687 | p.expect_eventually_and_print("\r\n")?; |
| 664 | 688 | ||
| 665 | assert!(git_repo.git_repo.find_commit(main_commit_id).is_ok()); | 689 | assert!(git_repo.git_repo.find_commit(main_commit_id).is_ok()); |
| @@ -725,9 +749,10 @@ mod fetch { | |||
| 725 | let mut p = cli_tester_after_fetch(&git_repo)?; | 749 | let mut p = cli_tester_after_fetch(&git_repo)?; |
| 726 | p.send_line(format!("fetch {main_commit_id} main").as_str())?; | 750 | p.send_line(format!("fetch {main_commit_id} main").as_str())?; |
| 727 | p.send_line("")?; | 751 | p.send_line("")?; |
| 728 | p.expect(format!("fetching from {error_path}...\r\n").as_str())?; | 752 | p.expect(format!("fetching over filesystem from {error_path}...\r\n").as_str())?; |
| 729 | // not sure why the below isn't appearing | 753 | // not sure why the below isn't appearing |
| 730 | // p.expect(format!("fetching from {source_path}...\r\n").as_str())?; | 754 | // p.expect(format!("fetching over filesystem from |
| 755 | // {source_path}...\r\n").as_str())?; | ||
| 731 | p.expect_eventually_and_print("\r\n")?; | 756 | p.expect_eventually_and_print("\r\n")?; |
| 732 | // p.expect("\r\n")?; | 757 | // p.expect("\r\n")?; |
| 733 | 758 | ||
| @@ -782,7 +807,7 @@ mod fetch { | |||
| 782 | let mut p = cli_tester_after_fetch(&git_repo)?; | 807 | let mut p = cli_tester_after_fetch(&git_repo)?; |
| 783 | p.send_line(format!("fetch {proposal_tip} refs/heads/{branch_name}").as_str())?; | 808 | p.send_line(format!("fetch {proposal_tip} refs/heads/{branch_name}").as_str())?; |
| 784 | p.send_line("")?; | 809 | p.send_line("")?; |
| 785 | p.expect(format!("fetching from {source_path}...\r\n").as_str())?; | 810 | p.expect(format!("fetching over filesystem from {source_path}...\r\n").as_str())?; |
| 786 | // expect no errors | 811 | // expect no errors |
| 787 | p.expect_after_whitespace("\r\n")?; | 812 | p.expect_after_whitespace("\r\n")?; |
| 788 | p.exit()?; | 813 | p.exit()?; |
| @@ -1753,7 +1778,13 @@ mod push { | |||
| 1753 | 1778 | ||
| 1754 | let mut p = CliTester::new_git_with_remote_helper_from_dir(&git_repo.dir, ["push"]); | 1779 | let mut p = CliTester::new_git_with_remote_helper_from_dir(&git_repo.dir, ["push"]); |
| 1755 | cli_expect_nostr_fetch(&mut p)?; | 1780 | cli_expect_nostr_fetch(&mut p)?; |
| 1756 | p.expect(format!("fetching refs list: {}...\r\n\r", source_path).as_str())?; | 1781 | p.expect( |
| 1782 | format!( | ||
| 1783 | "fetching ref list over filesystem from {}...\r\n", | ||
| 1784 | source_path | ||
| 1785 | ) | ||
| 1786 | .as_str(), | ||
| 1787 | )?; | ||
| 1757 | 1788 | ||
| 1758 | p.expect("merge commit ")?; | 1789 | p.expect("merge commit ")?; |
| 1759 | // shorthand merge commit id appears in this gap | 1790 | // shorthand merge commit id appears in this gap |
| @@ -1897,7 +1928,13 @@ mod push { | |||
| 1897 | 1928 | ||
| 1898 | let mut p = CliTester::new_git_with_remote_helper_from_dir(&git_repo.dir, ["push"]); | 1929 | let mut p = CliTester::new_git_with_remote_helper_from_dir(&git_repo.dir, ["push"]); |
| 1899 | cli_expect_nostr_fetch(&mut p)?; | 1930 | cli_expect_nostr_fetch(&mut p)?; |
| 1900 | p.expect(format!("fetching refs list: {}...\r\n\r", source_path).as_str())?; | 1931 | p.expect( |
| 1932 | format!( | ||
| 1933 | "fetching ref list over filesystem from {}...\r\n", | ||
| 1934 | source_path | ||
| 1935 | ) | ||
| 1936 | .as_str(), | ||
| 1937 | )?; | ||
| 1901 | p.expect(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; | 1938 | p.expect(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; |
| 1902 | let output = p.expect_end_eventually()?; | 1939 | let output = p.expect_end_eventually()?; |
| 1903 | 1940 | ||
| @@ -2051,7 +2088,13 @@ mod push { | |||
| 2051 | let mut p = | 2088 | let mut p = |
| 2052 | CliTester::new_git_with_remote_helper_from_dir(&git_repo.dir, ["push", "--force"]); | 2089 | CliTester::new_git_with_remote_helper_from_dir(&git_repo.dir, ["push", "--force"]); |
| 2053 | cli_expect_nostr_fetch(&mut p)?; | 2090 | cli_expect_nostr_fetch(&mut p)?; |
| 2054 | p.expect(format!("fetching refs list: {}...\r\n\r", source_path).as_str())?; | 2091 | p.expect( |
| 2092 | format!( | ||
| 2093 | "fetching ref list over filesystem from {}...\r\n", | ||
| 2094 | source_path | ||
| 2095 | ) | ||
| 2096 | .as_str(), | ||
| 2097 | )?; | ||
| 2055 | p.expect(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; | 2098 | p.expect(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; |
| 2056 | let output = p.expect_end_eventually()?; | 2099 | let output = p.expect_end_eventually()?; |
| 2057 | 2100 | ||
| @@ -2201,7 +2244,13 @@ mod push { | |||
| 2201 | ["push", "-u", "origin", branch_name], | 2244 | ["push", "-u", "origin", branch_name], |
| 2202 | ); | 2245 | ); |
| 2203 | cli_expect_nostr_fetch(&mut p)?; | 2246 | cli_expect_nostr_fetch(&mut p)?; |
| 2204 | p.expect(format!("fetching refs list: {}...\r\n\r", source_path).as_str())?; | 2247 | p.expect( |
| 2248 | format!( | ||
| 2249 | "fetching ref list over filesystem from {}...\r\n", | ||
| 2250 | source_path | ||
| 2251 | ) | ||
| 2252 | .as_str(), | ||
| 2253 | )?; | ||
| 2205 | p.expect(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; | 2254 | p.expect(format!("To {}\r\n", get_nostr_remote_url()?).as_str())?; |
| 2206 | let output = p.expect_end_eventually()?; | 2255 | let output = p.expect_end_eventually()?; |
| 2207 | 2256 | ||