mirror of
https://github.com/sharkdp/bat.git
synced 2025-09-22 21:22:27 +01:00
Only leave space for git diff markers if any line is modified (#3406)
Previously, setting `--style=changes` would always print a 2-space indent, even if the file was unmodified. This changes the style to only print an indent if there is at least one +/- git marker in the sidebar.
This commit is contained in:
@@ -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("");
|
||||
|
Reference in New Issue
Block a user