aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2014-06-25 12:23:27 -0700
committerJunio C Hamano <gitster@pobox.com>2014-06-25 12:23:27 -0700
commitaf6ba0eb9e7d39df135e818fc98629dec473306c (patch)
tree4ceb9b813db2d4878b7904b2312936384e14e81d
parent2a20f4b7e298891c9f02eb924ec9ddf4c35ae8ce (diff)
parent56f24e80f0af4dd3591c8f143183b59cf9a34620 (diff)
downloadgit-af6ba0eb9e7d39df135e818fc98629dec473306c.tar.gz
git-af6ba0eb9e7d39df135e818fc98629dec473306c.tar.xz
Merge branch 'sp/complete-ext-alias'
* sp/complete-ext-alias: completion: handle '!f() { ... }; f' and "!sh -c '...' -" aliases
-rw-r--r--contrib/completion/git-completion.bash10
-rwxr-xr-xt/t9902-completion.sh27
2 files changed, 37 insertions, 0 deletions
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 019026efc..7a6e1d797 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -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 ;;
@@ -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
diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
index 2d4beb5e5..1d1c1063a 100755
--- a/t/t9902-completion.sh
+++ b/t/t9902-completion.sh
@@ -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" &&