@@ -1006,8 +1006,8 @@ __git_complete_revlist ()
1006
1006
1007
1007
__git_complete_remote_or_refspec ()
1008
1008
{
1009
- local cur_=" $cur " cmd=" ${words[1 ]} "
1010
- local i c=2 remote=" " pfx=" " lhs=1 no_complete_refspec=0
1009
+ local cur_=" $cur " cmd=" ${words[__git_cmd_idx ]} "
1010
+ local i c=$(( __git_cmd_idx + 1 )) remote=" " pfx=" " lhs=1 no_complete_refspec=0
1011
1011
if [ " $cmd " = " remote" ]; then
1012
1012
(( c++ ))
1013
1013
fi
@@ -1176,7 +1176,7 @@ __git_aliased_command ()
1176
1176
# --show-idx: Optionally show the index of the found word in the $words array.
1177
1177
__git_find_on_cmdline ()
1178
1178
{
1179
- local word c=1 show_idx
1179
+ local word c=" $__git_cmd_idx " show_idx
1180
1180
1181
1181
while test $# -gt 1; do
1182
1182
case " $1 " in
@@ -1221,7 +1221,7 @@ __git_find_last_on_cmdline ()
1221
1221
done
1222
1222
local wordlist=" $1 "
1223
1223
1224
- while [ $c -gt 1 ]; do
1224
+ while [ $c -gt " $__git_cmd_idx " ]; do
1225
1225
(( c-- ))
1226
1226
for word in $wordlist ; do
1227
1227
if [ " $word " = " ${words[c]} " ]; then
@@ -1306,7 +1306,7 @@ __git_count_arguments ()
1306
1306
local word i c=0
1307
1307
1308
1308
# Skip "git" (first argument)
1309
- for (( i= 1 ; i < ${# words[@]} ; i++ )) ; do
1309
+ for (( i= " $__git_cmd_idx " ; i < ${# words[@]} ; i++ )) ; do
1310
1310
word=" ${words[i]} "
1311
1311
1312
1312
case " $word " in
@@ -1442,7 +1442,7 @@ __git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD
1442
1442
1443
1443
_git_branch ()
1444
1444
{
1445
- local i c=1 only_local_ref=" n" has_r=" n"
1445
+ local i c=" $__git_cmd_idx " only_local_ref=" n" has_r=" n"
1446
1446
1447
1447
while [ $c -lt $cword ]; do
1448
1448
i=" ${words[c]} "
@@ -1474,12 +1474,12 @@ _git_branch ()
1474
1474
1475
1475
_git_bundle ()
1476
1476
{
1477
- local cmd=" ${words[__git_subcommand_idx +1]} "
1477
+ local cmd=" ${words[__git_cmd_idx +1]} "
1478
1478
case " $cword " in
1479
- $(( __git_subcommand_idx + 1 )) )
1479
+ $(( __git_cmd_idx + 1 )) )
1480
1480
__gitcomp " create list-heads verify unbundle"
1481
1481
;;
1482
- $(( __git_subcommand_idx + 2 )) )
1482
+ $(( __git_cmd_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
- $(( __git_subcommand_idx + 1 )) ,* |* ,-* )
1897
+ $(( __git_cmd_idx + 1 )) ,* |* ,-* )
1898
1898
__git_complete_symbol && return
1899
1899
;;
1900
1900
esac
@@ -2474,7 +2474,7 @@ _git_switch ()
2474
2474
__git_config_get_set_variables ()
2475
2475
{
2476
2476
local prevword word config_file= c=$cword
2477
- while [ $c -gt 1 ]; do
2477
+ while [ $c -gt " $__git_cmd_idx " ]; do
2478
2478
word=" ${words[c]} "
2479
2479
case " $word " in
2480
2480
--system|--global|--local|--file=* )
@@ -3017,7 +3017,7 @@ _git_stash ()
3017
3017
local subcommand=" $( __git_find_on_cmdline " $subcommands save" ) "
3018
3018
3019
3019
if [ -z " $subcommand " ]; then
3020
- case " $(( cword - __git_subcommand_idx )) ,$cur " in
3020
+ case " $(( cword - __git_cmd_idx )) ,$cur " in
3021
3021
* ,--* )
3022
3022
__gitcomp_builtin stash_push
3023
3023
;;
@@ -3032,33 +3032,18 @@ _git_stash ()
3032
3032
fi
3033
3033
3034
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
3035
list,--* )
3051
3036
# NEEDSWORK: can we somehow unify this with the options in _git_log() and _git_show()
3052
3037
__gitcomp_builtin stash_list " $__git_log_common_options $__git_diff_common_options "
3053
3038
;;
3054
3039
show,--* )
3055
3040
__gitcomp_builtin stash_show " $__git_diff_common_options "
3056
3041
;;
3057
- branch ,--* )
3058
- __gitcomp_builtin stash_branch
3042
+ * ,--* )
3043
+ __gitcomp_builtin " stash_ $subcommand "
3059
3044
;;
3060
3045
branch,* )
3061
- if [ $cword -eq $(( __git_subcommand_idx + 2 )) ]; then
3046
+ if [ $cword -eq $(( __git_cmd_idx + 2 )) ]; then
3062
3047
__git_complete_refs
3063
3048
else
3064
3049
__gitcomp_nl " $( __git stash list \
@@ -3069,8 +3054,6 @@ _git_stash ()
3069
3054
__gitcomp_nl " $( __git stash list \
3070
3055
| sed -n -e ' s/:.*//p' ) "
3071
3056
;;
3072
- * )
3073
- ;;
3074
3057
esac
3075
3058
}
3076
3059
@@ -3224,7 +3207,7 @@ _git_svn ()
3224
3207
3225
3208
_git_tag ()
3226
3209
{
3227
- local i c=1 f=0
3210
+ local i c=" $__git_cmd_idx " f=0
3228
3211
while [ $c -lt $cword ]; do
3229
3212
i=" ${words[c]} "
3230
3213
case " $i " in
@@ -3276,9 +3259,11 @@ __git_complete_worktree_paths ()
3276
3259
_git_worktree ()
3277
3260
{
3278
3261
local subcommands=" add list lock move prune remove unlock"
3279
- local subcommand
3262
+ local subcommand subcommand_idx
3280
3263
3281
- subcommand=" $( __git_find_on_cmdline " $subcommands " ) "
3264
+ subcommand=" $( __git_find_on_cmdline --show-idx " $subcommands " ) "
3265
+ subcommand_idx=" ${subcommand% * } "
3266
+ subcommand=" ${subcommand#* } "
3282
3267
3283
3268
case " $subcommand ,$cur " in
3284
3269
,* )
@@ -3303,7 +3288,7 @@ _git_worktree ()
3303
3288
# be either the 'add' subcommand, the unstuck
3304
3289
# argument of an option (e.g. branch for -b|-B), or
3305
3290
# the path for the new worktree.
3306
- if [ $cword -eq $(( __git_subcommand_idx + 2 )) ]; then
3291
+ if [ $cword -eq $(( subcommand_idx + 1 )) ]; then
3307
3292
# Right after the 'add' subcommand: have to
3308
3293
# complete the path, so fall back to Bash
3309
3294
# filename completion.
@@ -3327,7 +3312,7 @@ _git_worktree ()
3327
3312
__git_complete_worktree_paths
3328
3313
;;
3329
3314
move,* )
3330
- if [ $cword -eq $(( __git_subcommand_idx + 2 )) ]; then
3315
+ if [ $cword -eq $(( subcommand_idx + 1 )) ]; then
3331
3316
# The first parameter must be an existing working
3332
3317
# tree to be moved.
3333
3318
__git_complete_worktree_paths
@@ -3395,22 +3380,40 @@ __git_main ()
3395
3380
{
3396
3381
local i c=1 command __git_dir __git_repo_path
3397
3382
local __git_C_args C_args_count=0
3398
- local __git_subcommand_idx
3383
+ local __git_cmd_idx
3399
3384
3400
3385
while [ $c -lt $cword ]; do
3401
3386
i=" ${words[c]} "
3402
3387
case " $i " in
3403
- --git-dir=* ) __git_dir=" ${i# --git-dir=} " ;;
3404
- --git-dir) (( c++ )) ; __git_dir=" ${words[c]} " ;;
3405
- --bare) __git_dir=" ." ;;
3406
- --help) command=" help" ; break ;;
3407
- -c|--work-tree|--namespace) (( c++ )) ;;
3408
- -C) __git_C_args[C_args_count++]=-C
3388
+ --git-dir=* )
3389
+ __git_dir=" ${i# --git-dir=} "
3390
+ ;;
3391
+ --git-dir)
3392
+ (( c++ ))
3393
+ __git_dir=" ${words[c]} "
3394
+ ;;
3395
+ --bare)
3396
+ __git_dir=" ."
3397
+ ;;
3398
+ --help)
3399
+ command=" help"
3400
+ break
3401
+ ;;
3402
+ -c|--work-tree|--namespace)
3403
+ (( c++ ))
3404
+ ;;
3405
+ -C)
3406
+ __git_C_args[C_args_count++]=-C
3409
3407
(( c++ ))
3410
3408
__git_C_args[C_args_count++]=" ${words[c]} "
3411
3409
;;
3412
- -* ) ;;
3413
- * ) command=" $i " ; __git_subcommand_idx=" $c " ; break ;;
3410
+ -* )
3411
+ ;;
3412
+ * )
3413
+ command=" $i "
3414
+ __git_cmd_idx=" $c "
3415
+ break
3416
+ ;;
3414
3417
esac
3415
3418
(( c++ ))
3416
3419
done
@@ -3432,7 +3435,8 @@ __git_main ()
3432
3435
;;
3433
3436
esac
3434
3437
case " $cur " in
3435
- --* ) __gitcomp "
3438
+ --* )
3439
+ __gitcomp "
3436
3440
--paginate
3437
3441
--no-pager
3438
3442
--git-dir=
0 commit comments