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
commit 848a17c274

View file

@ -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,66 +3013,65 @@ _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
case "$subcommand,$cur" in fi
push,--*)
__gitcomp "$save_opts --message" case "$subcommand,$cur" in
;; push,--*)
save,--*) __gitcomp_builtin stash_push
__gitcomp "$save_opts" ;;
;; save,--*)
apply,--*|pop,--*) __gitcomp_builtin stash_save
__gitcomp "--index --quiet" ;;
;; pop,--*)
drop,--*) __gitcomp_builtin stash_pop
__gitcomp "--quiet" ;;
;; apply,--*)
list,--*) __gitcomp_builtin stash_apply
__gitcomp "--name-status --oneline --patch-with-stat" ;;
;; drop,--*)
show,--*) __gitcomp_builtin stash_drop
__gitcomp "--include-untracked --only-untracked $__git_diff_common_options" ;;
;; list,--*)
branch,--*) # 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"
branch,*) ;;
if [ $cword -eq 3 ]; then show,--*)
__git_complete_refs __gitcomp_builtin stash_show "$__git_diff_common_options"
else ;;
__gitcomp_nl "$(__git stash list \ branch,--*)
| sed -n -e 's/:.*//p')" __gitcomp_builtin stash_branch
fi ;;
;; branch,*)
show,*|apply,*|drop,*|pop,*) if [ $cword -eq $((__git_subcommand_idx+2)) ]; then
__git_complete_refs
else
__gitcomp_nl "$(__git stash list \ __gitcomp_nl "$(__git stash list \
| sed -n -e 's/:.*//p')" | sed -n -e 's/:.*//p')"
;; fi
*) ;;
;; show,*|apply,*|drop,*|pop,*)
esac __gitcomp_nl "$(__git stash list \
fi | sed -n -e 's/:.*//p')"
;;
*)
;;
esac
} }
_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