diff --git a/CHANGELOG.md b/CHANGELOG.md index 10834e95..5419c6fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - Send all bat errors to stderr by default, see #3336 (@JerryImMouse) - Make --map-syntax target case insensitive to match --language, see #3206 (@keith-hall) - Correctly determine the end of the line in UTF16LE/BE input #3369 (@keith-hall) +- `--style=changes` no longer prints a two-space indent when the file is unmodified, see issue #2710 and PR #3406 (@jyn514) ## Other diff --git a/src/printer.rs b/src/printer.rs index 665871b4..a28cb190 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -227,7 +227,9 @@ impl<'a> InteractivePrinter<'a> { #[cfg(feature = "git")] { - if config.style_components.changes() { + if config.style_components.changes() + && line_changes.as_ref().is_some_and(|c| !c.is_empty()) + { decorations.push(Box::new(LineChangesDecoration::new(&colors))); } } diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index d9f8b403..f0ebef12 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -1854,11 +1854,11 @@ fn header_default() { .success() .stdout( "\ -───────┬──────────────────────────────────────────────────────────────────────── - │ File: single-line.txt -───────┼──────────────────────────────────────────────────────────────────────── - 1 │ Single Line -───────┴──────────────────────────────────────────────────────────────────────── +─────┬────────────────────────────────────────────────────────────────────────── + │ File: single-line.txt +─────┼────────────────────────────────────────────────────────────────────────── + 1 │ Single Line +─────┴────────────────────────────────────────────────────────────────────────── ", ) .stderr(""); @@ -1878,16 +1878,31 @@ fn header_default_is_default() { .success() .stdout( "\ -───────┬──────────────────────────────────────────────────────────────────────── - │ File: single-line.txt -───────┼──────────────────────────────────────────────────────────────────────── - 1 │ Single Line -───────┴──────────────────────────────────────────────────────────────────────── +─────┬────────────────────────────────────────────────────────────────────────── + │ File: single-line.txt +─────┼────────────────────────────────────────────────────────────────────────── + 1 │ Single Line +─────┴────────────────────────────────────────────────────────────────────────── ", ) .stderr(""); } +#[test] +#[cfg(feature = "git")] // Expected output assumes git is enabled + // Make sure indent isn't printed if there's no changes +fn header_and_changes_only() { + bat() + .arg("--style=header-filename,changes") + .arg("--decorations=always") + .arg("--color=never") + .arg("single-line.txt") + .assert() + .success() + .stdout("File: single-line.txt\nSingle Line\n") + .stderr(""); +} + #[test] fn filename_stdin() { bat() @@ -2282,12 +2297,12 @@ fn grid_for_file_without_newline() { .success() .stdout( "\ -───────┬──────────────────────────────────────────────────────────────────────── - │ File: single-line.txt - │ Size: 11 B -───────┼──────────────────────────────────────────────────────────────────────── - 1 │ Single Line -───────┴──────────────────────────────────────────────────────────────────────── +─────┬────────────────────────────────────────────────────────────────────────── + │ File: single-line.txt + │ Size: 11 B +─────┼────────────────────────────────────────────────────────────────────────── + 1 │ Single Line +─────┴────────────────────────────────────────────────────────────────────────── ", ) .stderr("");