upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/git_remote_helper.rs45
1 files changed, 33 insertions, 12 deletions
diff --git a/src/git_remote_helper.rs b/src/git_remote_helper.rs
index 12477da..657f992 100644
--- a/src/git_remote_helper.rs
+++ b/src/git_remote_helper.rs
@@ -234,11 +234,12 @@ async fn list(
234 let state = if let Some(nostr_state) = nostr_state { 234 let state = if let Some(nostr_state) = nostr_state {
235 for (name, value) in &nostr_state.state { 235 for (name, value) in &nostr_state.state {
236 for (url, remote_state) in &remote_states { 236 for (url, remote_state) in &remote_states {
237 let remote_name = get_short_git_server_name(git_repo, url);
237 if let Some(remote_value) = remote_state.get(name) { 238 if let Some(remote_value) = remote_state.get(name) {
238 if value.ne(remote_value) { 239 if value.ne(remote_value) {
239 term.write_line( 240 term.write_line(
240 format!( 241 format!(
241 "WARNING: {url} {name} is {} nostr ", 242 "WARNING: {remote_name} {name} is {} nostr ",
242 if let Ok((ahead, behind)) = 243 if let Ok((ahead, behind)) =
243 get_ahead_behind(git_repo, value, remote_value) 244 get_ahead_behind(git_repo, value, remote_value)
244 { 245 {
@@ -252,7 +253,8 @@ async fn list(
252 } 253 }
253 } else { 254 } else {
254 term.write_line( 255 term.write_line(
255 format!("WARNING: {url} {name} is missing but tracked on nostr").as_str(), 256 format!("WARNING: {remote_name} {name} is missing but tracked on nostr")
257 .as_str(),
256 )?; 258 )?;
257 } 259 }
258 } 260 }
@@ -291,14 +293,15 @@ fn list_from_remotes(
291) -> Result<HashMap<String, HashMap<String, String>>> { 293) -> Result<HashMap<String, HashMap<String, String>>> {
292 let mut remote_states = HashMap::new(); 294 let mut remote_states = HashMap::new();
293 for url in git_servers { 295 for url in git_servers {
294 term.write_line(format!("fetching refs list: {url}...").as_str())?; 296 let short_name = get_short_git_server_name(git_repo, url);
297 term.write_line(format!("fetching refs list: {short_name}...").as_str())?;
295 match list_from_remote(git_repo, url) { 298 match list_from_remote(git_repo, url) {
296 Ok(remote_state) => { 299 Ok(remote_state) => {
297 remote_states.insert(url.clone(), remote_state); 300 remote_states.insert(url.clone(), remote_state);
298 } 301 }
299 Err(error) => { 302 Err(error) => {
300 term.write_line( 303 term.write_line(
301 format!("WARNING: {url} failed to list refs error: {error}").as_str(), 304 format!("WARNING: {short_name} failed to list refs error: {error}",).as_str(),
302 )?; 305 )?;
303 } 306 }
304 } 307 }
@@ -486,7 +489,8 @@ async fn push(
486 if let Some(error) = error { 489 if let Some(error) = error {
487 term.write_line( 490 term.write_line(
488 format!( 491 format!(
489 "WARNING: {git_server_url} failed to push {name} error: {error}" 492 "WARNING: {} failed to push {name} error: {error}",
493 get_short_git_server_name(git_repo, &git_server_url),
490 ) 494 )
491 .as_str(), 495 .as_str(),
492 ) 496 )
@@ -519,6 +523,7 @@ fn create_rejected_refspecs_and_remotes_refspecs(
519 let mut rejected_refspecs: HashMapUrlRefspecs = HashMap::new(); 523 let mut rejected_refspecs: HashMapUrlRefspecs = HashMap::new();
520 524
521 for (url, remote_state) in list_outputs { 525 for (url, remote_state) in list_outputs {
526 let short_name = get_short_git_server_name(git_repo, url);
522 let mut refspecs_for_remote = vec![]; 527 let mut refspecs_for_remote = vec![];
523 for refspec in refspecs { 528 for refspec in refspecs {
524 let (from, to) = refspec_to_from_to(refspec)?; 529 let (from, to) = refspec_to_from_to(refspec)?;
@@ -565,7 +570,9 @@ fn create_rejected_refspecs_and_remotes_refspecs(
565 { 570 {
566 if from_tip.eq(&remote_value_tip) { 571 if from_tip.eq(&remote_value_tip) {
567 // remote already at correct state 572 // remote already at correct state
568 term.write_line(format!("{url} {to} already up-to-date").as_str())?; 573 term.write_line(
574 format!("{short_name} {to} already up-to-date").as_str(),
575 )?;
569 } 576 }
570 let nostr_value_tip = 577 let nostr_value_tip =
571 git_repo.get_commit_or_tip_of_reference(nostr_value)?; 578 git_repo.get_commit_or_tip_of_reference(nostr_value)?;
@@ -582,7 +589,7 @@ fn create_rejected_refspecs_and_remotes_refspecs(
582 .or_insert(vec![url.to_string()]); 589 .or_insert(vec![url.to_string()]);
583 term.write_line( 590 term.write_line(
584 format!( 591 format!(
585 "ERROR: {url} {to} conflicts with nostr ({} ahead {} behind). either:\r\n 1. pull from that git server and resolve\r\n 2. force push your branch to the git server before pushing to nostr remote", 592 "ERROR: {short_name} {to} conflicts with nostr ({} ahead {} behind). either:\r\n 1. pull from that git server and resolve\r\n 2. force push your branch to the git server before pushing to nostr remote",
586 ahead.len(), 593 ahead.len(),
587 behind.len(), 594 behind.len(),
588 ).as_str(), 595 ).as_str(),
@@ -598,15 +605,17 @@ fn create_rejected_refspecs_and_remotes_refspecs(
598 .and_modify(|a| a.push(url.to_string())) 605 .and_modify(|a| a.push(url.to_string()))
599 .or_insert(vec![url.to_string()]); 606 .or_insert(vec![url.to_string()]);
600 term.write_line( 607 term.write_line(
601 format!("ERROR: {url} {to} conflicts with nostr and is not an ancestor of local branch. either:\r\n 1. pull from that git server and resolve\r\n 2. force push your branch to the git server before pushing to nostr remote").as_str(), 608 format!("ERROR: {short_name} {to} conflicts with nostr and is not an ancestor of local branch. either:\r\n 1. pull from that git server and resolve\r\n 2. force push your branch to the git server before pushing to nostr remote").as_str(),
602 )?; 609 )?;
603 } 610 }
604 } else { 611 } else {
605 // existing nostr branch not on remote 612 // existing nostr branch not on remote
606 // report - creating new branch 613 // report - creating new branch
607 term.write_line( 614 term.write_line(
608 format!("{url} {to} doesn't exist and will be added as a new branch") 615 format!(
609 .as_str(), 616 "{short_name} {to} doesn't exist and will be added as a new branch"
617 )
618 .as_str(),
610 )?; 619 )?;
611 refspecs_for_remote.push(refspec.clone()); 620 refspecs_for_remote.push(refspec.clone());
612 } 621 }
@@ -627,7 +636,7 @@ fn create_rejected_refspecs_and_remotes_refspecs(
627 .or_insert(vec![url.to_string()]); 636 .or_insert(vec![url.to_string()]);
628 term.write_line( 637 term.write_line(
629 format!( 638 format!(
630 "ERROR: {url} already contains {to} {} ahead and {} behind local branch. either:\r\n 1. pull from that git server and resolve\r\n 2. force push your branch to the git server before pushing to nostr remote", 639 "ERROR: {short_name} already contains {to} {} ahead and {} behind local branch. either:\r\n 1. pull from that git server and resolve\r\n 2. force push your branch to the git server before pushing to nostr remote",
631 ahead.len(), 640 ahead.len(),
632 behind.len(), 641 behind.len(),
633 ).as_str(), 642 ).as_str(),
@@ -642,7 +651,7 @@ fn create_rejected_refspecs_and_remotes_refspecs(
642 .and_modify(|a| a.push(url.to_string())) 651 .and_modify(|a| a.push(url.to_string()))
643 .or_insert(vec![url.to_string()]); 652 .or_insert(vec![url.to_string()]);
644 term.write_line( 653 term.write_line(
645 format!("ERROR: {url} already contains {to} at {remote_value} which is not an ancestor of local branch. either:\r\n 1. pull from that git server and resolve\r\n 2. force push your branch to the git server before pushing to nostr remote").as_str(), 654 format!("ERROR: {short_name} already contains {to} at {remote_value} which is not an ancestor of local branch. either:\r\n 1. pull from that git server and resolve\r\n 2. force push your branch to the git server before pushing to nostr remote").as_str(),
646 )?; 655 )?;
647 } 656 }
648 } else { 657 } else {
@@ -796,6 +805,18 @@ fn get_remote_name_by_url(git_repo: &Repository, url: &str) -> Result<String> {
796 .to_string()) 805 .to_string())
797} 806}
798 807
808fn get_short_git_server_name(git_repo: &Repo, url: &str) -> std::string::String {
809 if let Ok(name) = get_remote_name_by_url(&git_repo.git_repo, url) {
810 return name;
811 }
812 if let Ok(url) = Url::parse(url) {
813 if let Some(domain) = url.domain() {
814 return domain.to_string();
815 }
816 }
817 url.to_string()
818}
819
799fn get_oids_from_fetch_batch(stdin: &Stdin, initial_oid: &str) -> Result<Vec<String>> { 820fn get_oids_from_fetch_batch(stdin: &Stdin, initial_oid: &str) -> Result<Vec<String>> {
800 let mut line = String::new(); 821 let mut line = String::new();
801 let mut oids = vec![initial_oid.to_string()]; 822 let mut oids = vec![initial_oid.to_string()];