From 4ea8f9ab6038b934a03c6370e5c3e45da0466fe5 Mon Sep 17 00:00:00 2001 From: Thomas Otto Date: Thu, 14 Nov 2024 23:22:24 +0100 Subject: testability: add pretty_assertions, git mocks --- src/git_config/mod.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'src/git_config/mod.rs') 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 { + 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 { + use std::str::FromStr; self.repo .as_ref()? .find_remote("origin") -- cgit v1.2.3