summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorryuta69 <eyma22s.yu@gmail.com>2020-09-19 00:00:52 +0900
committerGitHub <noreply@github.com>2020-09-18 11:00:52 -0400
commit3b5c89fcbc6efc2a346dfbd2cc2c49fcdae8a0b0 (patch)
tree24f15c8cfec6cb50d3879e923fb311dac09bcfb4
parentdd88342018aa239c77d7667bc988f0ff5db4610a (diff)
Fix `git add -p` to work when any options enabled (#323)
* Add test for input and output for diff interactive filter * Add color_only in config struct * Refactor should_handle false when color_only and FileMeta, CommitMeta * Refactor handle_hunk_header_line to show raw_text with color_format when color_only * Fix indent * Revert the logic changes for interactive filter * Add color only workaround in set options * Add more test patterns for diff interactive fillter
-rw-r--r--src/delta.rs10
-rw-r--r--src/options/set.rs10
-rw-r--r--src/tests/test_example_diffs.rs44
3 files changed, 54 insertions, 10 deletions
diff --git a/src/delta.rs b/src/delta.rs
index 9c411d8e..7ff70abe 100644
--- a/src/delta.rs
+++ b/src/delta.rs
@@ -380,9 +380,6 @@ fn handle_hunk_header_line(
plus_file: &str,
config: &Config,
) -> std::io::Result<()> {
- if config.hunk_header_style.is_omitted {
- return Ok(());
- }
let decoration_ansi_term_style;
let draw_fn = match config.hunk_header_style.decoration_style {
DecorationStyle::Box(style) => {
@@ -432,7 +429,7 @@ fn handle_hunk_header_line(
config.hunk_header_style,
decoration_ansi_term_style,
)?;
- } else {
+ } else if !config.hunk_header_style.is_omitted {
let line = match painter.prepare(&raw_code_fragment, false) {
s if s.len() > 0 => format!("{} ", s),
s => s,
@@ -466,11 +463,10 @@ fn handle_hunk_header_line(
config.hunk_header_style,
decoration_ansi_term_style,
)?;
- if !config.hunk_header_style.is_raw {
- painter.output_buffer.clear()
- };
+ painter.output_buffer.clear();
}
};
+
// Emit a single line number, or prepare for full line-numbering
if config.line_numbers {
painter
diff --git a/src/options/set.rs b/src/options/set.rs
index a6b4f151..a9ca6be7 100644
--- a/src/options/set.rs
+++ b/src/options/set.rs
@@ -19,8 +19,8 @@ use crate::options::option_value::{OptionValue, ProvenancedOptionValue};
use crate::options::{self, theme};
macro_rules! set_options {
- ([$( $field_ident:ident ),* ],
- $opt:expr, $builtin_features:expr, $git_config:expr, $arg_matches:expr, $expected_option_name_map:expr, $check_names:expr) => {
+ ([$( $field_ident:ident ),* ],
+ $opt:expr, $builtin_features:expr, $git_config:expr, $arg_matches:expr, $expected_option_name_map:expr, $check_names:expr) => {
let mut option_names = HashSet::new();
$(
let kebab_case_field_name = stringify!($field_ident).replace("_", "-");
@@ -59,7 +59,7 @@ macro_rules! set_options {
&option_names - &expected_option_names));
}
}
- }
+ }
}
pub fn set_options(
@@ -192,6 +192,10 @@ pub fn set_options(
// there (does not emit lines in 1-1 correspondence with raw git output). See #274.
if opt.color_only {
opt.side_by_side = false;
+ opt.file_style = "raw".to_string();
+ opt.commit_style = "raw".to_string();
+ opt.hunk_header_style = "raw".to_string();
+ opt.hunk_header_decoration_style = "none".to_string();
}
}
diff --git a/src/tests/test_example_diffs.rs b/src/tests/test_example_diffs.rs
index 9f1a257f..e7a00ee3 100644
--- a/src/tests/test_example_diffs.rs
+++ b/src/tests/test_example_diffs.rs
@@ -836,6 +836,50 @@ src/align.rs
}
#[test]
+ fn test_color_only_output_is_in_one_to_one_correspondence_with_input() {
+ _do_test_output_is_in_one_to_one_correspondence_with_input(&["--color-only", "true"]);
+ _do_test_output_is_in_one_to_one_correspondence_with_input(&[
+ "--color-only",
+ "true",
+ "--file-style",
+ "blue",
+ "--commit-style",
+ "omit",
+ "--hunk-header-style",
+ "omit",
+ "--hunk-header-decoration-style",
+ "omit",
+ ]);
+ _do_test_output_is_in_one_to_one_correspondence_with_input(&[
+ "--color-only",
+ "true",
+ "--file-style",
+ "blue",
+ "--commit-style",
+ "red",
+ "--hunk-header-style",
+ "syntax",
+ "--hunk-header-decoration-style",
+ "box",
+ ]);
+ }
+
+ fn _do_test_output_is_in_one_to_one_correspondence_with_input(args: &[&str]) {
+ let config = integration_test_utils::make_config_from_args(args);
+ let output = integration_test_utils::run_delta(GIT_DIFF_SINGLE_HUNK, &config);
+
+ let output = strip_ansi_codes(&output);
+ let output_lines: Vec<&str> = output.split('\n').collect();
+ let input_lines: Vec<&str> = GIT_DIFF_SINGLE_HUNK.split('\n').collect();
+
+ assert_eq!(input_lines.len(), output_lines.len());
+
+ for n in 0..input_lines.len() {
+ assert_eq!(input_lines[n], output_lines[n]);
+ }
+ }
+
+ #[test]
fn test_hunk_header_style_colored_input_color_is_stripped_under_normal() {
let config = integration_test_utils::make_config_from_args(&[
"--hunk-header-style",