diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-06-23 00:39:29 -0400 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2020-06-23 00:39:29 -0400 |
commit | 2968ef357129d25dd4fc31fe6f3e6186ad20c144 (patch) | |
tree | c6a9e7ded14a5baadc29e76e1c8f58626c647e0f | |
parent | 2567235f0c9ca5b3e6839b3632c1e6dd74853091 (diff) |
Fix --no-gitconfig implementation
-rw-r--r-- | src/features/mod.rs | 4 | ||||
-rw-r--r-- | src/get_option_value.rs | 20 | ||||
-rw-r--r-- | src/git_config.rs | 13 | ||||
-rw-r--r-- | src/set_options.rs | 5 |
4 files changed, 26 insertions, 16 deletions
diff --git a/src/features/mod.rs b/src/features/mod.rs index 67506ef8..c05f740a 100644 --- a/src/features/mod.rs +++ b/src/features/mod.rs @@ -55,8 +55,8 @@ macro_rules! builtin_feature { ( $option_name.to_string(), Box::new(move |$opt: &$crate::cli::Opt, git_config: &Option<$crate::git_config::GitConfig>| { - match (git_config, $git_config_key, $opt.no_gitconfig) { - (Some(git_config), Some(git_config_key), false) => match git_config.get::<$type>(git_config_key) { + match (git_config, $git_config_key) { + (Some(git_config), Some(git_config_key)) => match git_config.get::<$type>(git_config_key) { Some(value) => Some($crate::features::GitConfigValue(value.into())), _ => None, }, diff --git a/src/get_option_value.rs b/src/get_option_value.rs index 1eaa93d9..bce309c1 100644 --- a/src/get_option_value.rs +++ b/src/get_option_value.rs @@ -51,11 +51,9 @@ pub trait GetOptionValue { Self: From<OptionValue>, Self: Into<OptionValue>, { - if !opt.no_gitconfig { - if let Some(git_config) = git_config { - if let Some(value) = git_config.get::<Self>(&format!("delta.{}", option_name)) { - return Some(value); - } + if let Some(git_config) = git_config { + if let Some(value) = git_config.get::<Self>(&format!("delta.{}", option_name)) { + return Some(value); } } for feature in opt.features.to_lowercase().split_whitespace().rev() { @@ -90,13 +88,11 @@ pub trait GetOptionValue { Self: GitConfigGet, Self: Into<OptionValue>, { - if !opt.no_gitconfig { - if let Some(git_config) = git_config { - if let Some(value) = - git_config.get::<Self>(&format!("delta.{}.{}", feature, option_name)) - { - return Some(GitConfigValue(value.into())); - } + if let Some(git_config) = git_config { + if let Some(value) = + git_config.get::<Self>(&format!("delta.{}.{}", feature, option_name)) + { + return Some(GitConfigValue(value.into())); } } if let Some(builtin_feature) = builtin_features.get(feature) { diff --git a/src/git_config.rs b/src/git_config.rs index 77f4c899..c6ef9c0c 100644 --- a/src/git_config.rs +++ b/src/git_config.rs @@ -6,6 +6,7 @@ use git2; pub struct GitConfig { config: git2::Config, + pub enabled: bool, } impl GitConfig { @@ -24,7 +25,10 @@ impl GitConfig { eprintln!("Failed to read git config: {}", err); process::exit(1) }); - Some(Self { config }) + Some(Self { + config, + enabled: true, + }) } None => None, } @@ -34,6 +38,7 @@ impl GitConfig { pub fn from_path(path: &Path) -> Self { Self { config: git2::Config::open(path).unwrap(), + enabled: true, } } @@ -41,7 +46,11 @@ impl GitConfig { where T: GitConfigGet, { - T::git_config_get(key, self) + if self.enabled { + T::git_config_get(key, self) + } else { + None + } } } diff --git a/src/set_options.rs b/src/set_options.rs index 53a353ac..73bfadaa 100644 --- a/src/set_options.rs +++ b/src/set_options.rs @@ -25,6 +25,11 @@ pub fn set_options( git_config: &mut Option<git_config::GitConfig>, arg_matches: &clap::ArgMatches, ) { + if let Some(git_config) = git_config { + if opt.no_gitconfig { + git_config.enabled = false; + } + } let builtin_features = features::make_builtin_features(); opt.features = gather_features( opt, |