From 708f4137a89a3ce18db7bc416dd60bf27f8302aa Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Wed, 11 Sep 2024 16:22:09 +0100 Subject: fix(remote): identify auth failure so that attempts can be made to use a fallback protocol --- src/bin/git_remote_nostr/utils.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/bin') diff --git a/src/bin/git_remote_nostr/utils.rs b/src/bin/git_remote_nostr/utils.rs index 3039fe3..9be2580 100644 --- a/src/bin/git_remote_nostr/utils.rs +++ b/src/bin/git_remote_nostr/utils.rs @@ -284,14 +284,27 @@ pub fn get_write_protocols_to_try( /// to understand whether to try over another protocol pub fn fetch_or_list_error_is_not_authentication_failure(error: &anyhow::Error) -> bool { - let error_str = error.to_string(); - error_str.contains("Permission to") || error_str.contains("Repository not found") + !error_might_be_authentication_related(error) } /// to understand whether to try over another protocol pub fn push_error_is_not_authentication_failure(error: &anyhow::Error) -> bool { + !error_might_be_authentication_related(error) +} + +pub fn error_might_be_authentication_related(error: &anyhow::Error) -> bool { let error_str = error.to_string(); - error_str.contains("Permission to") || error_str.contains("Repository not found") + for s in [ + "no ssh keys found", + "invalid or unknown remote ssh", + "Permission to", + "Repository not found", + ] { + if error_str.contains(s) { + return true; + } + } + false } #[cfg(test)] -- cgit v1.2.3