From: Junio C Hamano Date: Mon, 27 Jun 2016 16:56:54 +0000 (-0700) Subject: Merge branch 'tb/complete-status' X-Git-Tag: v2.10.0-rc0~172 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/deee904aacccfcba5e38f9803799cd2e3a7d62ce?ds=inline;hp=-c Merge branch 'tb/complete-status' The completion script (in contrib/) learned to complete "git status" options. * tb/complete-status: completion: add git status completion: add __git_get_option_value helper completion: factor out untracked file modes into a variable --- deee904aacccfcba5e38f9803799cd2e3a7d62ce diff --combined contrib/completion/git-completion.bash index 34024754d9,bb3acac1ec..ddda5e5e27 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@@ -803,6 -803,50 +803,50 @@@ __git_find_on_cmdline ( done } + # Echo the value of an option set on the command line or config + # + # $1: short option name + # $2: long option name including = + # $3: list of possible values + # $4: config string (optional) + # + # example: + # result="$(__git_get_option_value "-d" "--do-something=" \ + # "yes no" "core.doSomething")" + # + # result is then either empty (no option set) or "yes" or "no" + # + # __git_get_option_value requires 3 arguments + __git_get_option_value () + { + local c short_opt long_opt val + local result= values config_key word + + short_opt="$1" + long_opt="$2" + values="$3" + config_key="$4" + + ((c = $cword - 1)) + while [ $c -ge 0 ]; do + word="${words[c]}" + for val in $values; do + if [ "$short_opt$val" = "$word" ] || + [ "$long_opt$val" = "$word" ]; then + result="$val" + break 2 + fi + done + ((c--)) + done + + if [ -n "$config_key" ] && [ -z "$result" ]; then + result="$(git --git-dir="$(__gitdir)" config "$config_key")" + fi + + echo "$result" + } + __git_has_doubledash () { local c=1 @@@ -1098,6 -1142,8 +1142,8 @@@ _git_clone ( esac } + __git_untracked_file_modes="all no normal" + _git_commit () { case "$prev" in @@@ -1119,7 -1165,7 +1165,7 @@@ return ;; --untracked-files=*) - __gitcomp "all no normal" "" "${cur##--untracked-files=}" + __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}" return ;; --*) @@@ -1339,15 -1385,15 +1385,15 @@@ _git_help ( { case "$cur" in --*) - __gitcomp "--all --info --man --web" + __gitcomp "--all --guides --info --man --web" return ;; esac __git_compute_all_commands __gitcomp "$__git_all_commands $(__git_aliases) attributes cli core-tutorial cvs-migration - diffcore gitk glossary hooks ignore modules - namespaces repository-layout tutorial tutorial-2 + diffcore everyday gitk glossary hooks ignore modules + namespaces repository-layout revisions tutorial tutorial-2 workflows " } @@@ -1458,7 -1504,6 +1504,7 @@@ _git_log ( --relative-date --date= --pretty= --format= --oneline --show-signature + --cherry-mark --cherry-pick --graph --decorate --decorate= @@@ -1780,6 -1825,56 +1826,56 @@@ _git_stage ( _git_add } + _git_status () + { + local complete_opt + local untracked_state + + case "$cur" in + --ignore-submodules=*) + __gitcomp "none untracked dirty all" "" "${cur##--ignore-submodules=}" + return + ;; + --untracked-files=*) + __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}" + return + ;; + --column=*) + __gitcomp " + always never auto column row plain dense nodense + " "" "${cur##--column=}" + return + ;; + --*) + __gitcomp " + --short --branch --porcelain --long --verbose + --untracked-files= --ignore-submodules= --ignored + --column= --no-column + " + return + ;; + esac + + untracked_state="$(__git_get_option_value "-u" "--untracked-files=" \ + "$__git_untracked_file_modes" "status.showUntrackedFiles")" + + case "$untracked_state" in + no) + # --ignored option does not matter + complete_opt= + ;; + all|normal|*) + complete_opt="--cached --directory --no-empty-directory --others" + + if [ -n "$(__git_find_on_cmdline "--ignored")" ]; then + complete_opt="$complete_opt --ignored --exclude=*" + fi + ;; + esac + + __git_complete_index_file "$complete_opt" + } + __git_config_get_set_variables () { local prevword word config_file= c=$cword