diff options
| -rw-r--r-- | src/bin/git_remote_nostr/fetch.rs | 33 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/list.rs | 7 | ||||
| -rw-r--r-- | src/bin/git_remote_nostr/utils.rs | 7 |
3 files changed, 33 insertions, 14 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 @@ | |||
| 1 | use std::io::Stdin; | 1 | use std::io::Stdin; |
| 2 | 2 | ||
| 3 | use anyhow::{bail, Result}; | 3 | use anyhow::{anyhow, bail, Result}; |
| 4 | use auth_git2::GitAuthenticator; | 4 | use auth_git2::GitAuthenticator; |
| 5 | use git2::Repository; | 5 | use git2::Repository; |
| 6 | use ngit::{ | 6 | use ngit::{ |
| @@ -15,8 +15,8 @@ use ngit::{ | |||
| 15 | }; | 15 | }; |
| 16 | 16 | ||
| 17 | use crate::utils::{ | 17 | use 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 | ||
| 22 | pub async fn run_fetch( | 22 | pub 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 | ||
| 161 | fn fetch_from_git_server_url( | 168 | fn fetch_from_git_server_url( |
diff --git a/src/bin/git_remote_nostr/list.rs b/src/bin/git_remote_nostr/list.rs index 26f699d..ae76614 100644 --- a/src/bin/git_remote_nostr/list.rs +++ b/src/bin/git_remote_nostr/list.rs | |||
| @@ -22,7 +22,8 @@ use repo_ref::RepoRef; | |||
| 22 | use crate::{ | 22 | use crate::{ |
| 23 | git::Repo, | 23 | git::Repo, |
| 24 | utils::{ | 24 | utils::{ |
| 25 | get_open_proposals, get_read_protocols_to_try, get_short_git_server_name, join_with_and, | 25 | error_is_not_authentication_failure, get_open_proposals, get_read_protocols_to_try, |
| 26 | get_short_git_server_name, join_with_and, | ||
| 26 | }, | 27 | }, |
| 27 | }; | 28 | }; |
| 28 | 29 | ||
| @@ -196,6 +197,10 @@ pub fn list_from_remote( | |||
| 196 | format!("list: {formatted_url} failed over {protocol}: {error}").as_str(), | 197 | format!("list: {formatted_url} failed over {protocol}: {error}").as_str(), |
| 197 | )?; | 198 | )?; |
| 198 | failed_protocols.push(protocol); | 199 | failed_protocols.push(protocol); |
| 200 | if protocol == &ServerProtocol::Ssh && error_is_not_authentication_failure(&error) { | ||
| 201 | // authenticated by failed to complete request | ||
| 202 | break; | ||
| 203 | } | ||
| 199 | } | 204 | } |
| 200 | } | 205 | } |
| 201 | term.clear_last_lines(1)?; | 206 | term.clear_last_lines(1)?; |
diff --git a/src/bin/git_remote_nostr/utils.rs b/src/bin/git_remote_nostr/utils.rs index a31dcbf..90ea848 100644 --- a/src/bin/git_remote_nostr/utils.rs +++ b/src/bin/git_remote_nostr/utils.rs | |||
| @@ -282,6 +282,7 @@ pub fn get_read_protocols_to_try( | |||
| 282 | vec![ | 282 | vec![ |
| 283 | ServerProtocol::UnauthHttp, | 283 | ServerProtocol::UnauthHttp, |
| 284 | ServerProtocol::Ssh, | 284 | ServerProtocol::Ssh, |
| 285 | // note: list and fetch stop here if ssh was authenticated | ||
| 285 | ServerProtocol::Http, | 286 | ServerProtocol::Http, |
| 286 | ] | 287 | ] |
| 287 | } else if server_url.protocol() == ServerProtocol::Ftp { | 288 | } else if server_url.protocol() == ServerProtocol::Ftp { |
| @@ -290,11 +291,17 @@ pub fn get_read_protocols_to_try( | |||
| 290 | vec![ | 291 | vec![ |
| 291 | ServerProtocol::UnauthHttps, | 292 | ServerProtocol::UnauthHttps, |
| 292 | ServerProtocol::Ssh, | 293 | ServerProtocol::Ssh, |
| 294 | // note: list and fetch stop here if ssh was authenticated | ||
| 293 | ServerProtocol::Https, | 295 | ServerProtocol::Https, |
| 294 | ] | 296 | ] |
| 295 | } | 297 | } |
| 296 | } | 298 | } |
| 297 | 299 | ||
| 300 | pub fn error_is_not_authentication_failure(error: &anyhow::Error) -> bool { | ||
| 301 | let error_str = error.to_string(); | ||
| 302 | error_str.contains("Permission to") || error_str.contains("Repository not found") | ||
| 303 | } | ||
| 304 | |||
| 298 | #[cfg(test)] | 305 | #[cfg(test)] |
| 299 | mod tests { | 306 | mod tests { |
| 300 | use super::*; | 307 | use super::*; |