Merge branch 'cp/completion-negative-refs'
authorJunio C Hamano <gitster@pobox.com>
Mon, 10 Oct 2016 21:03:49 +0000 (14:03 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 10 Oct 2016 21:03:49 +0000 (14:03 -0700)
The command-line completion script (in contrib/) learned to
complete "git cmd ^mas<HT>" to complete the negative end of
reference to "git cmd ^master".

* cp/completion-negative-refs:
completion: support excluding refs

1  2 
contrib/completion/git-completion.bash
index 9c8f7380d0f1ad76f0163209e5005adfe46ec916,eb8a3d4aa7e57d1d17760ecc516837fb4ed4ca92..21016bf8dfe87572fb53a05488ba05bb3c08ed97
@@@ -338,7 -338,7 +338,7 @@@ __git_tags (
  __git_refs ()
  {
        local i hash dir="$(__gitdir "${1-}")" track="${2-}"
-       local format refs
+       local format refs pfx
        if [ -d "$dir" ]; then
                case "$cur" in
                refs|refs/*)
                        track=""
                        ;;
                *)
+                       [[ "$cur" == ^* ]] && pfx="^"
                        for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD; do
-                               if [ -e "$dir/$i" ]; then echo $i; fi
+                               if [ -e "$dir/$i" ]; then echo $pfx$i; fi
                        done
                        format="refname:short"
                        refs="refs/tags refs/heads refs/remotes"
                        ;;
                esac
-               git --git-dir="$dir" for-each-ref --format="%($format)" \
+               git --git-dir="$dir" for-each-ref --format="$pfx%($format)" \
                        $refs
                if [ -n "$track" ]; then
                        # employ the heuristic used by git checkout
@@@ -803,50 -804,6 +804,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
@@@ -1008,8 -965,8 +1009,8 @@@ _git_branch (
        while [ $c -lt $cword ]; do
                i="${words[c]}"
                case "$i" in
 -              -d|-m)  only_local_ref="y" ;;
 -              -r)     has_r="y" ;;
 +              -d|--delete|-m|--move)  only_local_ref="y" ;;
 +              -r|--remotes)           has_r="y" ;;
                esac
                ((c++))
        done
                        --color --no-color --verbose --abbrev= --no-abbrev
                        --track --no-track --contains --merged --no-merged
                        --set-upstream-to= --edit-description --list
 -                      --unset-upstream
 +                      --unset-upstream --delete --move --remotes
                        "
                ;;
        *)
@@@ -1143,8 -1100,6 +1144,8 @@@ _git_clone (
        esac
  }
  
 +__git_untracked_file_modes="all no normal"
 +
  _git_commit ()
  {
        case "$prev" in
                return
                ;;
        --untracked-files=*)
 -              __gitcomp "all no normal" "" "${cur##--untracked-files=}"
 +              __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
                return
                ;;
        --*)
@@@ -1205,8 -1160,6 +1206,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
                        --dirstat --dirstat= --dirstat-by-file
                        --dirstat-by-file= --cumulative
                        --diff-algorithm=
 +                      --submodule --submodule=
  "
  
  _git_diff ()
                __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
@@@ -1501,14 -1449,6 +1502,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
@@@ -1842,56 -1782,6 +1843,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
@@@ -2197,7 -2087,6 +2198,7 @@@ _git_config (
                format.attach
                format.cc
                format.coverLetter
 +              format.from
                format.headers
                format.numbered
                format.pretty
@@@ -2472,10 -2361,6 +2473,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
@@@ -2712,32 -2597,6 +2713,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