Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix computed values to be computed after all set_options #690

Merged
merged 5 commits into from Aug 20, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,3 +496,25 @@ pub fn delta_unreachable(message: &str) -> ! {
);
process::exit(error_exit_code);
}

#[cfg(test)]
pub mod tests {
use crate::tests::integration_test_utils;
use std::fs::remove_file;

#[test]
fn test_get_true_color_from_config() {
let git_config_contents = r#"
[delta]
true-color = never
"#;
let git_config_path = "delta__test_get_true_color_from_config.gitconfig";
let config = integration_test_utils::make_config_from_args_and_git_config(
&[],
Some(git_config_contents.as_bytes()),
Some(git_config_path),
);
assert!(!config.true_color);
remove_file(git_config_path).unwrap();
}
}
22 changes: 20 additions & 2 deletions src/options/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn set_options(
set_widths(opt, git_config, arg_matches, &option_names);

// Set light, dark, and syntax-theme.
set_true_color(opt);
set_true_color(opt, git_config, arg_matches, &option_names);
set__light__dark__syntax_theme__options(opt, git_config, arg_matches, &option_names);
theme::set__is_light_mode__syntax_theme__syntax_set(opt, assets);

Expand Down Expand Up @@ -556,14 +556,31 @@ fn set_widths(
background_color_extends_to_terminal_width;
}

fn set_true_color(opt: &mut cli::Opt) {
fn set_true_color(
opt: &mut cli::Opt,
git_config: &mut Option<GitConfig>,
arg_matches: &clap::ArgMatches,
option_names: &HashMap<&str, &str>,
) {
if opt.true_color == "auto" {
// It's equal to its default, so the user might be using the deprecated
// --24-bit-color option.
if let Some(_24_bit_color) = opt._24_bit_color.as_ref() {
opt.true_color = _24_bit_color.clone();
} else {
let empty_builtin_features = HashMap::new();
set_options!(
[true_color],
opt,
&empty_builtin_features,
git_config,
arg_matches,
option_names,
false
);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true_color is present in the main call to set_options! on l.182. I think we need to know why that call is not working -- it feels wrong to make two set_options! calls for true_color.

Copy link
Author

@ghost ghost Aug 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, and sorry. I missed that and found opt.true_color is set correctly (not exact correct because it's not computed into bool) from gitconfig after set_options. I'm maybe going to fix.

}
}

opt.computed.true_color = match opt.true_color.as_ref() {
"always" => true,
"never" => false,
Expand Down Expand Up @@ -726,6 +743,7 @@ pub mod tests {
assert_eq!(opt.side_by_side, true);
assert_eq!(opt.syntax_theme, Some("xxxyyyzzz".to_string()));
assert_eq!(opt.tab_width, 77);
assert_eq!(opt.true_color, "never");
assert_eq!(opt.whitespace_error_style, "black black");
assert_eq!(opt.width, Some("77".to_string()));
assert_eq!(opt.tokenization_regex, "xxxyyyzzz");
Expand Down