upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/lib/git/mod.rs
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-03-05 15:03:37 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-03-05 15:06:02 +0000
commit09c3ae91830bd9c7543b401b19f8c65a15205d32 (patch)
tree3c7505301c9868cd421fbf0097ed946b9f4b9088 /src/lib/git/mod.rs
parent37244449d6d0d58bb639f181bd15092de1acaaee (diff)
fix(whoami): detect and fall back to system git config for nostr login
Add GitSystem to SignerInfoSource so credentials stored in the system git config (/etc/gitconfig) are included in the priority fallback chain (local > global > system) and shown as a separate level in whoami output.
Diffstat (limited to 'src/lib/git/mod.rs')
-rw-r--r--src/lib/git/mod.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/lib/git/mod.rs b/src/lib/git/mod.rs
index 23fa5f0..ca7aa3f 100644
--- a/src/lib/git/mod.rs
+++ b/src/lib/git/mod.rs
@@ -1089,6 +1089,22 @@ pub fn get_git_config_item(git_repo: &Option<&Repo>, item: &str) -> Result<Optio
1089 } 1089 }
1090} 1090}
1091 1091
1092/// Read a config item from the system-level git config only (e.g.
1093/// /etc/gitconfig).
1094pub fn get_git_config_item_system(item: &str) -> Result<Option<String>> {
1095 let config = git2::Config::open_default().context("failed to open git config")?;
1096 // Try system level first, then ProgramData (Windows equivalent)
1097 for level in [git2::ConfigLevel::System, git2::ConfigLevel::ProgramData] {
1098 if let Ok(level_config) = config.open_level(level) {
1099 match level_config.get_entry(item) {
1100 Ok(entry) => return Ok(entry.value().map(|v| v.to_string())),
1101 Err(_) => continue,
1102 }
1103 }
1104 }
1105 Ok(None)
1106}
1107
1092pub fn save_git_config_item(git_repo: &Option<&Repo>, item: &str, value: &str) -> Result<()> { 1108pub fn save_git_config_item(git_repo: &Option<&Repo>, item: &str, value: &str) -> Result<()> {
1093 if let Some(git_repo) = git_repo { 1109 if let Some(git_repo) = git_repo {
1094 git_repo.save_git_config_item(item, value, false) 1110 git_repo.save_git_config_item(item, value, false)