upleb.uk

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

summaryrefslogtreecommitdiff
path: root/src/lib/git
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/git')
-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)