From a5a662632b61ef2b35946af1e93f30a885ea1db2 Mon Sep 17 00:00:00 2001 From: DanConwayDev Date: Fri, 6 Sep 2024 07:47:13 +0100 Subject: feat(remote): fetch protocol selection / fallback enable override from nostr url clone url is local use local otherwise try https unathenticated, ssh, then https authenticated --- src/lib/git/mod.rs | 1 + src/lib/git/utils.rs | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/lib/git/utils.rs (limited to 'src/lib/git') diff --git a/src/lib/git/mod.rs b/src/lib/git/mod.rs index f92272f..72717f7 100644 --- a/src/lib/git/mod.rs +++ b/src/lib/git/mod.rs @@ -11,6 +11,7 @@ use nostr_sdk::hashes::{sha1::Hash as Sha1Hash, Hash}; use crate::git_events::{get_commit_id_from_patch, tag_value}; pub mod identify_ahead_behind; pub mod nostr_url; +pub mod utils; pub struct Repo { pub git_repo: git2::Repository, diff --git a/src/lib/git/utils.rs b/src/lib/git/utils.rs new file mode 100644 index 0000000..4e8f153 --- /dev/null +++ b/src/lib/git/utils.rs @@ -0,0 +1,25 @@ +use std::path::Path; + +use directories::UserDirs; + +pub fn check_ssh_keys() -> bool { + // Get the user's home directory using the directories crate + if let Some(user_dirs) = UserDirs::new() { + let ssh_dir = user_dirs.home_dir().join(".ssh"); + let key_files = vec![ + "id_rsa", + "id_ecdsa", + "id_ed25519", + "id_rsa.pub", + "id_ecdsa.pub", + "id_ed25519.pub", + ]; + + for key in key_files { + if Path::new(&ssh_dir.join(key)).exists() { + return true; // At least one key exists + } + } + } + false // No keys found +} -- cgit v1.2.3