Skip to content

Commit 848a17c

Browse files
committed
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()
2 parents 936e588 + 6131807 commit 848a17c

File tree

1 file changed

+60
-62
lines changed

1 file changed

+60
-62
lines changed

contrib/completion/git-completion.bash

Lines changed: 60 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,12 +1474,12 @@ _git_branch ()
14741474

14751475
_git_bundle ()
14761476
{
1477-
local cmd="${words[2]}"
1477+
local cmd="${words[__git_subcommand_idx+1]}"
14781478
case "$cword" in
1479-
2)
1479+
$((__git_subcommand_idx+1)))
14801480
__gitcomp "create list-heads verify unbundle"
14811481
;;
1482-
3)
1482+
$((__git_subcommand_idx+2)))
14831483
# looking for a file
14841484
;;
14851485
*)
@@ -1894,7 +1894,7 @@ _git_grep ()
18941894
esac
18951895

18961896
case "$cword,$prev" in
1897-
2,*|*,-*)
1897+
$((__git_subcommand_idx+1)),*|*,-*)
18981898
__git_complete_symbol && return
18991899
;;
19001900
esac
@@ -3013,66 +3013,65 @@ _git_sparse_checkout ()
30133013

30143014
_git_stash ()
30153015
{
3016-
local save_opts='--all --keep-index --no-keep-index --quiet --patch --include-untracked'
30173016
local subcommands='push list show apply clear drop pop create branch'
30183017
local subcommand="$(__git_find_on_cmdline "$subcommands save")"
3019-
if [ -z "$subcommand" -a -n "$(__git_find_on_cmdline "-p")" ]; then
3020-
subcommand="push"
3021-
fi
3018+
30223019
if [ -z "$subcommand" ]; then
3023-
case "$cur" in
3024-
--*)
3025-
__gitcomp "$save_opts"
3020+
case "$((cword - __git_subcommand_idx)),$cur" in
3021+
*,--*)
3022+
__gitcomp_builtin stash_push
30263023
;;
3027-
sa*)
3028-
if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
3029-
__gitcomp "save"
3030-
fi
3024+
1,sa*)
3025+
__gitcomp "save"
30313026
;;
3032-
*)
3033-
if [ -z "$(__git_find_on_cmdline "$save_opts")" ]; then
3034-
__gitcomp "$subcommands"
3035-
fi
3027+
1,*)
3028+
__gitcomp "$subcommands"
30363029
;;
30373030
esac
3038-
else
3039-
case "$subcommand,$cur" in
3040-
push,--*)
3041-
__gitcomp "$save_opts --message"
3042-
;;
3043-
save,--*)
3044-
__gitcomp "$save_opts"
3045-
;;
3046-
apply,--*|pop,--*)
3047-
__gitcomp "--index --quiet"
3048-
;;
3049-
drop,--*)
3050-
__gitcomp "--quiet"
3051-
;;
3052-
list,--*)
3053-
__gitcomp "--name-status --oneline --patch-with-stat"
3054-
;;
3055-
show,--*)
3056-
__gitcomp "--include-untracked --only-untracked $__git_diff_common_options"
3057-
;;
3058-
branch,--*)
3059-
;;
3060-
branch,*)
3061-
if [ $cword -eq 3 ]; then
3062-
__git_complete_refs
3063-
else
3064-
__gitcomp_nl "$(__git stash list \
3065-
| sed -n -e 's/:.*//p')"
3066-
fi
3067-
;;
3068-
show,*|apply,*|drop,*|pop,*)
3031+
return
3032+
fi
3033+
3034+
case "$subcommand,$cur" in
3035+
push,--*)
3036+
__gitcomp_builtin stash_push
3037+
;;
3038+
save,--*)
3039+
__gitcomp_builtin stash_save
3040+
;;
3041+
pop,--*)
3042+
__gitcomp_builtin stash_pop
3043+
;;
3044+
apply,--*)
3045+
__gitcomp_builtin stash_apply
3046+
;;
3047+
drop,--*)
3048+
__gitcomp_builtin stash_drop
3049+
;;
3050+
list,--*)
3051+
# NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show()
3052+
__gitcomp_builtin stash_list "$__git_log_common_options $__git_diff_common_options"
3053+
;;
3054+
show,--*)
3055+
__gitcomp_builtin stash_show "$__git_diff_common_options"
3056+
;;
3057+
branch,--*)
3058+
__gitcomp_builtin stash_branch
3059+
;;
3060+
branch,*)
3061+
if [ $cword -eq $((__git_subcommand_idx+2)) ]; then
3062+
__git_complete_refs
3063+
else
30693064
__gitcomp_nl "$(__git stash list \
30703065
| sed -n -e 's/:.*//p')"
3071-
;;
3072-
*)
3073-
;;
3074-
esac
3075-
fi
3066+
fi
3067+
;;
3068+
show,*|apply,*|drop,*|pop,*)
3069+
__gitcomp_nl "$(__git stash list \
3070+
| sed -n -e 's/:.*//p')"
3071+
;;
3072+
*)
3073+
;;
3074+
esac
30763075
}
30773076

30783077
_git_submodule ()
@@ -3277,11 +3276,9 @@ __git_complete_worktree_paths ()
32773276
_git_worktree ()
32783277
{
32793278
local subcommands="add list lock move prune remove unlock"
3280-
local subcommand subcommand_idx
3279+
local subcommand
32813280

3282-
subcommand="$(__git_find_on_cmdline --show-idx "$subcommands")"
3283-
subcommand_idx="${subcommand% *}"
3284-
subcommand="${subcommand#* }"
3281+
subcommand="$(__git_find_on_cmdline "$subcommands")"
32853282

32863283
case "$subcommand,$cur" in
32873284
,*)
@@ -3306,7 +3303,7 @@ _git_worktree ()
33063303
# be either the 'add' subcommand, the unstuck
33073304
# argument of an option (e.g. branch for -b|-B), or
33083305
# the path for the new worktree.
3309-
if [ $cword -eq $((subcommand_idx+1)) ]; then
3306+
if [ $cword -eq $((__git_subcommand_idx+2)) ]; then
33103307
# Right after the 'add' subcommand: have to
33113308
# complete the path, so fall back to Bash
33123309
# filename completion.
@@ -3330,7 +3327,7 @@ _git_worktree ()
33303327
__git_complete_worktree_paths
33313328
;;
33323329
move,*)
3333-
if [ $cword -eq $((subcommand_idx+1)) ]; then
3330+
if [ $cword -eq $((__git_subcommand_idx+2)) ]; then
33343331
# The first parameter must be an existing working
33353332
# tree to be moved.
33363333
__git_complete_worktree_paths
@@ -3398,6 +3395,7 @@ __git_main ()
33983395
{
33993396
local i c=1 command __git_dir __git_repo_path
34003397
local __git_C_args C_args_count=0
3398+
local __git_subcommand_idx
34013399

34023400
while [ $c -lt $cword ]; do
34033401
i="${words[c]}"
@@ -3412,7 +3410,7 @@ __git_main ()
34123410
__git_C_args[C_args_count++]="${words[c]}"
34133411
;;
34143412
-*) ;;
3415-
*) command="$i"; break ;;
3413+
*) command="$i"; __git_subcommand_idx="$c"; break ;;
34163414
esac
34173415
((c++))
34183416
done

0 commit comments

Comments
 (0)