From: Junio C Hamano Date: Wed, 20 Sep 2023 18:28:22 +0000 (-0700) Subject: completion: loosen and document the requirement around completing alias X-Git-Tag: v2.43.0-rc0~62^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8d73a2cc036199a25cc97586937267ec14cb6eae;p=thirdparty%2Fgit.git completion: loosen and document the requirement around completing alias Recently we started to tell users to spell ": git foo ;" with space(s) around 'foo' for an alias to be completed similarly to the 'git foo' command. It however is easy to also allow users to spell it in a more natural way with the semicolon attached to 'foo', i.e. ": git foo;". Also, add a comment to note that 'git' is optional and writing ": foo;" would complete the alias just fine. Signed-off-by: Junio C Hamano --- diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 47fd664ea5..477ef8157a 100644 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -28,7 +28,8 @@ # 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 ; ... '". -# Be sure to add a space between the command name and the ';'. +# Note that "git" is optional --- '!f() { : commit; ...}; f' would complete +# just like the 'git commit' command. # # If you have a command that is not part of git, but you would still # like completion, you can use __git_complete: @@ -1183,7 +1184,7 @@ __git_aliased_command () :) : skip null command ;; \'*) : skip opening quote after sh -c ;; *) - cur="$word" + cur="${word%;}" break esac done diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 47e20fb8b1..a7c3b4eb63 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -2464,6 +2464,24 @@ test_expect_success 'completion used completion for alias: !f() { : git completion for alias: !f() { : ; ... }' ' + test_config alias.co "!f() { : checkout ; if ... } f" && + test_completion "git co m" <<-\EOF + main Z + mybranch Z + mytag Z + EOF +' + +test_expect_success 'completion used completion for alias: !f() { : ; ... }' ' + test_config alias.co "!f() { : checkout; if ... } f" && + test_completion "git co m" <<-\EOF + main Z + mybranch Z + mytag Z + EOF +' + test_expect_success 'completion without explicit _git_xxx function' ' test_completion "git version --" <<-\EOF --build-options Z