]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'si/zsh-complete-comment-fix'
authorJunio C Hamano <gitster@pobox.com>
Fri, 7 May 2021 03:47:42 +0000 (12:47 +0900)
committerJunio C Hamano <gitster@pobox.com>
Fri, 7 May 2021 03:47:42 +0000 (12:47 +0900)
Portability fix for command line completion script (in contrib/).

* si/zsh-complete-comment-fix:
  work around zsh comment in __git_complete_worktree_paths

1  2 
contrib/completion/git-completion.bash

index b09cb62c9f48d939d0b98277994b9711bd9d7169,7ef7385d12a482d6ef95ced24269aae4a3bd3c6a..5722ef07aac1a82338d97e7aa7dd3b6dbb6aa1d4
@@@ -77,7 -77,7 +77,7 @@@ __git_find_repo_path (
                test -d "$__git_dir" &&
                __git_repo_path="$__git_dir"
        elif [ -n "${GIT_DIR-}" ]; then
 -              test -d "${GIT_DIR-}" &&
 +              test -d "$GIT_DIR" &&
                __git_repo_path="$GIT_DIR"
        elif [ -d .git ]; then
                __git_repo_path=.git
@@@ -427,7 -427,7 +427,7 @@@ __gitcomp_builtin (
  
        if [ -z "$options" ]; then
                local completion_helper
 -              if [ "$GIT_COMPLETION_SHOW_ALL" = "1" ]; then
 +              if [ "${GIT_COMPLETION_SHOW_ALL-}" = "1" ]; then
                        completion_helper="--git-completion-helper-all"
                else
                        completion_helper="--git-completion-helper"
@@@ -744,7 -744,7 +744,7 @@@ __git_refs (
                        track=""
                        ;;
                *)
 -                      for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD; do
 +                      for i in HEAD FETCH_HEAD ORIG_HEAD MERGE_HEAD REBASE_HEAD CHERRY_PICK_HEAD; do
                                case "$i" in
                                $match*)
                                        if [ -e "$dir/$i" ]; then
@@@ -1006,8 -1006,8 +1006,8 @@@ __git_complete_revlist (
  
  __git_complete_remote_or_refspec ()
  {
 -      local cur_="$cur" cmd="${words[1]}"
 -      local i c=2 remote="" pfx="" lhs=1 no_complete_refspec=0
 +      local cur_="$cur" cmd="${words[__git_cmd_idx]}"
 +      local i c=$((__git_cmd_idx+1)) remote="" pfx="" lhs=1 no_complete_refspec=0
        if [ "$cmd" = "remote" ]; then
                ((c++))
        fi
@@@ -1129,7 -1129,7 +1129,7 @@@ __git_pretty_aliases (
  # __git_aliased_command requires 1 argument
  __git_aliased_command ()
  {
 -      local cur=$1 last list word cmdline
 +      local cur=$1 last list= word cmdline
  
        while [[ -n "$cur" ]]; do
                if [[ "$list" == *" $cur "* ]]; then
  # --show-idx: Optionally show the index of the found word in the $words array.
  __git_find_on_cmdline ()
  {
 -      local word c=1 show_idx
 +      local word c="$__git_cmd_idx" show_idx
  
        while test $# -gt 1; do
                case "$1" in
@@@ -1221,7 -1221,7 +1221,7 @@@ __git_find_last_on_cmdline (
        done
        local wordlist="$1"
  
 -      while [ $c -gt 1 ]; do
 +      while [ $c -gt "$__git_cmd_idx" ]; do
                ((c--))
                for word in $wordlist; do
                        if [ "$word" = "${words[c]}" ]; then
@@@ -1306,7 -1306,7 +1306,7 @@@ __git_count_arguments (
        local word i c=0
  
        # Skip "git" (first argument)
 -      for ((i=1; i < ${#words[@]}; i++)); do
 +      for ((i="$__git_cmd_idx"; i < ${#words[@]}; i++)); do
                word="${words[i]}"
  
                case "$word" in
@@@ -1442,7 -1442,7 +1442,7 @@@ __git_ref_fieldlist="refname objecttyp
  
  _git_branch ()
  {
 -      local i c=1 only_local_ref="n" has_r="n"
 +      local i c="$__git_cmd_idx" only_local_ref="n" has_r="n"
  
        while [ $c -lt $cword ]; do
                i="${words[c]}"
  
  _git_bundle ()
  {
 -      local cmd="${words[2]}"
 +      local cmd="${words[__git_cmd_idx+1]}"
        case "$cword" in
 -      2)
 +      $((__git_cmd_idx+1)))
                __gitcomp "create list-heads verify unbundle"
                ;;
 -      3)
 +      $((__git_cmd_idx+2)))
                # looking for a file
                ;;
        *)
@@@ -1894,7 -1894,7 +1894,7 @@@ _git_grep (
        esac
  
        case "$cword,$prev" in
 -      2,*|*,-*)
 +      $((__git_cmd_idx+1)),*|*,-*)
                __git_complete_symbol && return
                ;;
        esac
@@@ -1910,7 -1910,7 +1910,7 @@@ _git_help (
                return
                ;;
        esac
 -      if test -n "$GIT_TESTING_ALL_COMMAND_LIST"
 +      if test -n "${GIT_TESTING_ALL_COMMAND_LIST-}"
        then
                __gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(__git --list-cmds=alias,list-guide) gitk"
        else
@@@ -2474,7 -2474,7 +2474,7 @@@ _git_switch (
  __git_config_get_set_variables ()
  {
        local prevword word config_file= c=$cword
 -      while [ $c -gt 1 ]; do
 +      while [ $c -gt "$__git_cmd_idx" ]; do
                word="${words[c]}"
                case "$word" in
                --system|--global|--local|--file=*)
@@@ -3013,48 -3013,66 +3013,48 @@@ _git_sparse_checkout (
  
  _git_stash ()
  {
 -      local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
        local subcommands='push list show apply clear drop pop create branch'
        local subcommand="$(__git_find_on_cmdline "$subcommands save")"
 -      if [ -z "$subcommand" -a -n "$(__git_find_on_cmdline "-p")" ]; then
 -              subcommand="push"
 -      fi
 +
        if [ -z "$subcommand" ]; then
 -              case "$cur" in
 -              --*)
 -                      __gitcomp "$save_opts"
 +              case "$((cword - __git_cmd_idx)),$cur" in
 +              *,--*)
 +                      __gitcomp_builtin stash_push
                        ;;
 -              sa*)
 -                      if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
 -                              __gitcomp "save"
 -                      fi
 +              1,sa*)
 +                      __gitcomp "save"
                        ;;
 -              *)
 -                      if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
 -                              __gitcomp "$subcommands"
 -                      fi
 +              1,*)
 +                      __gitcomp "$subcommands"
                        ;;
                esac
 -      else
 -              case "$subcommand,$cur" in
 -              push,--*)
 -                      __gitcomp "$save_opts --message"
 -                      ;;
 -              save,--*)
 -                      __gitcomp "$save_opts"
 -                      ;;
 -              apply,--*|pop,--*)
 -                      __gitcomp "--index --quiet"
 -                      ;;
 -              drop,--*)
 -                      __gitcomp "--quiet"
 -                      ;;
 -              list,--*)
 -                      __gitcomp "--name-status --oneline --patch-with-stat"
 -                      ;;
 -              show,--*)
 -                      __gitcomp "$__git_diff_common_options"
 -                      ;;
 -              branch,--*)
 -                      ;;
 -              branch,*)
 -                      if [ $cword -eq 3 ]; then
 -                              __git_complete_refs
 -                      else
 -                              __gitcomp_nl "$(__git stash list \
 -                                              | sed -n -e 's/:.*//p')"
 -                      fi
 -                      ;;
 -              show,*|apply,*|drop,*|pop,*)
 +              return
 +      fi
 +
 +      case "$subcommand,$cur" in
 +      list,--*)
 +              # NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show()
 +              __gitcomp_builtin stash_list "$__git_log_common_options $__git_diff_common_options"
 +              ;;
 +      show,--*)
 +              __gitcomp_builtin stash_show "$__git_diff_common_options"
 +              ;;
 +      *,--*)
 +              __gitcomp_builtin "stash_$subcommand"
 +              ;;
 +      branch,*)
 +              if [ $cword -eq $((__git_cmd_idx+2)) ]; then
 +                      __git_complete_refs
 +              else
                        __gitcomp_nl "$(__git stash list \
                                        | sed -n -e 's/:.*//p')"
 -                      ;;
 -              *)
 -                      ;;
 -              esac
 -      fi
 +              fi
 +              ;;
 +      show,*|apply,*|drop,*|pop,*)
 +              __gitcomp_nl "$(__git stash list \
 +                              | sed -n -e 's/:.*//p')"
 +              ;;
 +      esac
  }
  
  _git_submodule ()
