summaryrefslogtreecommitdiffstats
path: root/src/git_config/mod.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/git_config/mod.rs')
-rw-r--r--src/git_config/mod.rs31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/git_config/mod.rs b/src/git_config/mod.rs
index 60fb0a62..6e40a70e 100644
--- a/src/git_config/mod.rs
+++ b/src/git_config/mod.rs
@@ -5,7 +5,6 @@ pub use git_config_entry::{GitConfigEntry, GitRemoteRepo};
use crate::env::DeltaEnv;
use regex::Regex;
use std::collections::HashMap;
-#[cfg(test)]
use std::path::Path;
use std::str::FromStr;
@@ -65,12 +64,42 @@ impl GitConfig {
}
}
+ #[cfg(not(test))]
+ pub fn try_create_from_path(env: &DeltaEnv, path: &String) -> Self {
+ use crate::fatal;
+
+ let config = git2::Config::open(Path::new(path));
+
+ match config {
+ Ok(mut config) => {
+ let config = config.snapshot().unwrap_or_else(|err| {
+ fatal(format!("Failed to read git config: {err}"));
+ });
+
+ Self {
+ config,
+ config_from_env_var: parse_config_from_env_var(env),
+ repo: None,
+ enabled: true,
+ }
+ }
+ Err(e) => {
+ fatal(format!("Failed to read git config: {}", e.message()));
+ }
+ }
+ }
+
#[cfg(test)]
pub fn try_create(_env: &DeltaEnv) -> Option<Self> {
unreachable!("GitConfig::try_create() is not available when testing");
}
#[cfg(test)]
+ pub fn try_create_from_path(_env: &DeltaEnv, _path: &String) -> Self {
+ unreachable!("GitConfig::try_create_from_path() is not available when testing");
+ }
+
+ #[cfg(test)]
pub fn from_path(env: &DeltaEnv, path: &Path, honor_env_var: bool) -> Self {
Self {
config: git2::Config::open(path).unwrap(),