Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement --diff-args #1697

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Implement --diff-args #1697

wants to merge 1 commit into from

Conversation

dandavison
Copy link
Owner

@dandavison dandavison commented May 7, 2024

Allow extra arguments to git diff to be passed from the delta commands line, as suggested by @calestyo in #1644 (comment)

E.g.

delta --diff-args=-U99 /tmp/a /tmp/b
delta -@=-U99 /tmp/a /tmp/b

Note that the = is required in this case, due to the - that comes next.

Comment on lines +320 to +334
#[arg(
long = "diff-args",
short = '@',
default_value = "",
value_name = "STRING"
)]
/// 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 -U999 --no-index --color file_1 file_2 | delta`.
///
/// However, if you use process substitution instead of real file paths, it falls back to `diff -u` instead of `git
/// diff`.
pub diff_args: String,

Copy link
Contributor

@th1000s th1000s May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's actually a good use of the unique -@ argument.

Wording: "Arguments" -> "Extra arguments", -U999 comes after --color, and give a brief example of process substitution:

... process substitution (`delta <(grep a file_1) <(cmd_2)`) instead of ...

Comment on lines 26 to 28
let diff_cmd = if via_process_substitution(minus_file) || via_process_substitution(plus_file) {
["diff", "-u", "--"].as_slice()
format!("diff -u {} --", config.diff_args)
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff's -u (defaults to 3 context) will override a following -U<N> (GNU diffutils at least), so replace with -U3 which can be overwritten (and adapt help output above).

Comment on lines 42 to 47

let diff_process = process::Command::new(diff_path)
.args(&diff_cmd[1..])
.args(diff_cmd)
.args([minus_file, plus_file])
.stdout(process::Stdio::piped())
.spawn();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git diff --no-index --nonsense will exit with 129 and first print error: unknown option 'nonsense' and then the full --help output. Maybe catch such cases (diff will just exit with 2) and print the actual (quoted, in case split_whitespace() was the culprit) command delta called.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants