File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2121# source ~/.git-completion.sh
2222# 3) Consider changing your PS1 to also show the current branch,
2323# see git-prompt.sh for details.
24+ #
25+ # If you use complex aliases of form '!f() { ... }; f', you can use the null
26+ # command ':' as the first command in the function body to declare the desired
27+ # completion style. For example '!f() { : git commit ; ... }; f' will
28+ # tell the completion to use commit completion. This also works with aliases
29+ # of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".
2430
2531case " $COMP_WORDBREAKS " in
2632* :* ) : great ;;
@@ -781,6 +787,10 @@ __git_aliased_command ()
781787 -* ) : option ;;
782788 * =* ) : setting env ;;
783789 git) : git itself ;;
790+ \(\) ) : skip parens of shell function definition ;;
791+ {) : skip start of shell helper function ;;
792+ :) : skip null command ;;
793+ \' * ) : skip opening quote after sh -c ;;
784794 * )
785795 echo " $word "
786796 return
Original file line number Diff line number Diff line change @@ -550,6 +550,33 @@ test_expect_success 'complete files' '
550550 test_completion "git add mom" "momified"
551551'
552552
553+ test_expect_success " completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
554+ test_config alias.co "!sh -c ' " '" ' git checkout ...' " '" ' " &&
555+ test_completion "git co m" <<-\EOF
556+ master Z
557+ mybranch Z
558+ mytag Z
559+ EOF
560+ '
561+
562+ test_expect_success ' completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
563+ test_config alias.co "!f () { VAR=val git checkout ... ; } f" &&
564+ test_completion "git co m" <<-\EOF
565+ master Z
566+ mybranch Z
567+ mytag Z
568+ EOF
569+ '
570+
571+ test_expect_success ' completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
572+ test_config alias.co "!f() { : git checkout ; if ... } f" &&
573+ test_completion "git co m" <<-\EOF
574+ master Z
575+ mybranch Z
576+ mytag Z
577+ EOF
578+ '
579+
553580test_expect_failure ' complete with tilde expansion' '
554581 git init tmp && cd tmp &&
555582 test_when_finished "cd .. && rm -rf tmp" &&
You can’t perform that action at this time.
0 commit comments