提交 5a59a230 编写于 作者: N Nguyễn Thái Ngọc Duy 提交者: Junio C Hamano

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: NNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 35ee755a
...@@ -56,6 +56,10 @@ static int parse_whitespace_option(struct apply_state *state, const char *option ...@@ -56,6 +56,10 @@ static int parse_whitespace_option(struct apply_state *state, const char *option
state->ws_error_action = correct_ws_error; state->ws_error_action = correct_ws_error;
return 0; return 0;
} }
/*
* Please update $__git_whitespacelist in git-completion.bash
* when you add new options.
*/
return error(_("unrecognized whitespace option '%s'"), option); return error(_("unrecognized whitespace option '%s'"), option);
} }
......
...@@ -2119,6 +2119,10 @@ static int parse_opt_patchformat(const struct option *opt, const char *arg, int ...@@ -2119,6 +2119,10 @@ static int parse_opt_patchformat(const struct option *opt, const char *arg, int
*opt_value = PATCH_FORMAT_HG; *opt_value = PATCH_FORMAT_HG;
else if (!strcmp(arg, "mboxrd")) else if (!strcmp(arg, "mboxrd"))
*opt_value = PATCH_FORMAT_MBOXRD; *opt_value = PATCH_FORMAT_MBOXRD;
/*
* Please update $__git_patchformat in git-completion.bash
* when you add new options
*/
else else
return error(_("Invalid value for --patch-format: %s"), arg); return error(_("Invalid value for --patch-format: %s"), arg);
return 0; return 0;
......
...@@ -1038,6 +1038,10 @@ static void handle_untracked_files_arg(struct wt_status *s) ...@@ -1038,6 +1038,10 @@ static void handle_untracked_files_arg(struct wt_status *s)
s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES; s->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;
else if (!strcmp(untracked_files_arg, "all")) else if (!strcmp(untracked_files_arg, "all"))
s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES; s->show_untracked_files = SHOW_ALL_UNTRACKED_FILES;
/*
* Please update $__git_untracked_file_modes in
* git-completion.bash when you add new options
*/
else else
die(_("Invalid untracked files mode '%s'"), untracked_files_arg); die(_("Invalid untracked files mode '%s'"), untracked_files_arg);
} }
...@@ -1179,6 +1183,10 @@ static int parse_and_validate_options(int argc, const char *argv[], ...@@ -1179,6 +1183,10 @@ static int parse_and_validate_options(int argc, const char *argv[],
else if (!strcmp(cleanup_arg, "scissors")) else if (!strcmp(cleanup_arg, "scissors"))
cleanup_mode = use_editor ? COMMIT_MSG_CLEANUP_SCISSORS : cleanup_mode = use_editor ? COMMIT_MSG_CLEANUP_SCISSORS :
COMMIT_MSG_CLEANUP_SPACE; COMMIT_MSG_CLEANUP_SPACE;
/*
* Please update _git_commit() in git-completion.bash when you
* add new options.
*/
else else
die(_("Invalid cleanup mode %s"), cleanup_arg); die(_("Invalid cleanup mode %s"), cleanup_arg);
......
...@@ -70,6 +70,10 @@ static enum help_format parse_help_format(const char *format) ...@@ -70,6 +70,10 @@ static enum help_format parse_help_format(const char *format)
return HELP_FORMAT_INFO; return HELP_FORMAT_INFO;
if (!strcmp(format, "web") || !strcmp(format, "html")) if (!strcmp(format, "web") || !strcmp(format, "html"))
return HELP_FORMAT_WEB; return HELP_FORMAT_WEB;
/*
* Please update _git_config() in git-completion.bash when you
* add new help formats.
*/
die(_("unrecognized help format '%s'"), format); die(_("unrecognized help format '%s'"), format);
} }
......
...@@ -84,6 +84,10 @@ static int parse_decoration_style(const char *value) ...@@ -84,6 +84,10 @@ static int parse_decoration_style(const char *value)
return DECORATE_SHORT_REFS; return DECORATE_SHORT_REFS;
else if (!strcmp(value, "auto")) else if (!strcmp(value, "auto"))
return auto_decoration_style(); return auto_decoration_style();
/*
* Please update _git_log() in git-completion.bash when you
* add new decoration styles.
*/
return -1; return -1;
} }
...@@ -1228,6 +1232,10 @@ static int thread_callback(const struct option *opt, const char *arg, int unset) ...@@ -1228,6 +1232,10 @@ static int thread_callback(const struct option *opt, const char *arg, int unset)
*thread = THREAD_SHALLOW; *thread = THREAD_SHALLOW;
else if (!strcmp(arg, "deep")) else if (!strcmp(arg, "deep"))
*thread = THREAD_DEEP; *thread = THREAD_DEEP;
/*
* Please update _git_formatpatch() in git-completion.bash
* when you add new options.
*/
else else
return 1; return 1;
return 0; return 0;
......
...@@ -56,6 +56,10 @@ static enum rebase_type parse_config_rebase(const char *key, const char *value, ...@@ -56,6 +56,10 @@ static enum rebase_type parse_config_rebase(const char *key, const char *value,
return REBASE_MERGES; return REBASE_MERGES;
else if (!strcmp(value, "interactive") || !strcmp(value, "i")) else if (!strcmp(value, "interactive") || !strcmp(value, "i"))
return REBASE_INTERACTIVE; return REBASE_INTERACTIVE;
/*
* Please update _git_config() in git-completion.bash when you
* add new rebase modes.
*/
if (fatal) if (fatal)
die(_("Invalid value for %s: %s"), key, value); die(_("Invalid value for %s: %s"), key, value);
......
...@@ -82,6 +82,10 @@ static int list_replace_refs(const char *pattern, const char *format) ...@@ -82,6 +82,10 @@ static int list_replace_refs(const char *pattern, const char *format)
data.format = REPLACE_FORMAT_MEDIUM; data.format = REPLACE_FORMAT_MEDIUM;
else if (!strcmp(format, "long")) else if (!strcmp(format, "long"))
data.format = REPLACE_FORMAT_LONG; data.format = REPLACE_FORMAT_LONG;
/*
* Please update _git_replace() in git-completion.bash when
* you add new format
*/
else else
return error(_("invalid replace format '%s'\n" return error(_("invalid replace format '%s'\n"
"valid formats are 'short', 'medium' and 'long'"), "valid formats are 'short', 'medium' and 'long'"),
......
...@@ -853,6 +853,11 @@ __git_compute_merge_strategies () ...@@ -853,6 +853,11 @@ __git_compute_merge_strategies ()
__git_merge_strategies=$(__git_list_merge_strategies) __git_merge_strategies=$(__git_list_merge_strategies)
} }
__git_merge_strategy_options="ours theirs subtree subtree= patience
histogram diff-algorithm= ignore-space-change ignore-all-space
ignore-space-at-eol renormalize no-renormalize no-renames
find-renames find-renames= rename-threshold="
__git_complete_revlist_file () __git_complete_revlist_file ()
{ {
local dequoted_word pfx ls ref cur_="$cur" local dequoted_word pfx ls ref cur_="$cur"
...@@ -996,12 +1001,21 @@ __git_complete_strategy () ...@@ -996,12 +1001,21 @@ __git_complete_strategy ()
-s|--strategy) -s|--strategy)
__gitcomp "$__git_merge_strategies" __gitcomp "$__git_merge_strategies"
return 0 return 0
;;
-X)
__gitcomp "$__git_merge_strategy_options"
return 0
;;
esac esac
case "$cur" in case "$cur" in
--strategy=*) --strategy=*)
__gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}" __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}"
return 0 return 0
;; ;;
--strategy-option=*)
__gitcomp "$__git_merge_strategy_options" "" "${cur##--strategy-option=}"
return 0
;;
esac esac
return 1 return 1
} }
...@@ -1163,6 +1177,7 @@ __git_count_arguments () ...@@ -1163,6 +1177,7 @@ __git_count_arguments ()
} }
__git_whitespacelist="nowarn warn error error-all fix" __git_whitespacelist="nowarn warn error error-all fix"
__git_patchformat="mbox stgit stgit-series hg mboxrd"
__git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch" __git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch"
_git_am () _git_am ()
...@@ -1177,6 +1192,10 @@ _git_am () ...@@ -1177,6 +1192,10 @@ _git_am ()
__gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}" __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}"
return return
;; ;;
--patch-format=*)
__gitcomp "$__git_patchformat" "" "${cur##--patch-format=}"
return
;;
--*) --*)
__gitcomp_builtin am "" \ __gitcomp_builtin am "" \
"$__git_am_inprogress_options" "$__git_am_inprogress_options"
...@@ -1200,6 +1219,10 @@ _git_apply () ...@@ -1200,6 +1219,10 @@ _git_apply ()
_git_add () _git_add ()
{ {
case "$cur" in case "$cur" in
--chmod=*)
__gitcomp "+x -x" "" "${cur##--chmod=}"
return
;;
--*) --*)
__gitcomp_builtin add __gitcomp_builtin add
return return
...@@ -1260,6 +1283,8 @@ _git_bisect () ...@@ -1260,6 +1283,8 @@ _git_bisect ()
esac esac
} }
__git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD symref"
_git_branch () _git_branch ()
{ {
local i c=1 only_local_ref="n" has_r="n" local i c=1 only_local_ref="n" has_r="n"
...@@ -1343,6 +1368,9 @@ _git_cherry_pick () ...@@ -1343,6 +1368,9 @@ _git_cherry_pick ()
__gitcomp "$__git_cherry_pick_inprogress_options" __gitcomp "$__git_cherry_pick_inprogress_options"
return return
fi fi
__git_complete_strategy && return
case "$cur" in case "$cur" in
--*) --*)
__gitcomp_builtin cherry-pick "" \ __gitcomp_builtin cherry-pick "" \
...@@ -1506,6 +1534,10 @@ _git_fetch () ...@@ -1506,6 +1534,10 @@ _git_fetch ()
__gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}" __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}"
return return
;; ;;
--filter=*)
__gitcomp "blob:none blob:limit= sparse:oid= sparse:path=" "" "${cur##--filter=}"
return
;;
--*) --*)
__gitcomp_builtin fetch __gitcomp_builtin fetch
return return
...@@ -1702,8 +1734,8 @@ __git_log_shortlog_options=" ...@@ -1702,8 +1734,8 @@ __git_log_shortlog_options="
--all-match --invert-grep --all-match --invert-grep
" "
__git_log_pretty_formats="oneline short medium full fuller email raw format:" __git_log_pretty_formats="oneline short medium full fuller email raw format: mboxrd"
__git_log_date_formats="relative iso8601 rfc2822 short local default raw" __git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default raw unix format:"
_git_log () _git_log ()
{ {
...@@ -2221,7 +2253,7 @@ _git_config () ...@@ -2221,7 +2253,7 @@ _git_config ()
return return
;; ;;
diff.submodule) diff.submodule)
__gitcomp "log short" __gitcomp "$__git_diff_submodule_formats"
return return
;; ;;
help.format) help.format)
...@@ -2388,6 +2420,10 @@ _git_remote () ...@@ -2388,6 +2420,10 @@ _git_remote ()
_git_replace () _git_replace ()
{ {
case "$cur" in case "$cur" in
--format=*)
__gitcomp "short medium long" "" "${cur##--format=}"
return
;;
--*) --*)
__gitcomp_builtin replace __gitcomp_builtin replace
return return
...@@ -2429,6 +2465,7 @@ _git_revert () ...@@ -2429,6 +2465,7 @@ _git_revert ()
__gitcomp "$__git_revert_inprogress_options" __gitcomp "$__git_revert_inprogress_options"
return return
fi fi
__git_complete_strategy && return
case "$cur" in case "$cur" in
--*) --*)
__gitcomp_builtin revert "" \ __gitcomp_builtin revert "" \
......
...@@ -921,6 +921,10 @@ static enum date_mode_type parse_date_type(const char *format, const char **end) ...@@ -921,6 +921,10 @@ static enum date_mode_type parse_date_type(const char *format, const char **end)
return DATE_UNIX; return DATE_UNIX;
if (skip_prefix(format, "format", end)) if (skip_prefix(format, "format", end))
return DATE_STRFTIME; return DATE_STRFTIME;
/*
* Please update $__git_log_date_formats in
* git-completion.bash when you add new formats.
*/
die("unknown date format %s", format); die("unknown date format %s", format);
} }
......
...@@ -178,6 +178,10 @@ static int parse_submodule_params(struct diff_options *options, const char *valu ...@@ -178,6 +178,10 @@ static int parse_submodule_params(struct diff_options *options, const char *valu
options->submodule_format = DIFF_SUBMODULE_SHORT; options->submodule_format = DIFF_SUBMODULE_SHORT;
else if (!strcmp(value, "diff")) else if (!strcmp(value, "diff"))
options->submodule_format = DIFF_SUBMODULE_INLINE_DIFF; options->submodule_format = DIFF_SUBMODULE_INLINE_DIFF;
/*
* Please update $__git_diff_submodule_formats in
* git-completion.bash when you add new formats.
*/
else else
return -1; return -1;
return 0; return 0;
...@@ -204,6 +208,10 @@ long parse_algorithm_value(const char *value) ...@@ -204,6 +208,10 @@ long parse_algorithm_value(const char *value)
return XDF_PATIENCE_DIFF; return XDF_PATIENCE_DIFF;
else if (!strcasecmp(value, "histogram")) else if (!strcasecmp(value, "histogram"))
return XDF_HISTOGRAM_DIFF; return XDF_HISTOGRAM_DIFF;
/*
* Please update $__git_diff_algorithms in git-completion.bash
* when you add new algorithms.
*/
return -1; return -1;
} }
......
...@@ -465,6 +465,8 @@ sub read_config { ...@@ -465,6 +465,8 @@ sub read_config {
my(%suppress_cc); my(%suppress_cc);
if (@suppress_cc) { if (@suppress_cc) {
foreach my $entry (@suppress_cc) { foreach my $entry (@suppress_cc) {
# Please update $__git_send_email_suppresscc_options
# in git-completion.bash when you add new options.
die sprintf(__("Unknown --suppress-cc field: '%s'\n"), $entry) die sprintf(__("Unknown --suppress-cc field: '%s'\n"), $entry)
unless $entry =~ /^(?:all|cccmd|cc|author|self|sob|body|bodycc|misc-by)$/; unless $entry =~ /^(?:all|cccmd|cc|author|self|sob|body|bodycc|misc-by)$/;
$suppress_cc{$entry} = 1; $suppress_cc{$entry} = 1;
...@@ -494,6 +496,8 @@ sub read_config { ...@@ -494,6 +496,8 @@ sub read_config {
if ($confirm_unconfigured) { if ($confirm_unconfigured) {
$confirm = scalar %suppress_cc ? 'compose' : 'auto'; $confirm = scalar %suppress_cc ? 'compose' : 'auto';
}; };
# Please update $__git_send_email_confirm_options in
# git-completion.bash when you add new options.
die sprintf(__("Unknown --confirm setting: '%s'\n"), $confirm) die sprintf(__("Unknown --confirm setting: '%s'\n"), $confirm)
unless $confirm =~ /^(?:auto|cc|compose|always|never)/; unless $confirm =~ /^(?:auto|cc|compose|always|never)/;
...@@ -587,6 +591,8 @@ sub parse_sendmail_aliases { ...@@ -587,6 +591,8 @@ sub parse_sendmail_aliases {
if (/\(define-mail-alias\s+"(\S+?)"\s+"(\S+?)"\)/) { if (/\(define-mail-alias\s+"(\S+?)"\s+"(\S+?)"\)/) {
$aliases{$1} = [ $2 ]; $aliases{$1} = [ $2 ];
}}} }}}
# Please update _git_config() in git-completion.bash when you
# add new MUAs.
); );
if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) { if (@alias_files and $aliasfiletype and defined $parse_alias{$aliasfiletype}) {
......
...@@ -82,6 +82,10 @@ static int gently_parse_list_objects_filter( ...@@ -82,6 +82,10 @@ static int gently_parse_list_objects_filter(
filter_options->sparse_path_value = strdup(v0); filter_options->sparse_path_value = strdup(v0);
return 0; return 0;
} }
/*
* Please update _git_fetch() in git-completion.bash when you
* add new filters
*/
if (errbuf) if (errbuf)
strbuf_addf(errbuf, "invalid filter-spec '%s'", arg); strbuf_addf(errbuf, "invalid filter-spec '%s'", arg);
......
...@@ -3764,6 +3764,10 @@ int parse_merge_opt(struct merge_options *o, const char *s) ...@@ -3764,6 +3764,10 @@ int parse_merge_opt(struct merge_options *o, const char *s)
return -1; return -1;
o->merge_detect_rename = 1; o->merge_detect_rename = 1;
} }
/*
* Please update $__git_merge_strategy_options in
* git-completion.bash when you add new options
*/
else else
return -1; return -1;
return 0; return 0;
......
...@@ -98,6 +98,10 @@ static void setup_commit_formats(void) ...@@ -98,6 +98,10 @@ static void setup_commit_formats(void)
{ "fuller", CMIT_FMT_FULLER, 0, 8 }, { "fuller", CMIT_FMT_FULLER, 0, 8 },
{ "full", CMIT_FMT_FULL, 0, 8 }, { "full", CMIT_FMT_FULL, 0, 8 },
{ "oneline", CMIT_FMT_ONELINE, 1, 0 } { "oneline", CMIT_FMT_ONELINE, 1, 0 }
/*
* Please update $__git_log_pretty_formats in
* git-completion.bash when you add new formats.
*/
}; };
commit_formats_len = ARRAY_SIZE(builtin_formats); commit_formats_len = ARRAY_SIZE(builtin_formats);
builtin_formats_len = commit_formats_len; builtin_formats_len = commit_formats_len;
......
...@@ -485,6 +485,10 @@ static struct { ...@@ -485,6 +485,10 @@ static struct {
{ "if", SOURCE_NONE, FIELD_STR, if_atom_parser }, { "if", SOURCE_NONE, FIELD_STR, if_atom_parser },
{ "then", SOURCE_NONE }, { "then", SOURCE_NONE },
{ "else", SOURCE_NONE }, { "else", SOURCE_NONE },
/*
* Please update $__git_ref_fieldlist in git-completion.bash
* when you add new atoms
*/
}; };
#define REF_FORMATTING_STATE_INIT { 0, NULL } #define REF_FORMATTING_STATE_INIT { 0, NULL }
......
...@@ -281,7 +281,10 @@ static int parse_fetch_recurse(const char *opt, const char *arg, ...@@ -281,7 +281,10 @@ static int parse_fetch_recurse(const char *opt, const char *arg,
default: default:
if (!strcmp(arg, "on-demand")) if (!strcmp(arg, "on-demand"))
return RECURSE_SUBMODULES_ON_DEMAND; return RECURSE_SUBMODULES_ON_DEMAND;
/*
* Please update $__git_fetch_recurse_submodules in
* git-completion.bash when you add new options.
*/
if (die_on_error) if (die_on_error)
die("bad %s argument: %s", opt, arg); die("bad %s argument: %s", opt, arg);
else else
...@@ -362,6 +365,10 @@ static int parse_push_recurse(const char *opt, const char *arg, ...@@ -362,6 +365,10 @@ static int parse_push_recurse(const char *opt, const char *arg,
return RECURSE_SUBMODULES_CHECK; return RECURSE_SUBMODULES_CHECK;
else if (!strcmp(arg, "only")) else if (!strcmp(arg, "only"))
return RECURSE_SUBMODULES_ONLY; return RECURSE_SUBMODULES_ONLY;
/*
* Please update $__git_push_recurse_submodules in
* git-completion.bash when you add new modes.
*/
else if (die_on_error) else if (die_on_error)
die("bad %s argument: %s", opt, arg); die("bad %s argument: %s", opt, arg);
else else
......
...@@ -432,6 +432,10 @@ void handle_ignore_submodules_arg(struct diff_options *diffopt, ...@@ -432,6 +432,10 @@ void handle_ignore_submodules_arg(struct diff_options *diffopt,
diffopt->flags.ignore_dirty_submodules = 1; diffopt->flags.ignore_dirty_submodules = 1;
else if (strcmp(arg, "none")) else if (strcmp(arg, "none"))
die("bad --ignore-submodules argument: %s", arg); die("bad --ignore-submodules argument: %s", arg);
/*
* Please update _git_status() in git-completion.bash when you
* add new options
*/
} }
static int prepare_submodule_summary(struct rev_info *rev, const char *path, static int prepare_submodule_summary(struct rev_info *rev, const char *path,
......
...@@ -306,6 +306,10 @@ int git_xmerge_config(const char *var, const char *value, void *cb) ...@@ -306,6 +306,10 @@ int git_xmerge_config(const char *var, const char *value, void *cb)
git_xmerge_style = XDL_MERGE_DIFF3; git_xmerge_style = XDL_MERGE_DIFF3;
else if (!strcmp(value, "merge")) else if (!strcmp(value, "merge"))
git_xmerge_style = 0; git_xmerge_style = 0;
/*
* Please update _git_checkout() in
* git-completion.bash when you add new merge config
*/
else else
die("unknown style '%s' given for '%s'", die("unknown style '%s' given for '%s'",
value, var); value, var);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册