Merge branch 'dl/complete-stash'

The command line completion (in contrib/) for "git stash" has been
updated.

* dl/complete-stash:
  git-completion.bash: use __gitcomp_builtin() in _git_stash()
  git-completion.bash: extract from else in _git_stash()
  git-completion.bash: pass $__git_subcommand_idx from __git_main()
This commit is contained in:
Junio C Hamano 2021-05-07 12:47:41 +09:00
Родитель 936e58851a 6131807864
Коммит 848a17c274
1 изменённых файлов: 60 добавлений и 62 удалений

Просмотреть файл

@ -1474,12 +1474,12 @@ _git_branch ()
_git_bundle () _git_bundle ()
{ {
local cmd="${words[2]}" local cmd="${words[__git_subcommand_idx+1]}"
case "$cword" in case "$cword" in
2) $((__git_subcommand_idx+1)))
__gitcomp "create list-heads verify unbundle" __gitcomp "create list-heads verify unbundle"
;; ;;
3) $((__git_subcommand_idx+2)))
# looking for a file # looking for a file
;; ;;
*) *)
@ -1894,7 +1894,7 @@ _git_grep ()
esac esac
case "$cword,$prev" in case "$cword,$prev" in
2,*|*,-*) $((__git_subcommand_idx+1)),*|*,-*)
__git_complete_symbol && return __git_complete_symbol && return
;; ;;
esac esac
@ -3013,52 +3013,52 @@ _git_sparse_checkout ()
_git_stash () _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 subcommands='push list show apply clear drop pop create branch'
local subcommand="$(__git_find_on_cmdline "$subcommands save")" 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 if [ -z "$subcommand" ]; then
case "$cur" in case "$((cword - __git_subcommand_idx)),$cur" in
--*) *,--*)
__gitcomp "$save_opts" __gitcomp_builtin stash_push
;; ;;
sa*) 1,sa*)
if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
__gitcomp "save" __gitcomp "save"
fi
;; ;;
*) 1,*)
if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
__gitcomp "$subcommands" __gitcomp "$subcommands"
fi
;; ;;
esac esac
else return
fi
case "$subcommand,$cur" in case "$subcommand,$cur" in
push,--*) push,--*)
__gitcomp "$save_opts --message" __gitcomp_builtin stash_push
;; ;;
save,--*) save,--*)
__gitcomp "$save_opts" __gitcomp_builtin stash_save
;; ;;
apply,--*|pop,--*) pop,--*)
__gitcomp "--index --quiet" __gitcomp_builtin stash_pop
;;
apply,--*)
__gitcomp_builtin stash_apply
;; ;;
drop,--*) drop,--*)
__gitcomp "--quiet" __gitcomp_builtin stash_drop
;; ;;
list,--*) list,--*)
__gitcomp "--name-status --oneline --patch-with-stat" # 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,--*) show,--*)
__gitcomp "--include-untracked --only-untracked $__git_diff_common_options" __gitcomp_builtin stash_show "$__git_diff_common_options"
;; ;;
branch,--*) branch,--*)
__gitcomp_builtin stash_branch
;; ;;
branch,*) branch,*)
if [ $cword -eq 3 ]; then if [ $cword -eq $((__git_subcommand_idx+2)) ]; then
__git_complete_refs __git_complete_refs
else else
__gitcomp_nl "$(__git stash list \ __gitcomp_nl "$(__git stash list \
@ -3072,7 +3072,6 @@ _git_stash ()
*) *)
;; ;;
esac esac
fi
} }
_git_submodule () _git_submodule ()
@ -3277,11 +3276,9 @@ __git_complete_worktree_paths ()
_git_worktree () _git_worktree ()
{ {
local subcommands="add list lock move prune remove unlock" local subcommands="add list lock move prune remove unlock"
local subcommand subcommand_idx local subcommand
subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")" subcommand="$(__git_find_on_cmdline "$subcommands")"
subcommand_idx="${subcommand% *}"
subcommand="${subcommand#* }"
case "$subcommand,$cur" in case "$subcommand,$cur" in
,*) ,*)
@ -3306,7 +3303,7 @@ _git_worktree ()
# be either the 'add' subcommand, the unstuck # be either the 'add' subcommand, the unstuck
# argument of an option (e.g. branch for -b|-B), or # argument of an option (e.g. branch for -b|-B), or
# the path for the new worktree. # the path for the new worktree.
if [ $cword -eq $((subcommand_idx+1)) ]; then if [ $cword -eq $((__git_subcommand_idx+2)) ]; then
# Right after the 'add' subcommand: have to # Right after the 'add' subcommand: have to
# complete the path, so fall back to Bash # complete the path, so fall back to Bash
# filename completion. # filename completion.
@ -3330,7 +3327,7 @@ _git_worktree ()
__git_complete_worktree_paths __git_complete_worktree_paths
;; ;;
move,*) move,*)
if [ $cword -eq $((subcommand_idx+1)) ]; then if [ $cword -eq $((__git_subcommand_idx+2)) ]; then
# The first parameter must be an existing working # The first parameter must be an existing working
# tree to be moved. # tree to be moved.
__git_complete_worktree_paths __git_complete_worktree_paths
@ -3398,6 +3395,7 @@ __git_main ()
{ {
local i c=1 command __git_dir __git_repo_path local i c=1 command __git_dir __git_repo_path
local __git_C_args C_args_count=0 local __git_C_args C_args_count=0
local __git_subcommand_idx
while [ $c -lt $cword ]; do while [ $c -lt $cword ]; do
i="${words[c]}" i="${words[c]}"
@ -3412,7 +3410,7 @@ __git_main ()
__git_C_args[C_args_count++]="${words[c]}" __git_C_args[C_args_count++]="${words[c]}"
;; ;;
-*) ;; -*) ;;
*) command="$i"; break ;; *) command="$i"; __git_subcommand_idx="$c"; break ;;
esac esac
((c++)) ((c++))
done done