@@ -1474,12 +1474,12 @@ _git_branch ()
1474
1474
1475
1475
_git_bundle ()
1476
1476
{
1477
- local cmd=" ${words[2 ]} "
1477
+ local cmd=" ${words[__git_subcommand_idx+1 ]} "
1478
1478
case " $cword " in
1479
- 2 )
1479
+ $(( __git_subcommand_idx + 1 )) )
1480
1480
__gitcomp " create list-heads verify unbundle"
1481
1481
;;
1482
- 3 )
1482
+ $(( __git_subcommand_idx + 2 )) )
1483
1483
# looking for a file
1484
1484
;;
1485
1485
* )
@@ -1894,7 +1894,7 @@ _git_grep ()
1894
1894
esac
1895
1895
1896
1896
case " $cword ,$prev " in
1897
- 2 ,* |* ,-* )
1897
+ $(( __git_subcommand_idx + 1 )) ,* |* ,-* )
1898
1898
__git_complete_symbol && return
1899
1899
;;
1900
1900
esac
@@ -3013,66 +3013,65 @@ _git_sparse_checkout ()
3013
3013
3014
3014
_git_stash ()
3015
3015
{
3016
- local save_opts=' --all --keep-index --no-keep-index --quiet --patch --include-untracked'
3017
3016
local subcommands=' push list show apply clear drop pop create branch'
3018
3017
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
+
3022
3019
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
3026
3023
;;
3027
- sa* )
3028
- if [ -z " $( __git_find_on_cmdline " $save_opts " ) " ]; then
3029
- __gitcomp " save"
3030
- fi
3024
+ 1,sa* )
3025
+ __gitcomp " save"
3031
3026
;;
3032
- * )
3033
- if [ -z " $( __git_find_on_cmdline " $save_opts " ) " ]; then
3034
- __gitcomp " $subcommands "
3035
- fi
3027
+ 1,* )
3028
+ __gitcomp " $subcommands "
3036
3029
;;
3037
3030
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
3069
3064
__gitcomp_nl " $( __git stash list \
3070
3065
| 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
3076
3075
}
3077
3076
3078
3077
_git_submodule ()
@@ -3277,11 +3276,9 @@ __git_complete_worktree_paths ()
3277
3276
_git_worktree ()
3278
3277
{
3279
3278
local subcommands=" add list lock move prune remove unlock"
3280
- local subcommand subcommand_idx
3279
+ local subcommand
3281
3280
3282
- subcommand=" $( __git_find_on_cmdline --show-idx " $subcommands " ) "
3283
- subcommand_idx=" ${subcommand% * } "
3284
- subcommand=" ${subcommand#* } "
3281
+ subcommand=" $( __git_find_on_cmdline " $subcommands " ) "
3285
3282
3286
3283
case " $subcommand ,$cur " in
3287
3284
,* )
@@ -3306,7 +3303,7 @@ _git_worktree ()
3306
3303
# be either the 'add' subcommand, the unstuck
3307
3304
# argument of an option (e.g. branch for -b|-B), or
3308
3305
# the path for the new worktree.
3309
- if [ $cword -eq $(( subcommand_idx + 1 )) ]; then
3306
+ if [ $cword -eq $(( __git_subcommand_idx + 2 )) ]; then
3310
3307
# Right after the 'add' subcommand: have to
3311
3308
# complete the path, so fall back to Bash
3312
3309
# filename completion.
@@ -3330,7 +3327,7 @@ _git_worktree ()
3330
3327
__git_complete_worktree_paths
3331
3328
;;
3332
3329
move,* )
3333
- if [ $cword -eq $(( subcommand_idx + 1 )) ]; then
3330
+ if [ $cword -eq $(( __git_subcommand_idx + 2 )) ]; then
3334
3331
# The first parameter must be an existing working
3335
3332
# tree to be moved.
3336
3333
__git_complete_worktree_paths
@@ -3398,6 +3395,7 @@ __git_main ()
3398
3395
{
3399
3396
local i c=1 command __git_dir __git_repo_path
3400
3397
local __git_C_args C_args_count=0
3398
+ local __git_subcommand_idx
3401
3399
3402
3400
while [ $c -lt $cword ]; do
3403
3401
i=" ${words[c]} "
@@ -3412,7 +3410,7 @@ __git_main ()
3412
3410
__git_C_args[C_args_count++]=" ${words[c]} "
3413
3411
;;
3414
3412
-* ) ;;
3415
- * ) command=" $i " ; break ;;
3413
+ * ) command=" $i " ; __git_subcommand_idx= " $c " ; break ;;
3416
3414
esac
3417
3415
(( c++ ))
3418
3416
done
0 commit comments