Skip to content

Commit b062679

Browse files
committed
Rename to --diff-opt and --git-opt
Since the former --diff-opts option now only supports one git option per occurrence, the singular --diff-opt naming becomes more appropriate. The former --diff-opts option name remains supported as a hidden alias to ease compatibility with older versions of StGit. For `stg email format` and `stg email send`, the --git-opts option is renamed to --git-opt for the same reason. However, since these are new commands for StGit 2.0, the plural naming is not provided as an alias. This also corrects the zsh completion for --diff-opt to allow multiple occurrences. Ref: #220
1 parent 10b6f7b commit b062679

File tree

10 files changed

+58
-51
lines changed

10 files changed

+58
-51
lines changed

completion/stgit.zsh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ _stg-delete() {
420420
_stg-diff() {
421421
local -a subcmd_args
422422
__stg_add_args_help
423-
__stg_add_args_diffopts
423+
__stg_add_args_diffopt
424424
subcmd_args+=(
425425
'(-r --range)'{-r,--range=}'[show diff between revisions]: :__stg_patchrange --suggest-range --all'
426426
'(-s --stat)'{-s,--stat}'[show stat instead of diff]'
@@ -486,7 +486,7 @@ _stg-email-format() {
486486
__stg_add_args_color
487487
__stg_add_args_branch
488488
subcmd_args+=(
489-
'*'{-G+,--git-opts=}'[extra options for git-format-patch]:opts:__stg_git_format_patch_opts'
489+
'*'{-G+,--git-opt=}'[extra option for git-format-patch]:opt:__stg_git_format_patch_opts'
490490
'(-o --output-directory)'{-o+,--output-directory=}'[store resulting files in given directory]: :_directories'
491491
'(-n --numbered -N --no-numbered -k --keep-subject)'{-n,--numbered}'[name output in \[PATCH n/m\] format]'
492492
'(-n --numbered -N --no-numbered -k --keep-subject)'{-N,--no-numbered}'[name output in \[PATCH\] format]'
@@ -541,7 +541,7 @@ _stg-email-send() {
541541
__stg_add_args_help
542542
__stg_add_args_color
543543
subcmd_args+=(
544-
'*'{-G+,--git-opts=}'[extra options for git-send-email]:opts:__stg_git_send_email_opts'
544+
'*'{-G+,--git-opt=}'[extra option for git-send-email]:opt:__stg_git_send_email_opts'
545545
'--from=[specify sender]:email address:_email_addresses'
546546
'--to=[specify the primary recipient of the emails]: :_email_addresses'
547547
'--cc=[starting Cc: value for each email]: :_email_addresses'
@@ -605,7 +605,7 @@ _stg-export() {
605605
local -a subcmd_args
606606
__stg_add_args_help
607607
__stg_add_args_branch
608-
__stg_add_args_diffopts
608+
__stg_add_args_diffopt
609609
subcmd_args+=(
610610
'(-d --dir)'{-d,--dir}'[export patches to directory]: :_directories'
611611
'(-n --numbered)'{-n,--numbered}'[prefix patch names with order numbers]'
@@ -786,7 +786,7 @@ _stg-patches() {
786786
local -a subcmd_args
787787
__stg_add_args_help
788788
__stg_add_args_branch
789-
__stg_add_args_diffopts
789+
__stg_add_args_diffopt
790790
subcmd_args+=(
791791
'(-d --diff)'{-d,--diff}'[show diffs of given files]'
792792
'*:files:__stg_cached_files'
@@ -901,7 +901,7 @@ _stg-refresh() {
901901
__stg_add_args_edit
902902
__stg_add_args_hook
903903
__stg_add_args_trailers
904-
__stg_add_args_diffopts
904+
__stg_add_args_diffopt
905905
subcmd_args+=(
906906
'(-a --annotate)'{-a,--annotate=}'[annotate patch log entry]:note'
907907
'(-d --diff)'{-d,--diff}'[show diff when editing patch message]'
@@ -984,7 +984,7 @@ _stg-show() {
984984

985985
__stg_add_args_help
986986
__stg_add_args_branch
987-
__stg_add_args_diffopts
987+
__stg_add_args_diffopt
988988
subcmd_args+=(
989989
'(*)'{-p,--patch=}'[patch or revision to show]: :__stg_dedup_inside_arguments __stg_patchrange --all'
990990
'(-s --stat)'{-s,--stat}'[show diff stat]'
@@ -1148,10 +1148,9 @@ __stg_add_args_color() {
11481148
)
11491149
}
11501150

1151-
__stg_add_args_diffopts() {
1152-
# TODO: complete diff-opts values (with separators?)
1151+
__stg_add_args_diffopt() {
11531152
subcmd_args+=(
1154-
'(-O --diff-opts)'{-O+,--diff-opts=}'[extra options for git diff]:opts:__stg_git_diff_opts'
1153+
'*'{-O+,--diff-opt=}'[extra option for git diff]:opt:__stg_git_diff_opts'
11551154
)
11561155
}
11571156

@@ -1211,7 +1210,7 @@ __stg_git_diff_opts() {
12111210
words=('git' ${(@)__stg_C_args} 'diff-tree')
12121211
# Needs a way to know word indices for opt_args values to only provide through CURRENT.
12131212
#
1214-
# words+=(${(0)opt_args[-O]} ${(0)opt_args[--diff-opts]})
1213+
# words+=(${(0)opt_args[-O]} ${(0)opt_args[--diff-opt]})
12151214
words+=("$PREFIX$SUFFIX")
12161215
(( CURRENT = $#words ))
12171216

@@ -1225,7 +1224,7 @@ __stg_git_format_patch_opts() {
12251224
words=('git' ${(@)__stg_C_args} 'format-patch')
12261225
# Needs a way to know word indices for opt_args values to only provide through CURRENT.
12271226
#
1228-
# words+=(${(0)opt_args[-G]} ${(0)opt_args[--git-opts]})
1227+
# words+=(${(0)opt_args[-G]} ${(0)opt_args[--git-opt]})
12291228
words+=("$PREFIX$SUFFIX")
12301229
(( CURRENT = $#words ))
12311230

@@ -1239,7 +1238,7 @@ __stg_git_send_email_opts() {
12391238
words=('git' ${(@)__stg_C_args} 'send-email')
12401239
# Needs a way to know word indices for opt_args values to only provide through CURRENT.
12411240
#
1242-
# words+=(${(0)opt_args[-G]} ${(0)opt_args[--git-opts]})
1241+
# words+=(${(0)opt_args[-G]} ${(0)opt_args[--git-opt]})
12431242
words+=("$PREFIX$SUFFIX")
12441243
(( CURRENT = $#words ))
12451244

examples/gitconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
#namelength = 30
8080

8181
# Extra options to pass to "git diff" (extend/override with
82-
# -O/--diff-opts). For example, -M turns on rename detection.
82+
# -O/--diff-opt). For example, -M turns on rename detection.
8383
#diff-opts = -M
8484

8585
# Behave as if the --keep option is always passed

src/argset.rs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,23 @@ pub(crate) fn merged_arg() -> Arg {
3434
.action(clap::ArgAction::SetTrue)
3535
}
3636

37-
/// The `--diff-opts`/`-O` option for pass-through to subordinate `git` processes.
37+
/// The `--diff-opt`/`-O` option for pass-through to subordinate `git` processes.
3838
pub(crate) fn diff_opts_arg() -> Arg {
39-
Arg::new("git-diff-opts")
40-
.long("diff-opts")
39+
Arg::new("git-diff-opt")
40+
.long("diff-opt")
41+
.alias("diff-opts")
4142
.short('O')
42-
.help("Extra options to pass to \"git diff\"")
43+
.help("Pass additional <option> to \"git diff\"")
4344
.long_help(
44-
"Pass additional options <git-diff-options> to `git diff`. \
45-
See the git-diff(1) man page.",
45+
"Pass additional <option> to \"git diff\".\n\
46+
\n\
47+
See the git-diff(1) man page. This option may be specified multiple \
48+
times.",
4649
)
4750
.num_args(1)
4851
.allow_hyphen_values(true)
4952
.action(clap::ArgAction::Append)
50-
.value_name("git-diff-options")
53+
.value_name("option")
5154
.value_hint(clap::ValueHint::Other)
5255
}
5356

@@ -84,7 +87,7 @@ pub(crate) fn parse_usize(s: &str) -> anyhow::Result<usize> {
8487
/// diff options.
8588
///
8689
/// The base set of options come from `stgit.diff-opts` in the config. Additional
87-
/// options from `--diff-opts`/`-O` command line options are appended. And StGit
90+
/// options from `--diff-opt`/`-O` command line options are appended. And StGit
8891
/// command-specific policies for displaying the full object id (`--full-index`) and
8992
/// including binary diffs (`--binary`) are tacked on at the end.
9093
///
@@ -104,7 +107,7 @@ pub(crate) fn get_diff_opts(
104107
}
105108
}
106109

107-
if let Some(values) = matches.get_many::<String>("git-diff-opts") {
110+
if let Some(values) = matches.get_many::<String>("git-diff-opt") {
108111
opts.extend(values.cloned());
109112
}
110113

src/cmd/completion/bash.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,12 +219,12 @@ fn insert_compreply(script: &mut ShStream, arg: &clap::Arg) {
219219
"committish" => script.line(
220220
"mapfile -t COMPREPLY < <(compgen -W \"$(_all_branches) $(_tags) $(_remotes)\")",
221221
),
222-
"git-diff-opts" => script
222+
"git-diff-opt" => script
223223
.line("mapfile -t COMPREPLY < <(compgen -W \"$(_git_diff_opts)\" -- \"$cur\")"),
224-
"git-format-patch-opts" => script.line(
224+
"git-format-patch-opt" => script.line(
225225
"mapfile -t COMPREPLY < <(compgen -W \"$(_git_format_patch_opts)\" -- \"$cur\")",
226226
),
227-
"git-send-email-opts" => script.line(
227+
"git-send-email-opt" => script.line(
228228
"mapfile -t COMPREPLY < <(compgen -W \"$(_git_send_email_opts)\" -- \"$cur\")",
229229
),
230230
"patch" => script

src/cmd/completion/fish.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ fn get_arg_completion_params(arg: &clap::Arg) -> ShStream {
363363
"branch" | "ref-branch" => params.word("-xa '(__fish_stg_stg_branches)'"),
364364
"branch-any" => params.word("-xa '(__fish_stg_all_branches)'"),
365365
"committish" => params.word("-xa '(__fish_stg_commit)'"),
366-
"git-diff-opts" => params.word("-xa '(__fish_stg_git_diff_opts)'"),
366+
"git-diff-opt" => params.word("-xa '(__fish_stg_git_diff_opts)'"),
367367
"git-format-patch-opts" => params.word("-xa '(__fish_stg_git_format_patch_opts)'"),
368368
"git-send-email-opts" => params.word("-xa '(__fish_stg_git_send_email_opts)'"),
369369
"patch" | "patchranges" => params.word("-kxa '(__fish_stg_patches -A -U)'"),

src/cmd/email/format.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,19 @@ pub(super) fn command() -> clap::Command {
6868
.action(clap::ArgAction::SetTrue),
6969
)
7070
.arg(
71-
Arg::new("git-format-patch-opts")
72-
.long("git-opts")
71+
Arg::new("git-format-patch-opt")
72+
.long("git-opt")
7373
.short('G')
74-
.help("Extra options to pass to \"git format-patch\"")
74+
.help("Pass additional <option> to \"git format-patch\"")
7575
.long_help(
76-
"Pass additional options <git-options> to `git format-patch`. \
77-
See the git-format-patch(1) man page.",
76+
"Pass additional <option> to \"git format-patch\".\n\
77+
\n\
78+
See the git-format-patch(1) man page. This option may be \
79+
specified multiple times.",
7880
)
7981
.allow_hyphen_values(true)
8082
.action(clap::ArgAction::Append)
81-
.value_name("git-options"),
83+
.value_name("option"),
8284
)
8385
.next_help_heading("Format Options")
8486
.args(format_options())
@@ -505,7 +507,7 @@ pub(super) fn dispatch(matches: &clap::ArgMatches) -> Result<()> {
505507

506508
let mut format_args = format_args.drain(..).map(|(_, s)| s).collect::<Vec<_>>();
507509

508-
if let Some(values) = matches.get_many::<String>("git-format-patch-opts") {
510+
if let Some(values) = matches.get_many::<String>("git-format-patch-opt") {
509511
format_args.extend(values.cloned());
510512
}
511513

src/cmd/email/send.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,19 @@ pub(super) fn command() -> clap::Command {
7575
.conflicts_with_all(["patchranges-or-paths", "dump-aliases"]),
7676
)
7777
.arg(
78-
Arg::new("git-send-email-opts")
79-
.long("git-opts")
78+
Arg::new("git-send-email-opt")
79+
.long("git-opt")
8080
.short('G')
81-
.help("Extra options to pass to \"git send-email\"")
81+
.help("Pass additional <option> to \"git send-email\"")
8282
.long_help(
83-
"Pass additional options <git-options> to `git send-email`. \
84-
See the git-send-email(1) man page.",
83+
"Pass additional <option> to \"git send-email\".\n\
84+
\n\
85+
See the git-send-email(1) man page. This option may be specified \
86+
multiple times.",
8587
)
8688
.allow_hyphen_values(true)
8789
.action(clap::ArgAction::Append)
88-
.value_name("git-options"),
90+
.value_name("option"),
8991
)
9092
.next_help_heading("Compose Options")
9193
.args(compose_options())
@@ -458,7 +460,7 @@ pub(super) fn dispatch(matches: &clap::ArgMatches) -> Result<()> {
458460

459461
let mut send_args = send_args.drain(..).map(|(_, s)| s).collect::<Vec<_>>();
460462

461-
if let Some(values) = matches.get_many::<String>("git-send-email-opts") {
463+
if let Some(values) = matches.get_many::<String>("git-send-email-opt") {
462464
send_args.extend(values.cloned());
463465
}
464466

t/t0005-show.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ test_expect_success 'Show patch' '
3838
'
3939

4040
test_expect_success 'Bad diff opts' '
41-
command_error stg show --diff-opts=--this-is-bad 2>err &&
41+
command_error stg show --diff-opt=--this-is-bad 2>err &&
4242
grep -e "unrecognized argument: --this-is-bad" err
4343
'
4444

4545
test_expect_success 'Multiple diff opts' '
46-
stg show --diff-opts=--shortstat --diff-opts="--name-only" patch-bbb |
47-
grep -e "foo.txt"
46+
stg show --diff-opt=--line-prefix="A B C " --diff-opt="--name-only" patch-bbb >out &&
47+
grep -e "A B C foo.txt" out
4848
'
4949

5050
test_expect_success 'Diff opts from config' '

t/t0006-patches.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ test_expect_success 'With diff output' '
7878
test $(cat even-diff.log | grep -c -E "p(0|1|3) message") = "3"
7979
'
8080

81-
test_expect_success 'With diff output and diff-opts' '
82-
stg patches --diff-opts=--abbrev -O --name-only --diff even.txt > even-diff2.log
81+
test_expect_success 'With diff output and diff-opt' '
82+
stg patches --diff-opt=--abbrev -O --name-only --diff even.txt > even-diff2.log
8383
test $(cat even-diff2.log | grep -c -E "even.txt") = "3"
8484
test $(cat even-diff2.log | grep -c -E "p(0|1|3) message") = "3"
8585
'

t/t2400-diff.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ test_expect_success 'Diff stat with some local changes' '
3333
test_cmp add-foo-stat.diff expected-add-foo-stat.diff
3434
'
3535

36-
test_expect_success 'Diff with bad diff-opts' '
37-
command_error stg diff --diff-opts=--bad-diff-opt
36+
test_expect_success 'Diff with bad diff-opt' '
37+
command_error stg diff --diff-opt=--bad-diff-opt
3838
'
3939

4040
test_expect_success 'Initialize StGit stuff' '
@@ -47,8 +47,9 @@ test_expect_success 'Diff with some local changes' '
4747
test_cmp add-foo.diff add-foo2.diff
4848
'
4949

50-
test_expect_success 'Diff with multiple diff-opts' '
51-
stg diff --diff-opts=--shortstat -O --name-only | grep -e "foo.txt"
50+
test_expect_success 'Diff with multiple diff-opt' '
51+
stg diff --diff-opt=--line-prefix="A B C " -O --name-only >out &&
52+
grep -e "A B C foo.txt" out
5253
'
5354

5455
test_expect_success 'Refresh patch' '
@@ -179,7 +180,7 @@ test_expect_success 'Binary diff range' '
179180
'
180181

181182
test_expect_success 'Binary diff range with --binary' '
182-
stg diff -r p5..p6 --diff-opts=--binary > num-binary2.diff &&
183+
stg diff -r p5..p6 --diff-opt=--binary > num-binary2.diff &&
183184
test_cmp num-binary.diff num-binary2.diff
184185
'
185186

0 commit comments

Comments
 (0)