Skip to content

Commit

Permalink
Support passing arguments to git diff and diff (#1697)
Browse files Browse the repository at this point in the history
Adds --diff-args with short form -@.
  • Loading branch information
dandavison authored Aug 15, 2024
1 parent a01141b commit 5c53c5e
Show file tree
Hide file tree
Showing 9 changed files with 426 additions and 71 deletions.
197 changes: 197 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ unexpected_cfgs = { level = "warn", check-cfg = ['cfg(tarpaulin_include)'] }

[dev-dependencies]
insta = { version = "1.*", features = ["colors", "filters"] }
rstest = "0.21.0"

[profile.test]
opt-level = 2
Expand Down
19 changes: 17 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,21 @@ pub struct Opt {
#[arg(long = "detect-dark-light", value_enum, default_value_t = DetectDarkLight::default())]
pub detect_dark_light: DetectDarkLight,

#[arg(
long = "diff-args",
short = '@',
default_value = "",
value_name = "STRING"
)]
/// Extra arguments to pass to `git diff` when using delta to diff two files.
///
/// E.g. `delta --diff-args=-U999 file_1 file_2` is equivalent to
/// `git diff --no-index --color -U999 file_1 file_2 | delta`.
///
/// If you use process substitution (`delta <(command_1) <(command_2)`) and your git version
/// doesn't support it, then delta will fall back to `diff` instead of `git diff`.
pub diff_args: String,

#[arg(long = "diff-highlight")]
/// Emulate diff-highlight.
///
Expand Down Expand Up @@ -960,12 +975,12 @@ pub struct Opt {
/// Deprecated: use --true-color.
pub _24_bit_color: Option<String>,

/// First file to be compared when delta is being used in diff mode
/// First file to be compared when delta is being used to diff two files.
///
/// `delta file1 file2` is equivalent to `diff -u file1 file2 | delta`.
pub minus_file: Option<PathBuf>,

/// Second file to be compared when delta is being used in diff mode.
/// Second file to be compared when delta is being used to diff two files.
pub plus_file: Option<PathBuf>,

#[arg(skip)]
Expand Down
2 changes: 2 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub struct Config {
pub cwd_relative_to_repo_root: Option<String>,
pub decorations_width: cli::Width,
pub default_language: String,
pub diff_args: String,
pub diff_stat_align_width: usize,
pub error_exit_code: i32,
pub file_added_label: String,
Expand Down Expand Up @@ -298,6 +299,7 @@ impl From<cli::Opt> for Config {
cwd_relative_to_repo_root,
decorations_width: opt.computed.decorations_width,
default_language: opt.default_language,
diff_args: opt.diff_args,
diff_stat_align_width: opt.diff_stat_align_width,
error_exit_code: 2, // Use 2 for error because diff uses 0 and 1 for non-error.
file_added_label,
Expand Down
1 change: 1 addition & 0 deletions src/options/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pub fn set_options(
commit_regex,
commit_style,
default_language,
diff_args,
diff_stat_align_width,
file_added_label,
file_copied_label,
Expand Down
Loading

0 comments on commit 5c53c5e

Please sign in to comment.