completion: add more parameter value completion
This adds value completion for a couple more paramters. To make it easier to maintain these hard coded lists, add a comment at the original list/code to remind people to update git-completion.bash too. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Feb 16, 2019 at 18:24 UTC
5a59a2301f6ec9bcf1b101edb9ca33beb465842f
18 files changed
+126
-4
apply.c
+4
@@ -56,6 +56,10 @@ static int parse_whitespace_option(struct apply_state *state, const char *option
56
state->ws_error_action = correct_ws_error;
57
return 0;
58
}
59
+ /*
60
+ * Please update $__git_whitespacelist in git-completion.bash
61
+ * when you add new options.
62
+ */
63
return error(_("unrecognized whitespace option '%s'"), option);
64
}
65
builtin/am.c
+4
@@ -2119,6 +2119,10 @@ static int parse_opt_patchformat(const struct option *opt, const char *arg, int
2119
*opt_value = PATCH_FORMAT_HG;
2120
else if (!strcmp(arg, "mboxrd"))
2121
*opt_value = PATCH_FORMAT_MBOXRD;
2122
+ /*
2123
+ * Please update $__git_patchformat in git-completion.bash
2124
+ * when you add new options
2125
+ */
2126
else
2127
return error(_("Invalid value for --patch-format: %s"), arg);
2128
return 0;
builtin/commit.c
+8
@@ -1038,6 +1038,10 @@ static void handle_untracked_files_arg(struct wt_status *s)
1038
s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
1039
else if (!strcmp(untracked_files_arg, "all"))
1040
s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
1041
+ /*
1042
+ * Please update $__git_untracked_file_modes in
1043
+ * git-completion.bash when you add new options
1044
+ */
1045
else
1046
die(_("Invalid untracked files mode '%s'"), untracked_files_arg);
1047
}
@@ -1179,6 +1183,10 @@ static int parse_and_validate_options(int argc, const char *argv[],
1183
else if (!strcmp(cleanup_arg, "scissors"))
1184
cleanup_mode = use_editor ? COMMIT_MSG_CLEANUP_SCISSORS :
1185
COMMIT_MSG_CLEANUP_SPACE;
1186
+ /*
1187
+ * Please update _git_commit() in git-completion.bash when you
1188
+ * add new options.
1189
+ */
1190
else
1191
die(_("Invalid cleanup mode %s"), cleanup_arg);
1192
builtin/help.c
+4
@@ -70,6 +70,10 @@ static enum help_format parse_help_format(const char *format)
70
return HELP_FORMAT_INFO;
71
if (!strcmp(format, "web") || !strcmp(format, "html"))
72
return HELP_FORMAT_WEB;
73
+ /*
74
+ * Please update _git_config() in git-completion.bash when you
75
+ * add new help formats.
76
+ */
77
die(_("unrecognized help format '%s'"), format);
78
}
79
builtin/log.c
+8
@@ -84,6 +84,10 @@ static int parse_decoration_style(const char *value)
84
return DECORATE_SHORT_REFS;
85
else if (!strcmp(value, "auto"))
86
return auto_decoration_style();
87
+ /*
88
+ * Please update _git_log() in git-completion.bash when you
89
+ * add new decoration styles.
90
+ */
91
return -1;
92
}
93
@@ -1228,6 +1232,10 @@ static int thread_callback(const struct option *opt, const char *arg, int unset)
1232
*thread = THREAD_SHALLOW;
1233
else if (!strcmp(arg, "deep"))
1234
*thread = THREAD_DEEP;
1235
+ /*
1236
+ * Please update _git_formatpatch() in git-completion.bash
1237
+ * when you add new options.
1238
+ */
1239
else
1240
return 1;
1241
return 0;
builtin/pull.c
+4
@@ -56,6 +56,10 @@ static enum rebase_type parse_config_rebase(const char *key, const char *value,
56
return REBASE_MERGES;
57
else if (!strcmp(value, "interactive") || !strcmp(value, "i"))
58
return REBASE_INTERACTIVE;
59
+ /*
60
+ * Please update _git_config() in git-completion.bash when you
61
+ * add new rebase modes.
62
+ */
63
64
if (fatal)
65
die(_("Invalid value for %s: %s"), key, value);
builtin/replace.c
+4
@@ -82,6 +82,10 @@ static int list_replace_refs(const char *pattern, const char *format)
82
data.format = REPLACE_FORMAT_MEDIUM;
83
else if (!strcmp(format, "long"))
84
data.format = REPLACE_FORMAT_LONG;
85
+ /*
86
+ * Please update _git_replace() in git-completion.bash when
87
+ * you add new format
88
+ */
89
else
90
return error(_("invalid replace format '%s'\n"
91
"valid formats are 'short', 'medium' and 'long'"),
contrib/completion/git-completion.bash
+40
-3
@@ -853,6 +853,11 @@ __git_compute_merge_strategies ()
853
__git_merge_strategies=$(__git_list_merge_strategies)
854
}
855
856
+__git_merge_strategy_options="ours theirs subtree subtree= patience
857
+ histogram diff-algorithm= ignore-space-change ignore-all-space
858
+ ignore-space-at-eol renormalize no-renormalize no-renames
859
+ find-renames find-renames= rename-threshold="
860
+
861
__git_complete_revlist_file ()
862
{
863
local dequoted_word pfx ls ref cur_="$cur"
@@ -996,12 +1001,21 @@ __git_complete_strategy ()
1001
-s|--strategy)
1002
__gitcomp "$__git_merge_strategies"
1003
return 0
1004
+ ;;
1005
+ -X)
1006
+ __gitcomp "$__git_merge_strategy_options"
1007
+ return 0
1008
+ ;;
1009
esac
1010
case "$cur" in
1011
--strategy=*)
1012
__gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
1013
return 0
1014
;;
1015
+ --strategy-option=*)
1016
+ __gitcomp "$__git_merge_strategy_options" "" "${cur##--strategy-option=}"
1017
+ return 0
1018
+ ;;
1019
esac
1020
return 1
1021
}
@@ -1163,6 +1177,7 @@ __git_count_arguments ()
1177
}
1178
1179
__git_whitespacelist="nowarn warn error error-all fix"
1180
+__git_patchformat="mbox stgit stgit-series hg mboxrd"
1181
__git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
1182
1183
_git_am ()
@@ -1177,6 +1192,10 @@ _git_am ()
1192
__gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
1193
return
1194
;;
1195
+ --patch-format=*)
1196
+ __gitcomp "$__git_patchformat" "" "${cur##--patch-format=}"
1197
+ return
1198
+ ;;
1199
--*)
1200
__gitcomp_builtin am "" \
1201
"$__git_am_inprogress_options"
@@ -1200,6 +1219,10 @@ _git_apply ()
1219
_git_add ()
1220
{
1221
case "$cur" in
1222
+ --chmod=*)
1223
+ __gitcomp "+x -x" "" "${cur##--chmod=}"
1224
+ return
1225
+ ;;
1226
--*)
1227
__gitcomp_builtin add
1228
return
@@ -1260,6 +1283,8 @@ _git_bisect ()
1283
esac
1284
}
1285
1286
+__git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD symref"
1287
+
1288
_git_branch ()
1289
{
1290
local i c=1 only_local_ref="n" has_r="n"
@@ -1343,6 +1368,9 @@ _git_cherry_pick ()
1368
__gitcomp "$__git_cherry_pick_inprogress_options"
1369
return
1370
fi
1371
+
1372
+ __git_complete_strategy && return
1373
+
1374
case "$cur" in
1375
--*)
1376
__gitcomp_builtin cherry-pick "" \
@@ -1506,6 +1534,10 @@ _git_fetch ()
1534
__gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
1535
return
1536
;;
1537
+ --filter=*)
1538
+ __gitcomp "blob:none blob:limit= sparse:oid= sparse:path=" "" "${cur##--filter=}"
1539
+ return
1540
+ ;;
1541
--*)
1542
__gitcomp_builtin fetch
1543
return
@@ -1702,8 +1734,8 @@ __git_log_shortlog_options="
1734
--all-match --invert-grep
1735
"
1736
1705
-__git_log_pretty_formats="oneline short medium full fuller email raw format:"
1706
-__git_log_date_formats="relative iso8601 rfc2822 short local default raw"
1737
+__git_log_pretty_formats="oneline short medium full fuller email raw format: mboxrd"
1738
+__git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default raw unix format:"
1739
1740
_git_log ()
1741
{
@@ -2221,7 +2253,7 @@ _git_config ()
2253
return
2254
;;
2255
diff.submodule)
2224
- __gitcomp "log short"
2256
+ __gitcomp "$__git_diff_submodule_formats"
2257
return
2258
;;
2259
help.format)
@@ -2388,6 +2420,10 @@ _git_remote ()
2420
_git_replace ()
2421
{
2422
case "$cur" in
2423
+ --format=*)
2424
+ __gitcomp "short medium long" "" "${cur##--format=}"
2425
+ return
2426
+ ;;
2427
--*)
2428
__gitcomp_builtin replace
2429
return
@@ -2429,6 +2465,7 @@ _git_revert ()
2465
__gitcomp "$__git_revert_inprogress_options"
2466
return
2467
fi
2468
+ __git_complete_strategy && return
2469
case "$cur" in
2470
--*)
2471
__gitcomp_builtin revert "" \
date.c
+4
@@ -921,6 +921,10 @@ static enum date_mode_type parse_date_type(const char *format, const char **end)
921
return DATE_UNIX;
922
if (skip_prefix(format, "format", end))
923
return DATE_STRFTIME;
924
+ /*
925
+ * Please update $__git_log_date_formats in
926
+ * git-completion.bash when you add new formats.
927
+ */
928
929
die("unknown date format %s", format);
930
}
diff.c
+8
@@ -178,6 +178,10 @@ static int parse_submodule_params(struct diff_options *options, const char *valu
178
options->submodule_format = DIFF_SUBMODULE_SHORT;
179
else if (!strcmp(value, "diff"))
180
options->submodule_format = DIFF_SUBMODULE_INLINE_DIFF;
181
+ /*
182
+ * Please update $__git_diff_submodule_formats in
183
+ * git-completion.bash when you add new formats.
184
+ */
185
else
186
return -1;
187
return 0;
@@ -204,6 +208,10 @@ long parse_algorithm_value(const char *value)
208
return XDF_PATIENCE_DIFF;
209
else if (!strcasecmp(value, "histogram"))
210
return XDF_HISTOGRAM_DIFF;
211
+ /*
212
+ * Please update $__git_diff_algorithms in git-completion.bash
213
+ * when you add new algorithms.
214
+ */
215
return -1;
216
}
217
git-send-email.perl
+6
@@ -465,6 +465,8 @@ $smtp_encryption = '' unless (defined $smtp_encryption);
465
my(%suppress_cc);
466
if (@suppress_cc) {
467
foreach my $entry (@suppress_cc) {
468
+ # Please update $__git_send_email_suppresscc_options
469
+ # in git-completion.bash when you add new options.
470
die sprintf(__("Unknown --suppress-cc field: '%s'\n"), $entry)
471
unless $entry =~ /^(?:all|cccmd|cc|author|self|sob|body|bodycc|misc-by)$/;
472
$suppress_cc{$entry} = 1;
@@ -494,6 +496,8 @@ my $confirm_unconfigured = !defined $confirm;
496
if ($confirm_unconfigured) {
497
$confirm = scalar %suppress_cc ? 'compose' : 'auto';
498
};
499
+# Please update $__git_send_email_confirm_options in
500
+# git-completion.bash when you add new options.
501
die sprintf(__("Unknown --confirm setting: '%s'\n"), $confirm)
502
unless $confirm =~ /^(?:auto|cc|compose|always|never)/;
503
@@ -587,6 +591,8 @@ my %parse_alias = (
591
if (/\(define-mail-alias\s+"(\S+?)"\s+"(\S+?)"\)/) {
592
$aliases{$1} = [ $2 ];
593
}}}
594
+ # Please update _git_config() in git-completion.bash when you
595
+ # add new MUAs.
596
);
597
598
if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) {
list-objects-filter-options.c
+4
@@ -82,6 +82,10 @@ static int gently_parse_list_objects_filter(
82
filter_options->sparse_path_value = strdup(v0);
83
return 0;
84
}
85
+ /*
86
+ * Please update _git_fetch() in git-completion.bash when you
87
+ * add new filters
88
+ */
89
90
if (errbuf)
91
strbuf_addf(errbuf, "invalid filter-spec '%s'", arg);
merge-recursive.c
+4
@@ -3764,6 +3764,10 @@ int parse_merge_opt(struct merge_options *o, const char *s)
3764
return -1;
3765
o->merge_detect_rename = 1;
3766
}
3767
+ /*
3768
+ * Please update $__git_merge_strategy_options in
3769
+ * git-completion.bash when you add new options
3770
+ */
3771
else
3772
return -1;
3773
return 0;
pretty.c
+4
@@ -98,6 +98,10 @@ static void setup_commit_formats(void)
98
{ "fuller", CMIT_FMT_FULLER, 0, 8 },
99
{ "full", CMIT_FMT_FULL, 0, 8 },
100
{ "oneline", CMIT_FMT_ONELINE, 1, 0 }
101
+ /*
102
+ * Please update $__git_log_pretty_formats in
103
+ * git-completion.bash when you add new formats.
104
+ */
105
};
106
commit_formats_len = ARRAY_SIZE(builtin_formats);
107
builtin_formats_len = commit_formats_len;
ref-filter.c
+4
@@ -485,6 +485,10 @@ static struct {
485
{ "if", SOURCE_NONE, FIELD_STR, if_atom_parser },
486
{ "then", SOURCE_NONE },
487
{ "else", SOURCE_NONE },
488
+ /*
489
+ * Please update $__git_ref_fieldlist in git-completion.bash
490
+ * when you add new atoms
491
+ */
492
};
493
494
#define REF_FORMATTING_STATE_INIT { 0, NULL }
submodule-config.c
+8
-1
@@ -281,7 +281,10 @@ static int parse_fetch_recurse(const char *opt, const char *arg,
281
default:
282
if (!strcmp(arg, "on-demand"))
283
return RECURSE_SUBMODULES_ON_DEMAND;
284
-
284
+ /*
285
+ * Please update $__git_fetch_recurse_submodules in
286
+ * git-completion.bash when you add new options.
287
+ */
288
if (die_on_error)
289
die("bad %s argument: %s", opt, arg);
290
else
@@ -362,6 +365,10 @@ static int parse_push_recurse(const char *opt, const char *arg,
365
return RECURSE_SUBMODULES_CHECK;
366
else if (!strcmp(arg, "only"))
367
return RECURSE_SUBMODULES_ONLY;
368
+ /*
369
+ * Please update $__git_push_recurse_submodules in
370
+ * git-completion.bash when you add new modes.
371
+ */
372
else if (die_on_error)
373
die("bad %s argument: %s", opt, arg);
374
else
submodule.c
+4
@@ -432,6 +432,10 @@ void handle_ignore_submodules_arg(struct diff_options *diffopt,
432
diffopt->flags.ignore_dirty_submodules = 1;
433
else if (strcmp(arg, "none"))
434
die("bad --ignore-submodules argument: %s", arg);
435
+ /*
436
+ * Please update _git_status() in git-completion.bash when you
437
+ * add new options
438
+ */
439
}
440
441
static int prepare_submodule_summary(struct rev_info *rev, const char *path,
xdiff-interface.c
+4
@@ -306,6 +306,10 @@ int git_xmerge_config(const char *var, const char *value, void *cb)
306
git_xmerge_style = XDL_MERGE_DIFF3;
307
else if (!strcmp(value, "merge"))
308
git_xmerge_style = 0;
309
+ /*
310
+ * Please update _git_checkout() in
311
+ * git-completion.bash when you add new merge config
312
+ */
313
else
314
die("unknown style '%s' given for '%s'",
315
value, var);