@@@ -3207,7 -3225,7 +3207,7 @@@ _git_svn (
  
  _git_tag ()
  {
 -      local i c=1 f=0
 +      local i c="$__git_cmd_idx" f=0
        while [ $c -lt $cword ]; do
                i="${words[c]}"
                case "$i" in
@@@ -3250,9 -3268,10 +3250,10 @@@ _git_whatchanged (
  __git_complete_worktree_paths ()
  {
        local IFS=$'\n'
+       # Generate completion reply from worktree list skipping the first
+       # entry: it's the path of the main worktree, which can't be moved,
+       # removed, locked, etc.
        __gitcomp_nl "$(git worktree list --porcelain |
-               # Skip the first entry: it's the path of the main worktree,
-               # which can't be moved, removed, locked, etc.
                sed -n -e '2,$ s/^worktree //p')"
  }
  
@@@ -3380,40 -3399,21 +3381,40 @@@ __git_main (
  {
        local i c=1 command __git_dir __git_repo_path
        local __git_C_args C_args_count=0
 +      local __git_cmd_idx
  
        while [ $c -lt $cword ]; do
                i="${words[c]}"
                case "$i" in
 -              --git-dir=*) __git_dir="${i#--git-dir=}" ;;
 -              --git-dir)   ((c++)) ; __git_dir="${words[c]}" ;;
 -              --bare)      __git_dir="." ;;
 -              --help) command="help"; break ;;
 -              -c|--work-tree|--namespace) ((c++)) ;;
 -              -C)     __git_C_args[C_args_count++]=-C
 +              --git-dir=*)
 +                      __git_dir="${i#--git-dir=}"
 +                      ;;
 +              --git-dir)
 +                      ((c++))
 +                      __git_dir="${words[c]}"
 +                      ;;
 +              --bare)
 +                      __git_dir="."
 +                      ;;
 +              --help)
 +                      command="help"
 +                      break
 +                      ;;
 +              -c|--work-tree|--namespace)
 +                      ((c++))
 +                      ;;
 +              -C)
 +                      __git_C_args[C_args_count++]=-C
                        ((c++))
                        __git_C_args[C_args_count++]="${words[c]}"
                        ;;
 -              -*) ;;
 -              *) command="$i"; break ;;
 +              -*)
 +                      ;;
 +              *)
 +                      command="$i"
 +                      __git_cmd_idx="$c"
 +                      break
 +                      ;;
                esac
                ((c++))
        done
                        ;;
                esac
                case "$cur" in
 -              --*)   __gitcomp "
 +              --*)
 +                      __gitcomp "
                        --paginate
                        --no-pager
                        --git-dir=