summaryrefslogtreecommitdiff
path: root/src/git_config/mod.rs
diff options
context:
space:
mode:
authorThomas Otto <th1000s@posteo.net>2024-11-14 23:22:24 +0100
committerThomas Otto <th1000s@posteo.net>2024-11-20 23:45:55 +0100
commit4ea8f9ab6038b934a03c6370e5c3e45da0466fe5 (patch)
tree3768eed6dd0e0b866280780fb4a5735da14582aa /src/git_config/mod.rs
parent1dd28e7b51a913fc28eefc59d01f3b78f1146850 (diff)
testability: add pretty_assertions, git mocks
Diffstat (limited to 'src/git_config/mod.rs')
-rw-r--r--src/git_config/mod.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/git_config/mod.rs b/src/git_config/mod.rs
index 22fc604..fc59a84 100644
--- a/src/git_config/mod.rs
+++ b/src/git_config/mod.rs
@@ -6,7 +6,6 @@ use crate::env::DeltaEnv;
use regex::Regex;
use std::collections::HashMap;
use std::path::Path;
-use std::str::FromStr;
use lazy_static::lazy_static;
@@ -70,6 +69,17 @@ impl GitConfig {
None
}
+ #[cfg(test)]
+ pub fn for_testing() -> Option<Self> {
+ Some(GitConfig {
+ config: git2::Config::new().unwrap(),
+ config_from_env_var: HashMap::new(),
+ enabled: true,
+ repo: None,
+ path: std::path::PathBuf::from("/invalid_null.git"),
+ })
+ }
+
pub fn from_path(env: &DeltaEnv, path: &Path, honor_env_var: bool) -> Self {
use crate::fatal;
@@ -109,7 +119,9 @@ impl GitConfig {
}
}
+ #[cfg(not(test))]
pub fn get_remote_url(&self) -> Option<GitRemoteRepo> {
+ use std::str::FromStr;
self.repo
.as_ref()?
.find_remote("origin")