diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-07-17 19:16:17 -0400 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2020-07-22 17:55:27 -0400 |
commit | 142fdbd067c602859eabebe583acfe9dc63d692a (patch) | |
tree | 54f9351e17d28265bcfe56eb8a60946b3293e88d /src/options | |
parent | 8233a753114b3a8ef853931b5d57029b42b897ed (diff) |
Read git config entries at start-up
Diffstat (limited to 'src/options')
-rw-r--r-- | src/options/set.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/options/set.rs b/src/options/set.rs index 48b31e80..8d52938d 100644 --- a/src/options/set.rs +++ b/src/options/set.rs @@ -1,5 +1,6 @@ use std::collections::{HashMap, HashSet, VecDeque}; use std::process; +use std::str::FromStr; use console::Term; use structopt::clap; @@ -11,8 +12,10 @@ use crate::config; use crate::env; use crate::features; use crate::git_config; +use crate::git_config_entry::{self, GitConfigEntry}; use crate::options::option_value::{OptionValue, ProvenancedOptionValue}; use crate::options::theme; +use crate::style::Style; macro_rules! set_options { ([$( $field_ident:ident ),* ], @@ -68,6 +71,7 @@ pub fn set_options( if opt.no_gitconfig { git_config.enabled = false; } + set_git_config_entries(opt, git_config); } let option_names = cli::Opt::get_option_names(); @@ -493,6 +497,34 @@ fn set_widths(opt: &mut cli::Opt) { background_color_extends_to_terminal_width; } +fn set_git_config_entries(opt: &mut cli::Opt, git_config: &mut git_config::GitConfig) { + // Styles + for key in &["color.diff.old", "color.diff.new"] { + if let Some(style_string) = git_config.get::<String>(key) { + opt.git_config_entries.insert( + key.to_string(), + GitConfigEntry::Style(Style::from_str( + &style_string, + None, + None, + opt.computed.true_color, + false, + )), + ); + } + } + + // Strings + for key in &["remote.origin.url"] { + if let Some(string) = git_config.get::<String>(key) { + if let Ok(repo) = git_config_entry::GitRemoteRepo::from_str(&string) { + opt.git_config_entries + .insert(key.to_string(), GitConfigEntry::GitRemote(repo)); + } + } + } +} + #[cfg(test)] pub mod tests { use std::fs::remove_file; |