From: Junio C Hamano Date: Wed, 10 Aug 2016 19:33:19 +0000 (-0700) Subject: Merge branch 'jk/completion-diff-submodule' X-Git-Tag: v2.10.0-rc0~23 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/483ca933f8fee1e9264aeef71f48f086e7cc70db?ds=inline;hp=-c Merge branch 'jk/completion-diff-submodule' * jk/completion-diff-submodule: completion: add completion for --submodule=* diff option --- 483ca933f8fee1e9264aeef71f48f086e7cc70db diff --combined contrib/completion/git-completion.bash index 85bb8b579b,8f700deaac..c1b2135544 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@@ -803,50 -803,6 +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 @@@ -1136,15 -1092,12 +1136,15 @@@ _git_clone ( --depth --single-branch --branch + --recurse-submodules " return ;; esac } +__git_untracked_file_modes="all no normal" + _git_commit () { case "$prev" in @@@ -1166,7 -1119,7 +1166,7 @@@ return ;; --untracked-files=*) - __gitcomp "all no normal" "" "${cur##--untracked-files=}" + __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}" return ;; --*) @@@ -1205,6 -1158,8 +1205,8 @@@ _git_describe ( __git_diff_algorithms="myers minimal patience histogram" + __git_diff_submodule_formats="log short" + __git_diff_common_options="--stat --numstat --shortstat --summary --patch-with-stat --name-only --name-status --color --no-color --color-words --no-renames --check @@@ -1220,6 -1175,7 +1222,7 @@@ --dirstat --dirstat= --dirstat-by-file --dirstat-by-file= --cumulative --diff-algorithm= + --submodule --submodule= " _git_diff () @@@ -1231,6 -1187,10 +1234,10 @@@ __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}" return ;; + --submodule=*) + __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}" + return + ;; --*) __gitcomp "--cached --staged --pickaxe-all --pickaxe-regex --base --ours --theirs --no-index @@@ -1494,6 -1454,14 +1501,14 @@@ _git_log ( __gitcomp "full short no" "" "${cur##--decorate=}" return ;; + --diff-algorithm=*) + __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}" + return + ;; + --submodule=*) + __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}" + return + ;; --*) __gitcomp " $__git_log_common_options @@@ -1827,56 -1795,6 +1842,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 @@@ -2182,7 -2100,6 +2197,7 @@@ _git_config ( format.attach format.cc format.coverLetter + format.from format.headers format.numbered format.pretty @@@ -2457,6 -2374,10 +2472,10 @@@ _git_show ( __gitcomp "$__git_diff_algorithms" "" "${cur##--diff-algorithm=}" return ;; + --submodule=*) + __gitcomp "$__git_diff_submodule_formats" "" "${cur##--submodule=}" + return + ;; --*) __gitcomp "--pretty= --format= --abbrev-commit --oneline --show-signature @@@ -2693,32 -2614,6 +2712,32 @@@ _git_whatchanged ( _git_log } +_git_worktree () +{ + local subcommands="add list lock prune unlock" + local subcommand="$(__git_find_on_cmdline "$subcommands")" + if [ -z "$subcommand" ]; then + __gitcomp "$subcommands" + else + case "$subcommand,$cur" in + add,--*) + __gitcomp "--detach" + ;; + list,--*) + __gitcomp "--porcelain" + ;; + lock,--*) + __gitcomp "--reason" + ;; + prune,--*) + __gitcomp "--dry-run --expire --verbose" + ;; + *) + ;; + esac + fi +} + __git_main () { local i c=1 command __git_dir