diff mbox series

completion: loosen and document the requirement around completing alias

Message ID xmqqy1h08zsp.fsf_-_@gitster.g (mailing list archive)
State New, archived
Headers show
Series completion: loosen and document the requirement around completing alias | expand

Commit Message

Junio C Hamano Sept. 20, 2023, 6:28 p.m. UTC
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 <gitster@pobox.com>
---

 * We've discussed this when we reviewed the topic that just hit
   'master'.  Before we forget...

 contrib/completion/git-completion.bash | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

Comments

Junio C Hamano Sept. 20, 2023, 6:46 p.m. UTC | #1
Junio C Hamano <gitster@pobox.com> writes:

>  * We've discussed this when we reviewed the topic that just hit
>    'master'.  Before we forget...
>
>  contrib/completion/git-completion.bash | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)

And here is an obligatory "test" update I will squash into the main
patch.  The new ones copy a canonical ": git <cmd> ; ..."  test and
remove 'git' and also the space before the semicolon.

diff --git c/t/t9902-completion.sh w/t/t9902-completion.sh
index 47e20fb8b1..a7c3b4eb63 100755
--- c/t/t9902-completion.sh
+++ w/t/t9902-completion.sh
@@ -2464,6 +2464,24 @@ test_expect_success 'completion used <cmd> completion for alias: !f() { : git <c
 	EOF
 '
 
+test_expect_success 'completion used <cmd> completion for alias: !f() { : <cmd> ; ... }' '
+	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 <cmd> completion for alias: !f() { : <cmd>; ... }' '
+	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
Linus Arver Sept. 22, 2023, 6:31 p.m. UTC | #2
Junio C Hamano <gitster@pobox.com> writes:

> Junio C Hamano <gitster@pobox.com> writes:
>
>>  * We've discussed this when we reviewed the topic that just hit
>>    'master'.  Before we forget...
>>
>>  contrib/completion/git-completion.bash | 5 +++--
>>  1 file changed, 3 insertions(+), 2 deletions(-)
>
> And here is an obligatory "test" update I will squash into the main
> patch.  The new ones copy a canonical ": git <cmd> ; ..."  test and
> remove 'git' and also the space before the semicolon.
>
> diff --git c/t/t9902-completion.sh w/t/t9902-completion.sh
> index 47e20fb8b1..a7c3b4eb63 100755
> --- c/t/t9902-completion.sh
> +++ w/t/t9902-completion.sh
> @@ -2464,6 +2464,24 @@ test_expect_success 'completion used <cmd> completion for alias: !f() { : git <c
>  	EOF
>  '
>  
> +test_expect_success 'completion used <cmd> completion for alias: !f() { : <cmd> ; ... }' '
> +	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 <cmd> completion for alias: !f() { : <cmd>; ... }' '
> +	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

LGTM, thanks!
Junio C Hamano Sept. 22, 2023, 7:49 p.m. UTC | #3
Linus Arver <linusa@google.com> writes:

> Junio C Hamano <gitster@pobox.com> writes:
>
>> Junio C Hamano <gitster@pobox.com> writes:
>>
>>>  * We've discussed this when we reviewed the topic that just hit
>>>    'master'.  Before we forget...
> ...
> LGTM, thanks!

Thanks for reading.
diff mbox series

Patch

diff --git c/contrib/completion/git-completion.bash w/contrib/completion/git-completion.bash
index 47fd664ea5..477ef8157a 100644
--- c/contrib/completion/git-completion.bash
+++ w/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