From f52ca706f3a6c6fb31ea31856534a8b56c153095 Mon Sep 17 00:00:00 2001 From: Wilfred Hughes Date: Tue, 9 Apr 2024 08:34:58 -0700 Subject: [PATCH] Enable --strip-cr by default Line ending differences between input files often leads to confusing diffs, so remove carriage returns unless explicitly requested. Fixes #653 Fixes #696 --- CHANGELOG.md | 6 ++++++ src/options.rs | 7 +++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d253ef589..00622088d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ ## 0.58 (unreleased) +### Diffing + +`--strip-cr` now defaults to `on`, so comparing a file with CRLF +endings with a file with unix line endings will not show spurious +changes. + ## 0.57 (released 1st April 2024) ### Parsing diff --git a/src/options.rs b/src/options.rs index eefc1c93d..2e2af3eac 100644 --- a/src/options.rs +++ b/src/options.rs @@ -208,8 +208,11 @@ json: Output the results as a machine-readable JSON array with an element per fi ) .arg( Arg::new("strip-cr").long("strip-cr") + .value_name("on/off") .env("DFT_STRIP_CR") - .help("Remove any carriage return characters before diffing. This can be helpful when dealing with files on Windows that contain CRLF, i.e. `\\r\\n`.") + .possible_values(["on", "off"]) + .default_value("on") + .help("Remove any carriage return characters before diffing. This can be helpful when dealing with files on Windows that contain CRLF, i.e. `\\r\\n`.\n\nWhen disabled, difftastic will consider multiline string literals (in code) or mutiline text (e.g. in HTML) to differ if the two input files have different line endings.") ) .arg( Arg::new("check-only").long("check-only") @@ -717,7 +720,7 @@ pub(crate) fn parse_args() -> Mode { let set_exit_code = matches.is_present("exit-code"); - let strip_cr = matches.is_present("strip-cr"); + let strip_cr = matches.value_of("strip-cr") == Some("on"); let check_only = matches.is_present("check-only");