diff options
| -rw-r--r-- | src/bin/git_remote_nostr/fetch.rs | 8 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/list.rs | 24 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/push.rs | 24 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/utils.rs | 8 | ||||
| -rw-r--r-- | src/bin/ngit/sub_commands/init.rs | 91 | ||||
| -rw-r--r-- | src/lib/repo_ref.rs | 41 |
6 files changed, 100 insertions, 96 deletions
diff --git a/src/bin/git_remote_nostr/fetch.rs b/src/bin/git_remote_nostr/fetch.rs index adc68b3..b191850 100644 --- a/src/bin/git_remote_nostr/fetch.rs +++ b/src/bin/git_remote_nostr/fetch.rs | |||
| @@ -18,7 +18,7 @@ use ngit::{ | |||
| 18 | }, | 18 | }, |
| 19 | git_events::tag_value, | 19 | git_events::tag_value, |
| 20 | login::get_curent_user, | 20 | login::get_curent_user, |
| 21 | repo_ref::{RepoRef, is_ngit_relay}, | 21 | repo_ref::{RepoRef, is_grasp_server}, |
| 22 | }; | 22 | }; |
| 23 | use nostr::nips::nip19; | 23 | use nostr::nips::nip19; |
| 24 | use nostr_sdk::{Event, ToBech32}; | 24 | use nostr_sdk::{Event, ToBech32}; |
| @@ -54,7 +54,7 @@ pub async fn run_fetch( | |||
| 54 | git_server_url, | 54 | git_server_url, |
| 55 | &repo_ref.to_nostr_git_url(&None), | 55 | &repo_ref.to_nostr_git_url(&None), |
| 56 | &term, | 56 | &term, |
| 57 | is_ngit_relay(git_server_url, &repo_ref.ngit_relays()), | 57 | is_grasp_server(git_server_url, &repo_ref.grasp_servers()), |
| 58 | ) { | 58 | ) { |
| 59 | errors.push(error); | 59 | errors.push(error); |
| 60 | } else { | 60 | } else { |
| @@ -164,7 +164,7 @@ pub fn fetch_from_git_server( | |||
| 164 | git_server_url: &str, | 164 | git_server_url: &str, |
| 165 | decoded_nostr_url: &NostrUrlDecoded, | 165 | decoded_nostr_url: &NostrUrlDecoded, |
| 166 | term: &console::Term, | 166 | term: &console::Term, |
| 167 | is_ngit_relay: bool, | 167 | is_grasp_server: bool, |
| 168 | ) -> Result<()> { | 168 | ) -> Result<()> { |
| 169 | let already_have_oids = oids | 169 | let already_have_oids = oids |
| 170 | .iter() | 170 | .iter() |
| @@ -176,7 +176,7 @@ pub fn fetch_from_git_server( | |||
| 176 | let server_url = git_server_url.parse::<CloneUrl>()?; | 176 | let server_url = git_server_url.parse::<CloneUrl>()?; |
| 177 | 177 | ||
| 178 | let protocols_to_attempt = | 178 | let protocols_to_attempt = |
| 179 | get_read_protocols_to_try(git_repo, &server_url, decoded_nostr_url, is_ngit_relay); | 179 | get_read_protocols_to_try(git_repo, &server_url, decoded_nostr_url, is_grasp_server); |
| 180 | 180 | ||
| 181 | let mut failed_protocols = vec![]; | 181 | let mut failed_protocols = vec![]; |
| 182 | let mut success = false; | 182 | let mut success = false; |
diff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs index c27e4d2..b9fb0c0 100644 --- a/src/bin/git_remote_nostr/list.rs +++ b/src/bin/git_remote_nostr/list.rs | |||
| @@ -13,7 +13,7 @@ use ngit::{ | |||
| 13 | }, | 13 | }, |
| 14 | git_events::event_to_cover_letter, | 14 | git_events::event_to_cover_letter, |
| 15 | login::get_curent_user, | 15 | login::get_curent_user, |
| 16 | repo_ref::{self, is_ngit_relay}, | 16 | repo_ref::{self, is_grasp_server}, |
| 17 | }; | 17 | }; |
| 18 | use nostr_sdk::hashes::sha1::Hash as Sha1Hash; | 18 | use nostr_sdk::hashes::sha1::Hash as Sha1Hash; |
| 19 | use repo_ref::RepoRef; | 19 | use repo_ref::RepoRef; |
| @@ -41,12 +41,12 @@ pub async fn run_list( | |||
| 41 | git_repo, | 41 | git_repo, |
| 42 | &repo_ref.git_server, | 42 | &repo_ref.git_server, |
| 43 | &repo_ref.to_nostr_git_url(&None), | 43 | &repo_ref.to_nostr_git_url(&None), |
| 44 | &repo_ref.ngit_relays(), | 44 | &repo_ref.grasp_servers(), |
| 45 | ); | 45 | ); |
| 46 | 46 | ||
| 47 | let mut state = if let Some(nostr_state) = nostr_state { | 47 | let mut state = if let Some(nostr_state) = nostr_state { |
| 48 | for (name, value) in &nostr_state.state { | 48 | for (name, value) in &nostr_state.state { |
| 49 | for (url, (remote_state, _is_ngit_relay)) in &remote_states { | 49 | for (url, (remote_state, _is_grasp_server)) in &remote_states { |
| 50 | let remote_name = get_short_git_server_name(git_repo, url); | 50 | let remote_name = get_short_git_server_name(git_repo, url); |
| 51 | if let Some(remote_value) = remote_state.get(name) { | 51 | if let Some(remote_value) = remote_state.get(name) { |
| 52 | if value.ne(remote_value) { | 52 | if value.ne(remote_value) { |
| @@ -74,7 +74,7 @@ pub async fn run_list( | |||
| 74 | } | 74 | } |
| 75 | nostr_state.state | 75 | nostr_state.state |
| 76 | } else { | 76 | } else { |
| 77 | let (state, _is_ngit_relay) = repo_ref | 77 | let (state, _is_grasp_server) = repo_ref |
| 78 | .git_server | 78 | .git_server |
| 79 | .iter() | 79 | .iter() |
| 80 | .filter_map(|server| remote_states.get(server)) | 80 | .filter_map(|server| remote_states.get(server)) |
| @@ -122,7 +122,7 @@ async fn get_open_and_draft_proposals_state( | |||
| 122 | 122 | ||
| 123 | // without trusting commit_id we must apply each patch which requires the oid of | 123 | // without trusting commit_id we must apply each patch which requires the oid of |
| 124 | // the parent so we much do a fetch | 124 | // the parent so we much do a fetch |
| 125 | for (git_server_url, (oids_from_git_servers, is_ngit_relay)) in remote_states { | 125 | for (git_server_url, (oids_from_git_servers, is_grasp_server)) in remote_states { |
| 126 | if fetch_from_git_server( | 126 | if fetch_from_git_server( |
| 127 | git_repo, | 127 | git_repo, |
| 128 | &oids_from_git_servers | 128 | &oids_from_git_servers |
| @@ -133,7 +133,7 @@ async fn get_open_and_draft_proposals_state( | |||
| 133 | git_server_url, | 133 | git_server_url, |
| 134 | &repo_ref.to_nostr_git_url(&None), | 134 | &repo_ref.to_nostr_git_url(&None), |
| 135 | term, | 135 | term, |
| 136 | *is_ngit_relay, | 136 | *is_grasp_server, |
| 137 | ) | 137 | ) |
| 138 | .is_ok() | 138 | .is_ok() |
| 139 | { | 139 | { |
| @@ -178,18 +178,18 @@ pub fn list_from_remotes( | |||
| 178 | git_repo: &Repo, | 178 | git_repo: &Repo, |
| 179 | git_servers: &Vec<String>, | 179 | git_servers: &Vec<String>, |
| 180 | decoded_nostr_url: &NostrUrlDecoded, | 180 | decoded_nostr_url: &NostrUrlDecoded, |
| 181 | ngit_relays: &[String], | 181 | grasp_servers: &[String], |
| 182 | ) -> HashMap<String, (HashMap<String, String>, bool)> { | 182 | ) -> HashMap<String, (HashMap<String, String>, bool)> { |
| 183 | let mut remote_states = HashMap::new(); | 183 | let mut remote_states = HashMap::new(); |
| 184 | let mut errors = HashMap::new(); | 184 | let mut errors = HashMap::new(); |
| 185 | for url in git_servers { | 185 | for url in git_servers { |
| 186 | let is_ngit_relay = is_ngit_relay(url, ngit_relays); | 186 | let is_grasp_server = is_grasp_server(url, grasp_servers); |
| 187 | match list_from_remote(term, git_repo, url, decoded_nostr_url, is_ngit_relay) { | 187 | match list_from_remote(term, git_repo, url, decoded_nostr_url, is_grasp_server) { |
| 188 | Err(error) => { | 188 | Err(error) => { |
| 189 | errors.insert(url, error); | 189 | errors.insert(url, error); |
| 190 | } | 190 | } |
| 191 | Ok(state) => { | 191 | Ok(state) => { |
| 192 | remote_states.insert(url.to_string(), (state, is_ngit_relay)); | 192 | remote_states.insert(url.to_string(), (state, is_grasp_server)); |
| 193 | } | 193 | } |
| 194 | } | 194 | } |
| 195 | } | 195 | } |
| @@ -201,11 +201,11 @@ pub fn list_from_remote( | |||
| 201 | git_repo: &Repo, | 201 | git_repo: &Repo, |
| 202 | git_server_url: &str, | 202 | git_server_url: &str, |
| 203 | decoded_nostr_url: &NostrUrlDecoded, | 203 | decoded_nostr_url: &NostrUrlDecoded, |
| 204 | is_ngit_relay: bool, | 204 | is_grasp_server: bool, |
| 205 | ) -> Result<HashMap<String, String>> { | 205 | ) -> Result<HashMap<String, String>> { |
| 206 | let server_url = git_server_url.parse::<CloneUrl>()?; | 206 | let server_url = git_server_url.parse::<CloneUrl>()?; |
| 207 | let protocols_to_attempt = | 207 | let protocols_to_attempt = |
| 208 | get_read_protocols_to_try(git_repo, &server_url, decoded_nostr_url, is_ngit_relay); | 208 | get_read_protocols_to_try(git_repo, &server_url, decoded_nostr_url, is_grasp_server); |
| 209 | 209 | ||
| 210 | let mut failed_protocols = vec![]; | 210 | let mut failed_protocols = vec![]; |
| 211 | let mut remote_state: Option<HashMap<String, String>> = None; | 211 | let mut remote_state: Option<HashMap<String, String>> = None; |
diff --git a/src/bin/git_remote_nostr/push.rs b/src/bin/git_remote_nostr/push.rs index 9e54ca7..04fc4d8 100644 --- a/src/bin/git_remote_nostr/push.rs +++ b/src/bin/git_remote_nostr/push.rs | |||
| @@ -25,7 +25,7 @@ use ngit::{ | |||
| 25 | }, | 25 | }, |
| 26 | git_events::{self, event_to_cover_letter, get_event_root}, | 26 | git_events::{self, event_to_cover_letter, get_event_root}, |
| 27 | login::{self, user::UserRef}, | 27 | login::{self, user::UserRef}, |
| 28 | repo_ref::{self, get_repo_config_from_yaml, is_ngit_relay}, | 28 | repo_ref::{self, get_repo_config_from_yaml, is_grasp_server}, |
| 29 | repo_state, | 29 | repo_state, |
| 30 | }; | 30 | }; |
| 31 | use nostr::nips::nip10::Marker; | 31 | use nostr::nips::nip10::Marker; |
| @@ -79,7 +79,7 @@ pub async fn run_push( | |||
| 79 | git_repo, | 79 | git_repo, |
| 80 | &repo_ref.git_server, | 80 | &repo_ref.git_server, |
| 81 | &repo_ref.to_nostr_git_url(&None), | 81 | &repo_ref.to_nostr_git_url(&None), |
| 82 | &repo_ref.ngit_relays(), | 82 | &repo_ref.grasp_servers(), |
| 83 | ) | 83 | ) |
| 84 | }); | 84 | }); |
| 85 | 85 | ||
| @@ -92,7 +92,7 @@ pub async fn run_push( | |||
| 92 | .iter() | 92 | .iter() |
| 93 | .find(|&url| list_outputs.contains_key(url)) | 93 | .find(|&url| list_outputs.contains_key(url)) |
| 94 | { | 94 | { |
| 95 | let (state, _is_ngit_relay) = list_outputs.get(url).unwrap().to_owned(); | 95 | let (state, _is_grasp_server) = list_outputs.get(url).unwrap().to_owned(); |
| 96 | state | 96 | state |
| 97 | } else { | 97 | } else { |
| 98 | bail!( | 98 | bail!( |
| @@ -163,7 +163,7 @@ pub async fn run_push( | |||
| 163 | &repo_ref.to_nostr_git_url(&None), | 163 | &repo_ref.to_nostr_git_url(&None), |
| 164 | &remote_refspecs, | 164 | &remote_refspecs, |
| 165 | &term, | 165 | &term, |
| 166 | is_ngit_relay(&git_server_url, &repo_ref.ngit_relays()), | 166 | is_grasp_server(&git_server_url, &repo_ref.grasp_servers()), |
| 167 | ); | 167 | ); |
| 168 | } | 168 | } |
| 169 | } | 169 | } |
| @@ -429,11 +429,11 @@ fn push_to_remote( | |||
| 429 | decoded_nostr_url: &NostrUrlDecoded, | 429 | decoded_nostr_url: &NostrUrlDecoded, |
| 430 | remote_refspecs: &[String], | 430 | remote_refspecs: &[String], |
| 431 | term: &Term, | 431 | term: &Term, |
| 432 | is_ngit_relay: bool, | 432 | is_grasp_server: bool, |
| 433 | ) -> Result<()> { | 433 | ) -> Result<()> { |
| 434 | let server_url = git_server_url.parse::<CloneUrl>()?; | 434 | let server_url = git_server_url.parse::<CloneUrl>()?; |
| 435 | let protocols_to_attempt = | 435 | let protocols_to_attempt = |
| 436 | get_write_protocols_to_try(git_repo, &server_url, decoded_nostr_url, is_ngit_relay); | 436 | get_write_protocols_to_try(git_repo, &server_url, decoded_nostr_url, is_grasp_server); |
| 437 | 437 | ||
| 438 | let mut failed_protocols = vec![]; | 438 | let mut failed_protocols = vec![]; |
| 439 | let mut success = false; | 439 | let mut success = false; |
| @@ -726,8 +726,8 @@ fn create_rejected_refspecs_and_remotes_refspecs( | |||
| 726 | 726 | ||
| 727 | let mut rejected_refspecs: HashMapUrlRefspecs = HashMap::new(); | 727 | let mut rejected_refspecs: HashMapUrlRefspecs = HashMap::new(); |
| 728 | 728 | ||
| 729 | for (url, (remote_state, is_ngit_relay)) in list_outputs { | 729 | for (url, (remote_state, is_grasp_server)) in list_outputs { |
| 730 | let is_ngit_relay = is_ngit_relay.to_owned(); | 730 | let is_grasp_server = is_grasp_server.to_owned(); |
| 731 | let short_name = get_short_git_server_name(git_repo, url); | 731 | let short_name = get_short_git_server_name(git_repo, url); |
| 732 | let mut refspecs_for_remote = vec![]; | 732 | let mut refspecs_for_remote = vec![]; |
| 733 | for refspec in refspecs { | 733 | for refspec in refspecs { |
| @@ -788,7 +788,7 @@ fn create_rejected_refspecs_and_remotes_refspecs( | |||
| 788 | if ahead_of_nostr.is_empty() { | 788 | if ahead_of_nostr.is_empty() { |
| 789 | // ancestor of nostr and we are force pushing anyway... | 789 | // ancestor of nostr and we are force pushing anyway... |
| 790 | refspecs_for_remote.push(refspec.clone()); | 790 | refspecs_for_remote.push(refspec.clone()); |
| 791 | } else if is_ngit_relay { | 791 | } else if is_grasp_server { |
| 792 | // a grasp server can only be pushed to via nostr so can force push | 792 | // a grasp server can only be pushed to via nostr so can force push |
| 793 | refspecs_for_remote.push(ensure_force_push_refspec(refspec)); | 793 | refspecs_for_remote.push(ensure_force_push_refspec(refspec)); |
| 794 | } else { | 794 | } else { |
| @@ -807,7 +807,7 @@ fn create_rejected_refspecs_and_remotes_refspecs( | |||
| 807 | )?; | 807 | )?; |
| 808 | } | 808 | } |
| 809 | } | 809 | } |
| 810 | } else if is_ngit_relay { | 810 | } else if is_grasp_server { |
| 811 | refspecs_for_remote.push(ensure_force_push_refspec(refspec)); | 811 | refspecs_for_remote.push(ensure_force_push_refspec(refspec)); |
| 812 | } else { | 812 | } else { |
| 813 | // remote_value oid is not present locally | 813 | // remote_value oid is not present locally |
| @@ -842,7 +842,7 @@ fn create_rejected_refspecs_and_remotes_refspecs( | |||
| 842 | if ahead.is_empty() { | 842 | if ahead.is_empty() { |
| 843 | // can soft push | 843 | // can soft push |
| 844 | refspecs_for_remote.push(refspec.clone()); | 844 | refspecs_for_remote.push(refspec.clone()); |
| 845 | } else if is_ngit_relay { | 845 | } else if is_grasp_server { |
| 846 | refspecs_for_remote.push(ensure_force_push_refspec(refspec)); | 846 | refspecs_for_remote.push(ensure_force_push_refspec(refspec)); |
| 847 | } else { | 847 | } else { |
| 848 | // cant soft push | 848 | // cant soft push |
| @@ -858,7 +858,7 @@ fn create_rejected_refspecs_and_remotes_refspecs( | |||
| 858 | ).as_str(), | 858 | ).as_str(), |
| 859 | )?; | 859 | )?; |
| 860 | } | 860 | } |
| 861 | } else if is_ngit_relay { | 861 | } else if is_grasp_server { |
| 862 | refspecs_for_remote.push(ensure_force_push_refspec(refspec)); | 862 | refspecs_for_remote.push(ensure_force_push_refspec(refspec)); |
| 863 | } else { | 863 | } else { |
| 864 | // havn't fetched oid from remote | 864 | // havn't fetched oid from remote |
diff --git a/src/bin/git_remote_nostr/utils.rs b/src/bin/git_remote_nostr/utils.rs index ec6412b..f7e688e 100644 --- a/src/bin/git_remote_nostr/utils.rs +++ b/src/bin/git_remote_nostr/utils.rs | |||
| @@ -216,9 +216,9 @@ pub fn get_read_protocols_to_try( | |||
| 216 | git_repo: &Repo, | 216 | git_repo: &Repo, |
| 217 | server_url: &CloneUrl, | 217 | server_url: &CloneUrl, |
| 218 | decoded_nostr_url: &NostrUrlDecoded, | 218 | decoded_nostr_url: &NostrUrlDecoded, |
| 219 | is_ngit_relay: bool, | 219 | is_grasp_server: bool, |
| 220 | ) -> Vec<ServerProtocol> { | 220 | ) -> Vec<ServerProtocol> { |
| 221 | if is_ngit_relay { | 221 | if is_grasp_server { |
| 222 | if server_url.protocol() == ServerProtocol::Http { | 222 | if server_url.protocol() == ServerProtocol::Http { |
| 223 | vec![(ServerProtocol::UnauthHttp)] | 223 | vec![(ServerProtocol::UnauthHttp)] |
| 224 | } else { | 224 | } else { |
| @@ -269,9 +269,9 @@ pub fn get_write_protocols_to_try( | |||
| 269 | git_repo: &Repo, | 269 | git_repo: &Repo, |
| 270 | server_url: &CloneUrl, | 270 | server_url: &CloneUrl, |
| 271 | decoded_nostr_url: &NostrUrlDecoded, | 271 | decoded_nostr_url: &NostrUrlDecoded, |
| 272 | is_ngit_relay: bool, | 272 | is_grasp_server: bool, |
| 273 | ) -> Vec<ServerProtocol> { | 273 | ) -> Vec<ServerProtocol> { |
| 274 | if is_ngit_relay { | 274 | if is_grasp_server { |
| 275 | if server_url.protocol() == ServerProtocol::Http { | 275 | if server_url.protocol() == ServerProtocol::Http { |
| 276 | vec![(ServerProtocol::UnauthHttp)] | 276 | vec![(ServerProtocol::UnauthHttp)] |
| 277 | } else { | 277 | } else { |
diff --git a/src/bin/ngit/sub_commands/init.rs b/src/bin/ngit/sub_commands/init.rs index 7e095a3..1242e45 100644 --- a/src/bin/ngit/sub_commands/init.rs +++ b/src/bin/ngit/sub_commands/init.rs | |||
| @@ -16,7 +16,7 @@ use ngit::{ | |||
| 16 | client::{Params, send_events}, | 16 | client::{Params, send_events}, |
| 17 | git::nostr_url::{CloneUrl, NostrUrlDecoded}, | 17 | git::nostr_url::{CloneUrl, NostrUrlDecoded}, |
| 18 | repo_ref::{ | 18 | repo_ref::{ |
| 19 | detect_existing_ngit_relays, extract_npub, extract_pks, normalize_ngit_relay_url, | 19 | detect_existing_grasp_servers, extract_npub, extract_pks, normalize_grasp_server_url, |
| 20 | save_repo_config_to_yaml, | 20 | save_repo_config_to_yaml, |
| 21 | }, | 21 | }, |
| 22 | }; | 22 | }; |
| @@ -252,20 +252,20 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 252 | args.blossoms.clone() | 252 | args.blossoms.clone() |
| 253 | }; | 253 | }; |
| 254 | 254 | ||
| 255 | let fallback_ngit_relays = | 255 | let fallback_grasp_servers = |
| 256 | if let Ok(Some(s)) = git_repo.get_git_config_item("nostr.grasp-default-set", None) { | 256 | if let Ok(Some(s)) = git_repo.get_git_config_item("nostr.grasp-default-set", None) { |
| 257 | s.split(';') | 257 | s.split(';') |
| 258 | .filter_map(|url| normalize_ngit_relay_url(url).ok()) // Attempt to parse and filter out errors | 258 | .filter_map(|url| normalize_grasp_server_url(url).ok()) // Attempt to parse and filter out errors |
| 259 | .collect() | 259 | .collect() |
| 260 | } else { | 260 | } else { |
| 261 | vec!["relay.ngit.dev".to_string(), "gitnostr.com".to_string()] | 261 | vec!["relay.ngit.dev".to_string(), "gitnostr.com".to_string()] |
| 262 | }; | 262 | }; |
| 263 | 263 | ||
| 264 | let selected_ngit_relays = if has_server_and_relay_flags { | 264 | let selected_grasp_servers = if has_server_and_relay_flags { |
| 265 | // ignore so a script running `ngit init` can contiue without prompts | 265 | // ignore so a script running `ngit init` can contiue without prompts |
| 266 | vec![] | 266 | vec![] |
| 267 | } else { | 267 | } else { |
| 268 | let mut options: Vec<String> = detect_existing_ngit_relays( | 268 | let mut options: Vec<String> = detect_existing_grasp_servers( |
| 269 | repo_ref.as_ref(), | 269 | repo_ref.as_ref(), |
| 270 | &args.relays, | 270 | &args.relays, |
| 271 | &args.clone_url, | 271 | &args.clone_url, |
| @@ -274,7 +274,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 274 | ); | 274 | ); |
| 275 | let mut selections: Vec<bool> = vec![true; options.len()]; // Initialize selections based on existing options | 275 | let mut selections: Vec<bool> = vec![true; options.len()]; // Initialize selections based on existing options |
| 276 | let empty = options.is_empty(); | 276 | let empty = options.is_empty(); |
| 277 | for fallback in fallback_ngit_relays { | 277 | for fallback in fallback_grasp_servers { |
| 278 | // Check if any option contains the fallback as a substring | 278 | // Check if any option contains the fallback as a substring |
| 279 | if !options.iter().any(|option| option.contains(&fallback)) { | 279 | if !options.iter().any(|option| option.contains(&fallback)) { |
| 280 | options.push(fallback.clone()); // Add fallback if not found | 280 | options.push(fallback.clone()); // Add fallback if not found |
| @@ -286,22 +286,25 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 286 | "grasp server", | 286 | "grasp server", |
| 287 | options, | 287 | options, |
| 288 | selections, | 288 | selections, |
| 289 | normalize_ngit_relay_url, | 289 | normalize_grasp_server_url, |
| 290 | )?; | 290 | )?; |
| 291 | show_multi_input_prompt_success("grasp servers", &selected); | 291 | show_multi_input_prompt_success("grasp servers", &selected); |
| 292 | selected | 292 | selected |
| 293 | }; | 293 | }; |
| 294 | 294 | ||
| 295 | // ensure ngit relays are added as git server, relay and blossom entries | 295 | // ensure ngit relays are added as git server, relay and blossom entries |
| 296 | for ngit_relay in &selected_ngit_relays { | 296 | for grasp_server in &selected_grasp_servers { |
| 297 | if args.clone_url.is_empty() { | 297 | if args.clone_url.is_empty() { |
| 298 | let clone_url = | 298 | let clone_url = format_grasp_server_url_as_clone_url( |
| 299 | format_ngit_relay_url_as_clone_url(ngit_relay, &user_ref.public_key, &identifier)?; | 299 | grasp_server, |
| 300 | &user_ref.public_key, | ||
| 301 | &identifier, | ||
| 302 | )?; | ||
| 300 | 303 | ||
| 301 | let ngit_relay_clone_root = if clone_url.contains("https://") { | 304 | let grasp_server_clone_root = if clone_url.contains("https://") { |
| 302 | format!("https://{ngit_relay}") | 305 | format!("https://{grasp_server}") |
| 303 | } else { | 306 | } else { |
| 304 | ngit_relay.to_string() | 307 | grasp_server.to_string() |
| 305 | }; | 308 | }; |
| 306 | 309 | ||
| 307 | // Find all positions of entries containing the relay root | 310 | // Find all positions of entries containing the relay root |
| @@ -309,7 +312,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 309 | .iter() | 312 | .iter() |
| 310 | .enumerate() | 313 | .enumerate() |
| 311 | .filter_map(|(idx, url)| { | 314 | .filter_map(|(idx, url)| { |
| 312 | if url.contains(&ngit_relay_clone_root) { | 315 | if url.contains(&grasp_server_clone_root) { |
| 313 | Some(idx) | 316 | Some(idx) |
| 314 | } else { | 317 | } else { |
| 315 | None | 318 | None |
| @@ -332,13 +335,13 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 332 | } | 335 | } |
| 333 | } | 336 | } |
| 334 | if args.relays.is_empty() { | 337 | if args.relays.is_empty() { |
| 335 | let relay_url = format_ngit_relay_url_as_relay_url(ngit_relay)?; | 338 | let relay_url = format_grasp_server_url_as_relay_url(grasp_server)?; |
| 336 | if !relay_defaults.contains(&relay_url) { | 339 | if !relay_defaults.contains(&relay_url) { |
| 337 | relay_defaults.push(relay_url); | 340 | relay_defaults.push(relay_url); |
| 338 | } | 341 | } |
| 339 | } | 342 | } |
| 340 | if args.blossoms.is_empty() { | 343 | if args.blossoms.is_empty() { |
| 341 | let blossom = format_ngit_relay_url_as_blossom_url(ngit_relay)?; | 344 | let blossom = format_grasp_server_url_as_blossom_url(grasp_server)?; |
| 342 | if !blossoms_defaults.contains(&blossom) { | 345 | if !blossoms_defaults.contains(&blossom) { |
| 343 | blossoms_defaults.push(blossom); | 346 | blossoms_defaults.push(blossom); |
| 344 | } | 347 | } |
| @@ -370,18 +373,18 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 370 | } | 373 | } |
| 371 | 374 | ||
| 372 | let git_server = if args.clone_url.is_empty() { | 375 | let git_server = if args.clone_url.is_empty() { |
| 373 | let ngit_relay_git_servers: Vec<String> = git_server_defaults | 376 | let grasp_server_git_servers: Vec<String> = git_server_defaults |
| 374 | .iter() | 377 | .iter() |
| 375 | .filter(|s| selected_ngit_relays.iter().any(|r| s.contains(r))) | 378 | .filter(|s| selected_grasp_servers.iter().any(|r| s.contains(r))) |
| 376 | .cloned() | 379 | .cloned() |
| 377 | .collect(); | 380 | .collect(); |
| 378 | let mut additional_server_options: Vec<String> = git_server_defaults | 381 | let mut additional_server_options: Vec<String> = git_server_defaults |
| 379 | .iter() | 382 | .iter() |
| 380 | .filter(|s| ngit_relay_git_servers.iter().any(|r| s.eq(&r))) | 383 | .filter(|s| grasp_server_git_servers.iter().any(|r| s.eq(&r))) |
| 381 | .cloned() | 384 | .cloned() |
| 382 | .collect(); | 385 | .collect(); |
| 383 | 386 | ||
| 384 | if simple_mode && !selected_ngit_relays.is_empty() { | 387 | if simple_mode && !selected_grasp_servers.is_empty() { |
| 385 | if additional_server_options.is_empty() { | 388 | if additional_server_options.is_empty() { |
| 386 | // additional git servers were listed | 389 | // additional git servers were listed |
| 387 | let selected = loop { | 390 | let selected = loop { |
| @@ -414,7 +417,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 414 | break selected; | 417 | break selected; |
| 415 | }; | 418 | }; |
| 416 | show_multi_input_prompt_success("git servers", &selected); | 419 | show_multi_input_prompt_success("git servers", &selected); |
| 417 | let mut combined = ngit_relay_git_servers; | 420 | let mut combined = grasp_server_git_servers; |
| 418 | combined.extend(selected); | 421 | combined.extend(selected); |
| 419 | combined | 422 | combined |
| 420 | } else { | 423 | } else { |
| @@ -444,14 +447,14 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 444 | 447 | ||
| 445 | let relays: Vec<RelayUrl> = { | 448 | let relays: Vec<RelayUrl> = { |
| 446 | if simple_mode { | 449 | if simple_mode { |
| 447 | let formatted_selected_ngit_relays: Vec<String> = selected_ngit_relays | 450 | let formatted_selected_grasp_servers: Vec<String> = selected_grasp_servers |
| 448 | .iter() | 451 | .iter() |
| 449 | .filter_map(|r| format_ngit_relay_url_as_relay_url(r).ok()) | 452 | .filter_map(|r| format_grasp_server_url_as_relay_url(r).ok()) |
| 450 | .collect(); | 453 | .collect(); |
| 451 | let mut options: Vec<String> = relay_defaults | 454 | let mut options: Vec<String> = relay_defaults |
| 452 | .iter() | 455 | .iter() |
| 453 | .filter(|s| { | 456 | .filter(|s| { |
| 454 | !formatted_selected_ngit_relays | 457 | !formatted_selected_grasp_servers |
| 455 | .iter() | 458 | .iter() |
| 456 | .any(|r| s.as_str() == r) | 459 | .any(|r| s.as_str() == r) |
| 457 | }) | 460 | }) |
| @@ -463,7 +466,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 463 | // add fallback relays as options | 466 | // add fallback relays as options |
| 464 | for relay in client.get_fallback_relays().clone() { | 467 | for relay in client.get_fallback_relays().clone() { |
| 465 | if !options.iter().any(|r| r.contains(&relay)) | 468 | if !options.iter().any(|r| r.contains(&relay)) |
| 466 | && !formatted_selected_ngit_relays | 469 | && !formatted_selected_grasp_servers |
| 467 | .iter() | 470 | .iter() |
| 468 | .any(|r| relay.contains(r)) | 471 | .any(|r| relay.contains(r)) |
| 469 | { | 472 | { |
| @@ -485,7 +488,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 485 | )?; | 488 | )?; |
| 486 | show_multi_input_prompt_success("additional nostr relays", &selected); | 489 | show_multi_input_prompt_success("additional nostr relays", &selected); |
| 487 | [ | 490 | [ |
| 488 | formatted_selected_ngit_relays | 491 | formatted_selected_grasp_servers |
| 489 | .iter() | 492 | .iter() |
| 490 | .filter_map(|r| parse_relay_url(r).ok()) | 493 | .filter_map(|r| parse_relay_url(r).ok()) |
| 491 | .collect::<Vec<RelayUrl>>(), | 494 | .collect::<Vec<RelayUrl>>(), |
| @@ -538,7 +541,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 538 | blossoms_defaults, | 541 | blossoms_defaults, |
| 539 | selections, | 542 | selections, |
| 540 | |s| { | 543 | |s| { |
| 541 | format_ngit_relay_url_as_blossom_url(s) | 544 | format_grasp_server_url_as_blossom_url(s) |
| 542 | .context(format!("Invalid blossom URL format: {s}")) | 545 | .context(format!("Invalid blossom URL format: {s}")) |
| 543 | }, | 546 | }, |
| 544 | )?; | 547 | )?; |
| @@ -616,7 +619,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 616 | default_maintainers | 619 | default_maintainers |
| 617 | }; | 620 | }; |
| 618 | 621 | ||
| 619 | if selected_ngit_relays.is_empty() && git_server.iter().any(|s| s.contains("github.com") || s.contains("codeberg.org")) && Interactor::default().confirm( | 622 | if selected_grasp_servers.is_empty() && git_server.iter().any(|s| s.contains("github.com") || s.contains("codeberg.org")) && Interactor::default().confirm( |
| 620 | PromptConfirmParms::default() | 623 | PromptConfirmParms::default() |
| 621 | .with_prompt("you have listed github / codeberg. Are you or other maintainers planning on pushing directly to github / codeberg rather than using your shiny new nostr clone url which will do this for you?") | 624 | .with_prompt("you have listed github / codeberg. Are you or other maintainers planning on pushing directly to github / codeberg rather than using your shiny new nostr clone url which will do this for you?") |
| 622 | .with_default(false), | 625 | .with_default(false), |
| @@ -782,7 +785,7 @@ pub async fn launch(cli_args: &Cli, args: &SubCommandArgs) -> Result<()> { | |||
| 782 | // ignore during tests as git-remote-nostr isn't installed during ngit binary | 785 | // ignore during tests as git-remote-nostr isn't installed during ngit binary |
| 783 | // tests | 786 | // tests |
| 784 | 787 | ||
| 785 | if selected_ngit_relays.is_empty() { | 788 | if selected_grasp_servers.is_empty() { |
| 786 | println!("running `git push` to publish your repository data"); | 789 | println!("running `git push` to publish your repository data"); |
| 787 | } else { | 790 | } else { |
| 788 | let countdown_start = 5; | 791 | let countdown_start = 5; |
| @@ -940,38 +943,38 @@ where | |||
| 940 | Ok(selected_choices) | 943 | Ok(selected_choices) |
| 941 | } | 944 | } |
| 942 | 945 | ||
| 943 | fn format_ngit_relay_url_as_clone_url( | 946 | fn format_grasp_server_url_as_clone_url( |
| 944 | url: &str, | 947 | url: &str, |
| 945 | public_key: &PublicKey, | 948 | public_key: &PublicKey, |
| 946 | identifier: &str, | 949 | identifier: &str, |
| 947 | ) -> Result<String> { | 950 | ) -> Result<String> { |
| 948 | let ngit_relay_url = normalize_ngit_relay_url(url)?; | 951 | let grasp_server_url = normalize_grasp_server_url(url)?; |
| 949 | if ngit_relay_url.contains("http://") { | 952 | if grasp_server_url.contains("http://") { |
| 950 | return Ok(format!( | 953 | return Ok(format!( |
| 951 | "{ngit_relay_url}/{}/{identifier}.git", | 954 | "{grasp_server_url}/{}/{identifier}.git", |
| 952 | public_key.to_bech32()? | 955 | public_key.to_bech32()? |
| 953 | )); | 956 | )); |
| 954 | } | 957 | } |
| 955 | Ok(format!( | 958 | Ok(format!( |
| 956 | "https://{ngit_relay_url}/{}/{identifier}.git", | 959 | "https://{grasp_server_url}/{}/{identifier}.git", |
| 957 | public_key.to_bech32()? | 960 | public_key.to_bech32()? |
| 958 | )) | 961 | )) |
| 959 | } | 962 | } |
| 960 | 963 | ||
| 961 | fn format_ngit_relay_url_as_relay_url(url: &str) -> Result<String> { | 964 | fn format_grasp_server_url_as_relay_url(url: &str) -> Result<String> { |
| 962 | let ngit_relay_url = normalize_ngit_relay_url(url)?; | 965 | let grasp_server_url = normalize_grasp_server_url(url)?; |
| 963 | if ngit_relay_url.contains("http://") { | 966 | if grasp_server_url.contains("http://") { |
| 964 | return Ok(ngit_relay_url.replace("http://", "ws://")); | 967 | return Ok(grasp_server_url.replace("http://", "ws://")); |
| 965 | } | 968 | } |
| 966 | Ok(format!("wss://{ngit_relay_url}")) | 969 | Ok(format!("wss://{grasp_server_url}")) |
| 967 | } | 970 | } |
| 968 | 971 | ||
| 969 | fn format_ngit_relay_url_as_blossom_url(url: &str) -> Result<String> { | 972 | fn format_grasp_server_url_as_blossom_url(url: &str) -> Result<String> { |
| 970 | let ngit_relay_url = normalize_ngit_relay_url(url)?; | 973 | let grasp_server_url = normalize_grasp_server_url(url)?; |
| 971 | if ngit_relay_url.contains("http://") { | 974 | if grasp_server_url.contains("http://") { |
| 972 | return Ok(ngit_relay_url); | 975 | return Ok(grasp_server_url); |
| 973 | } | 976 | } |
| 974 | Ok(format!("https://{ngit_relay_url}")) | 977 | Ok(format!("https://{grasp_server_url}")) |
| 975 | } | 978 | } |
| 976 | 979 | ||
| 977 | fn parse_relay_url(s: &str) -> Result<RelayUrl> { | 980 | fn parse_relay_url(s: &str) -> Result<RelayUrl> { |
diff --git a/src/lib/repo_ref.rs b/src/lib/repo_ref.rs index 78968b4..c1fc288 100644 --- a/src/lib/repo_ref.rs +++ b/src/lib/repo_ref.rs | |||
| @@ -308,8 +308,8 @@ impl RepoRef { | |||
| 308 | } | 308 | } |
| 309 | } | 309 | } |
| 310 | 310 | ||
| 311 | pub fn ngit_relays(&self) -> Vec<String> { | 311 | pub fn grasp_servers(&self) -> Vec<String> { |
| 312 | detect_existing_ngit_relays(Some(self), &[], &[], &[], &self.identifier) | 312 | detect_existing_grasp_servers(Some(self), &[], &[], &[], &self.identifier) |
| 313 | } | 313 | } |
| 314 | } | 314 | } |
| 315 | 315 | ||
| @@ -586,7 +586,7 @@ pub fn save_repo_config_to_yaml( | |||
| 586 | .context("failed to write maintainers to maintainers.yaml file serde_yaml") | 586 | .context("failed to write maintainers to maintainers.yaml file serde_yaml") |
| 587 | } | 587 | } |
| 588 | 588 | ||
| 589 | pub fn detect_existing_ngit_relays( | 589 | pub fn detect_existing_grasp_servers( |
| 590 | repo_ref: Option<&RepoRef>, | 590 | repo_ref: Option<&RepoRef>, |
| 591 | args_relays: &[String], | 591 | args_relays: &[String], |
| 592 | args_clone_url: &[String], | 592 | args_clone_url: &[String], |
| @@ -626,45 +626,46 @@ pub fn detect_existing_ngit_relays( | |||
| 626 | Vec::new() | 626 | Vec::new() |
| 627 | }; | 627 | }; |
| 628 | 628 | ||
| 629 | let mut existing_ngit_relays = Vec::new(); | 629 | let mut existing_grasp_servers = Vec::new(); |
| 630 | for url in &clone_urls { | 630 | for url in &clone_urls { |
| 631 | let Ok(formatted_as_ngit_relay_url) = normalize_ngit_relay_url(url) else { | 631 | let Ok(formatted_as_grasp_server_url) = normalize_grasp_server_url(url) else { |
| 632 | continue; | 632 | continue; |
| 633 | }; | 633 | }; |
| 634 | if existing_ngit_relays.contains(&formatted_as_ngit_relay_url) { | 634 | if existing_grasp_servers.contains(&formatted_as_grasp_server_url) { |
| 635 | continue; | 635 | continue; |
| 636 | } | 636 | } |
| 637 | 637 | ||
| 638 | let clone_url_is_ngit_relay_format = if let Ok(npub) = extract_npub(url) { | 638 | let clone_url_is_grasp_server_format = if let Ok(npub) = extract_npub(url) { |
| 639 | url.contains(&format!("/{npub}/{identifier}.git")) | 639 | url.contains(&format!("/{npub}/{identifier}.git")) |
| 640 | } else { | 640 | } else { |
| 641 | false | 641 | false |
| 642 | }; | 642 | }; |
| 643 | if !clone_url_is_ngit_relay_format { | 643 | if !clone_url_is_grasp_server_format { |
| 644 | continue; | 644 | continue; |
| 645 | } | 645 | } |
| 646 | 646 | ||
| 647 | let matches_relay = relays.iter().any(|r| { | 647 | let matches_relay = relays.iter().any(|r| { |
| 648 | normalize_ngit_relay_url(&r.to_string()) | 648 | normalize_grasp_server_url(&r.to_string()) |
| 649 | .is_ok_and(|r| r.eq(&formatted_as_ngit_relay_url)) | 649 | .is_ok_and(|r| r.eq(&formatted_as_grasp_server_url)) |
| 650 | }); | 650 | }); |
| 651 | if !matches_relay { | 651 | if !matches_relay { |
| 652 | continue; | 652 | continue; |
| 653 | } | 653 | } |
| 654 | 654 | ||
| 655 | let matches_blossoms = blossoms.iter().any(|r| { | 655 | let matches_blossoms = blossoms.iter().any(|r| { |
| 656 | normalize_ngit_relay_url(r.as_str()).is_ok_and(|r| r.eq(&formatted_as_ngit_relay_url)) | 656 | normalize_grasp_server_url(r.as_str()) |
| 657 | .is_ok_and(|r| r.eq(&formatted_as_grasp_server_url)) | ||
| 657 | }); | 658 | }); |
| 658 | if !matches_blossoms { | 659 | if !matches_blossoms { |
| 659 | continue; | 660 | continue; |
| 660 | } | 661 | } |
| 661 | 662 | ||
| 662 | existing_ngit_relays.push(formatted_as_ngit_relay_url); | 663 | existing_grasp_servers.push(formatted_as_grasp_server_url); |
| 663 | } | 664 | } |
| 664 | existing_ngit_relays | 665 | existing_grasp_servers |
| 665 | } | 666 | } |
| 666 | 667 | ||
| 667 | pub fn normalize_ngit_relay_url(url: &str) -> Result<String> { | 668 | pub fn normalize_grasp_server_url(url: &str) -> Result<String> { |
| 668 | // Parse the URL and handle errors | 669 | // Parse the URL and handle errors |
| 669 | let mut parsed = Url::parse(url) | 670 | let mut parsed = Url::parse(url) |
| 670 | .or_else(|_| Url::parse(&format!("https://{url}"))) | 671 | .or_else(|_| Url::parse(&format!("https://{url}"))) |
| @@ -716,10 +717,10 @@ pub fn extract_npub(s: &str) -> Result<&str> { | |||
| 716 | } | 717 | } |
| 717 | } | 718 | } |
| 718 | 719 | ||
| 719 | pub fn is_ngit_relay(url: &str, ngit_relays: &[String]) -> bool { | 720 | pub fn is_grasp_server(url: &str, grasp_servers: &[String]) -> bool { |
| 720 | if !ngit_relays.is_empty() { | 721 | if !grasp_servers.is_empty() { |
| 721 | if let Ok(n) = normalize_ngit_relay_url(url) { | 722 | if let Ok(n) = normalize_grasp_server_url(url) { |
| 722 | return ngit_relays.contains(&n); | 723 | return grasp_servers.contains(&n); |
| 723 | } | 724 | } |
| 724 | } | 725 | } |
| 725 | false | 726 | false |
| @@ -1005,7 +1006,7 @@ mod tests { | |||
| 1005 | } | 1006 | } |
| 1006 | 1007 | ||
| 1007 | #[test] | 1008 | #[test] |
| 1008 | fn normalize_ngit_relay_url_all_checks() -> Result<()> { | 1009 | fn normalize_grasp_server_url_all_checks() -> Result<()> { |
| 1009 | let test_cases = vec![ | 1010 | let test_cases = vec![ |
| 1010 | ("https://sub.domain.org", "sub.domain.org"), | 1011 | ("https://sub.domain.org", "sub.domain.org"), |
| 1011 | ("wss://sub.domain.org", "sub.domain.org"), | 1012 | ("wss://sub.domain.org", "sub.domain.org"), |
| @@ -1035,7 +1036,7 @@ mod tests { | |||
| 1035 | ]; | 1036 | ]; |
| 1036 | 1037 | ||
| 1037 | for (input, expected) in test_cases { | 1038 | for (input, expected) in test_cases { |
| 1038 | let normalized = normalize_ngit_relay_url(input)?; | 1039 | let normalized = normalize_grasp_server_url(input)?; |
| 1039 | assert_eq!(normalized, expected); | 1040 | assert_eq!(normalized, expected); |
| 1040 | } | 1041 | } |
| 1041 | Ok(()) | 1042 | Ok(()) |