454
454
455
455
# This function is equivalent to
456
456
#
457
- # __gitcomp " $(git xxx --git-completion-helper) ..."
457
+ # ___git_resolved_builtins= $(git xxx --git-completion-helper)
458
458
#
459
- # except that the output is cached. Accept 1-3 arguments:
459
+ # except that the result of the execution is cached.
460
+ #
461
+ # Accept 1-3 arguments:
460
462
# 1: the git command to execute, this is also the cache key
463
+ # (use "_" when the command contains spaces, e.g. "remote add"
464
+ # becomes "remote_add")
461
465
# 2: extra options to be added on top (e.g. negative forms)
462
466
# 3: options to be excluded
463
- __gitcomp_builtin ()
467
+ __git_resolve_builtins ()
464
468
{
465
- # spaces must be replaced with underscore for multi-word
466
- # commands, e.g. "git remote add" becomes remote_add.
467
469
local cmd=" $1 "
468
470
local incl=" ${2-} "
469
471
local excl=" ${3-} "
@@ -489,7 +491,24 @@ __gitcomp_builtin ()
489
491
eval " $var =\" $options \" "
490
492
fi
491
493
492
- __gitcomp " $options "
494
+ ___git_resolved_builtins=" $options "
495
+ }
496
+
497
+ # This function is equivalent to
498
+ #
499
+ # __gitcomp "$(git xxx --git-completion-helper) ..."
500
+ #
501
+ # except that the output is cached. Accept 1-3 arguments:
502
+ # 1: the git command to execute, this is also the cache key
503
+ # (use "_" when the command contains spaces, e.g. "remote add"
504
+ # becomes "remote_add")
505
+ # 2: extra options to be added on top (e.g. negative forms)
506
+ # 3: options to be excluded
507
+ __gitcomp_builtin ()
508
+ {
509
+ __git_resolve_builtins " $1 " " $2 " " $3 "
510
+
511
+ __gitcomp " $___git_resolved_builtins "
493
512
}
494
513
495
514
# Variation of __gitcomp_nl () that appends to the existing list of
@@ -556,6 +575,26 @@ __gitcomp_file ()
556
575
true
557
576
}
558
577
578
+ # Find the current subcommand for commands that follow the syntax:
579
+ #
580
+ # git <command> <subcommand>
581
+ #
582
+ # 1: List of possible subcommands.
583
+ # 2: Optional subcommand to return when none is found.
584
+ __git_find_subcommand ()
585
+ {
586
+ local subcommand subcommands=" $1 " default_subcommand=" $2 "
587
+
588
+ for subcommand in $subcommands ; do
589
+ if [ " $subcommand " = " ${words[__git_cmd_idx+1]} " ]; then
590
+ echo $subcommand
591
+ return
592
+ fi
593
+ done
594
+
595
+ echo $default_subcommand
596
+ }
597
+
559
598
# Execute 'git ls-files', unless the --committable option is specified, in
560
599
# which case it runs 'git diff-index' to find out the files that can be
561
600
# committed. It return paths relative to the directory specified in the first
@@ -2471,13 +2510,30 @@ _git_rebase ()
2471
2510
2472
2511
_git_reflog ()
2473
2512
{
2474
- local subcommands=" show delete expire"
2475
- local subcommand=" $( __git_find_on_cmdline " $subcommands " ) "
2513
+ local subcommands subcommand
2476
2514
2477
- if [ -z " $subcommand " ]; then
2478
- __gitcomp " $subcommands "
2479
- else
2480
- __git_complete_refs
2515
+ __git_resolve_builtins " reflog"
2516
+
2517
+ subcommands=" $___git_resolved_builtins "
2518
+ subcommand=" $( __git_find_subcommand " $subcommands " " show" ) "
2519
+
2520
+ case " $subcommand ,$cur " in
2521
+ show,--* )
2522
+ __gitcomp "
2523
+ $__git_log_common_options
2524
+ "
2525
+ return
2526
+ ;;
2527
+ $subcommand ,--* )
2528
+ __gitcomp_builtin " reflog_$subcommand "
2529
+ return
2530
+ ;;
2531
+ esac
2532
+
2533
+ __git_complete_refs
2534
+
2535
+ if [ $(( cword - __git_cmd_idx)) -eq 1 ]; then
2536
+ __gitcompappend " $subcommands " " " " $cur " " "
2481
2537
fi
2482
2538
}
2483
2539
0 commit comments