Skip to content

Commit

Permalink
Merge branch 'sp/complete-ext-alias'
Browse files Browse the repository at this point in the history
* sp/complete-ext-alias:
  completion: handle '!f() { ... }; f' and "!sh -c '...' -" aliases
  • Loading branch information
Junio C Hamano committed Jun 25, 2014
2 parents 2a20f4b + 56f24e8 commit af6ba0e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
10 changes: 10 additions & 0 deletions contrib/completion/git-completion.bash
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
# source ~/.git-completion.sh
# 3) Consider changing your PS1 to also show the current branch,
# see git-prompt.sh for details.
#
# If you use complex aliases of form '!f() { ... }; f', you can use the null
# command ':' as the first command in the function body to declare the desired
# completion style. For example '!f() { : git commit ; ... }; f' will
# tell the completion to use commit completion. This also works with aliases
# of form "!sh -c '...'". For example, "!sh -c ': git commit ; ... '".

case "$COMP_WORDBREAKS" in
*:*) : great ;;
Expand Down Expand Up @@ -781,6 +787,10 @@ __git_aliased_command ()
-*) : option ;;
*=*) : setting env ;;
git) : git itself ;;
\(\)) : skip parens of shell function definition ;;
{) : skip start of shell helper function ;;
:) : skip null command ;;
\'*) : skip opening quote after sh -c ;;
*)
echo "$word"
return
Expand Down
27 changes: 27 additions & 0 deletions t/t9902-completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,33 @@ test_expect_success 'complete files' '
test_completion "git add mom" "momified"
'

test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" &&
test_completion "git co m" <<-\EOF
master Z
mybranch Z
mytag Z
EOF
'

test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
test_config alias.co "!f () { VAR=val git checkout ... ; } f" &&
test_completion "git co m" <<-\EOF
master Z
mybranch Z
mytag Z
EOF
'

test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '
test_config alias.co "!f() { : git checkout ; if ... } f" &&
test_completion "git co m" <<-\EOF
master Z
mybranch Z
mytag Z
EOF
'

test_expect_failure 'complete with tilde expansion' '
git init tmp && cd tmp &&
test_when_finished "cd .. && rm -rf tmp" &&
Expand Down

0 comments on commit af6ba0e

Please sign in to comment.