-
Notifications
You must be signed in to change notification settings - Fork 352
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
base: main
Are you sure you want to change the base?
Implement --diff-args #1697
Conversation
c6fdfb9
to
71473d5
Compare
#[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, | ||
|
There was a problem hiding this comment.
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 ...
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 { |
There was a problem hiding this comment.
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).
|
||
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(); |
There was a problem hiding this comment.
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.
Allow extra arguments to
git diff
to be passed from the delta commands line, as suggested by @calestyo in #1644 (comment)E.g.
Note that the
=
is required in this case, due to the-
that comes next.