upleb.uk

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

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/repo_ref.rs4
-rw-r--r--tests/ngit_list.rs51
2 files changed, 37 insertions, 18 deletions
diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs
index b21a4e9..1b25ccf 100644
--- a/src/lib/repo_ref.rs
+++ b/src/lib/repo_ref.rs
@@ -438,15 +438,15 @@ fn set_or_create_git_remote_with_nostr_url(
438 repo_ref: &RepoRef, 438 repo_ref: &RepoRef,
439 git_repo: &Repo, 439 git_repo: &Repo,
440) -> Result<()> { 440) -> Result<()> {
441 let url = repo_ref.to_nostr_git_url();
441 if git_repo 442 if git_repo
442 .git_repo 443 .git_repo
443 .remote_set_url(name, &repo_ref.to_nostr_git_url()) 444 .remote_set_url(name, &repo_ref.to_nostr_git_url())
444 .is_err() 445 .is_err()
445 { 446 {
446 let url = repo_ref.to_nostr_git_url();
447 git_repo.git_repo.remote(name, &url)?; 447 git_repo.git_repo.remote(name, &url)?;
448 eprintln!("set git remote \"{name}\" to {url}");
449 } 448 }
449 eprintln!("set git remote \"{name}\" to {url}");
450 Ok(()) 450 Ok(())
451} 451}
452 452
diff --git a/tests/ngit_list.rs b/tests/ngit_list.rs
index ab6ba22..1d297b6 100644
--- a/tests/ngit_list.rs
+++ b/tests/ngit_list.rs
@@ -76,29 +76,48 @@ mod cannot_find_repo_event {
76 test_repo.populate()?; 76 test_repo.populate()?;
77 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]); 77 let mut p = CliTester::new_from_dir(&test_repo.dir, ["list"]);
78 p.expect( 78 p.expect(
79 "hint: https://gitworkshop.dev/repos lists repositories and their naddr\r\n", 79 "hint: https://gitworkshop.dev/repos lists repositories and their nostr address\r\n",
80 )?; 80 )?;
81 if invalid_input { 81 if invalid_input {
82 let mut input = p.expect_input("repository naddr")?; 82 let mut input = p.expect_input("nostr repository")?;
83 input.succeeds_with("dfgvfvfzadvd")?; 83 input.succeeds_with("dfgvfvfzadvd")?;
84 p.expect("not a valid naddr\r\n")?; 84 p.expect("not a valid naddr or git nostr remote URL starting nostr://\r\n")?;
85 let _ = p.expect_input("repository naddr")?; 85 let _ = p.expect_input("nostr repository")?;
86 p.exit()?; 86 p.exit()?;
87 } 87 }
88 if naddr { 88 if naddr {
89 let mut input = p.expect_input("repository naddr")?; 89 let mut input = p.expect_input("nostr repository")?;
90 input.succeeds_with( 90 let coordinate = Coordinate {
91 &Coordinate { 91 kind: nostr::Kind::GitRepoAnnouncement,
92 kind: nostr::Kind::GitRepoAnnouncement, 92 public_key: TEST_KEY_1_KEYS.public_key(),
93 public_key: TEST_KEY_1_KEYS.public_key(), 93 identifier: repo_event.tags.identifier().unwrap().to_string(),
94 identifier: repo_event.tags.identifier().unwrap().to_string(), 94 relays: vec![RelayUrl::parse("ws://localhost:8056").unwrap()],
95 relays: vec![RelayUrl::parse("ws://localhost:8056").unwrap()], 95 };
96 } 96 input.succeeds_with(&coordinate.to_bech32()?)?;
97 .to_bech32()?, 97 p.expect("searching for repository...\r\n")?;
98 )?; 98 p.expect_eventually("repository found\r\n")?;
99 p.expect_confirm(
100 "set git remote \"origin\" to nostr repository url?",
101 Some(true),
102 )?
103 .succeeds_with(None)?;
104 let nostr_url = format!(
105 "nostr://{}/{}/{}",
106 TEST_KEY_1_NPUB,
107 // first relay in repo ann event
108 urlencoding::encode("ws://localhost:8055"),
109 coordinate.identifier,
110 );
111 p.expect(format!("set git remote \"origin\" to {}\r\n", &nostr_url))?;
99 p.expect("fetching updates...\r\n")?; 112 p.expect("fetching updates...\r\n")?;
100 p.expect_eventually("\r\n")?; // some updates listed here 113 // no updates as they were fetched when searching for repo
114 p.expect("no updates\r\n")?;
101 p.expect_end_with("no proposals found... create one? try `ngit send`\r\n")?; 115 p.expect_end_with("no proposals found... create one? try `ngit send`\r\n")?;
116
117 assert_eq!(
118 test_repo.git_repo.find_remote("origin")?.url().unwrap(),
119 nostr_url
120 );
102 } 121 }
103 122
104 for p in [51, 52, 53, 55, 56] { 123 for p in [51, 52, 53, 55, 56] {
@@ -127,7 +146,7 @@ mod cannot_find_repo_event {
127 146
128 #[tokio::test] 147 #[tokio::test]
129 #[serial] 148 #[serial]
130 async fn finds_based_on_naddr_on_embeded_relay() -> Result<()> { 149 async fn finds_based_on_naddr_on_embeded_relay_and_added_as_origin_remote() -> Result<()> {
131 run_async_repo_event_ref_needed(false, true).await 150 run_async_repo_event_ref_needed(false, true).await
132 } 151 }
133 } 152 }