upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/bin/git_remote_nostr/fetch.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2024-09-06 11:29:27 +0100
committerDanConwayDev <DanConwayDev@protonmail.com>2024-09-06 11:29:27 +0100
commit0b9ebd63be13ee403c415d4a29538b94f9e7cffe (patch)
treeb0308cb9685e1d1dd764e3ed9c3d6e5b63322025 /src/bin/git_remote_nostr/fetch.rs
parent6e7e7bd3497d2a77fda34e27f65955b8ac09b3be (diff)
feat(remote): just use ssh if auth succeeds
and don't proceed to https or http
Diffstat (limited to 'src/bin/git_remote_nostr/fetch.rs')
-rw-r--r--src/bin/git_remote_nostr/fetch.rs33
1 files changed, 20 insertions, 13 deletions
diff --git a/src/bin/git_remote_nostr/fetch.rs b/src/bin/git_remote_nostr/fetch.rs
index f591fed..0a98db2 100644
--- a/src/bin/git_remote_nostr/fetch.rs
+++ b/src/bin/git_remote_nostr/fetch.rs
@@ -1,6 +1,6 @@
1use std::io::Stdin; 1use std::io::Stdin;
2 2
3use anyhow::{bail, Result}; 3use anyhow::{anyhow, bail, Result};
4use auth_git2::GitAuthenticator; 4use auth_git2::GitAuthenticator;
5use git2::Repository; 5use git2::Repository;
6use ngit::{ 6use ngit::{
@@ -15,8 +15,8 @@ use ngit::{
15}; 15};
16 16
17use crate::utils::{ 17use crate::utils::{
18 find_proposal_and_patches_by_branch_name, get_oids_from_fetch_batch, get_open_proposals, 18 error_is_not_authentication_failure, find_proposal_and_patches_by_branch_name,
19 get_read_protocols_to_try, join_with_and, 19 get_oids_from_fetch_batch, get_open_proposals, get_read_protocols_to_try, join_with_and,
20}; 20};
21 21
22pub async fn run_fetch( 22pub async fn run_fetch(
@@ -136,6 +136,10 @@ fn fetch_from_git_server(
136 format!("fetch: {formatted_url} failed over {protocol}: {error}").as_str(), 136 format!("fetch: {formatted_url} failed over {protocol}: {error}").as_str(),
137 )?; 137 )?;
138 failed_protocols.push(protocol); 138 failed_protocols.push(protocol);
139 if protocol == &ServerProtocol::Ssh && error_is_not_authentication_failure(&error) {
140 // authenticated by failed to complete request
141 break;
142 }
139 } else { 143 } else {
140 success = true; 144 success = true;
141 if !failed_protocols.is_empty() { 145 if !failed_protocols.is_empty() {
@@ -143,19 +147,22 @@ fn fetch_from_git_server(
143 } 147 }
144 } 148 }
145 } 149 }
146 if !success { 150 if success {
147 if decoded_nostr_url.protocol.is_some() { 151 Ok(())
148 term.write_line( 152 } else {
149 "fetch: protocol override in nostr url so not attempting with any other protocols", 153 let error = anyhow!(
150 )?; 154 "{} failed over {}{}",
151 }
152 bail!(
153 "{} failed over {}",
154 server_url.domain(), 155 server_url.domain(),
155 join_with_and(&failed_protocols) 156 join_with_and(&failed_protocols),
157 if decoded_nostr_url.protocol.is_some() {
158 " and nostr url contains protocol override so no other protocols were attempted"
159 } else {
160 ""
161 },
156 ); 162 );
163 term.write_line(format!("fetch: {error}").as_str())?;
164 Err(error)
157 } 165 }
158 Ok(())
159} 166}
160 167
161fn fetch_from_git_server_url( 168fn fetch_from_git_server_url(