{"thread":{"id":"61364","subject":"[PATCH 2/2] completion: add docs on how to add subcommand completions","startedAt":"2024-04-24T21:06:00Z","lastAt":"2024-04-24T22:22:44Z","messageCount":6,"participants":["Roland Hieber","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"493437","messageId":"20240424210549.256256-2-rhi@pengutronix.de","threadId":"61364","inReplyTo":"20240424210549.256256-1-rhi@pengutronix.de","subject":"[PATCH 2/2] completion: add docs on how to add subcommand completions","fromName":"Roland Hieber","fromEmail":"rhi@pengutronix.de","sentAt":"2024-04-24T21:05:48Z","receivedAt":"2024-04-24T21:06:00Z","isPatch":true,"sender":{"key":"rhi@pengutronix.de","avatar":"https://avatars.githubusercontent.com/u/192014?v=4"},"body":"It took me more than a few tries and a good lecture of __git_main to\nunderstand that the two paragraphs above really only refer to adding\ncompletion functions for executables that are not called through git's\nsubcommand magic. Add a few sentences for that case.\n\nSigned-off-by: Roland Hieber <rhi@pengutronix.de>\n---\n contrib/completion/git-completion.bash | 7 +++++++\n 1 file changed, 7 insertions(+)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex ffcc55484bcd..f0c8353c1cdb 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -40,6 +40,13 @@\n #\n #   __git_complete gk gitk\n #\n+# To add completion for git subcommands that live in external scripts,\n+# define a function of the form '_git_${subcommand}' while replacing all dashes\n+# with underscores, and the main git completion will make use of it.\n+# For example, to add completeion after 'git do-my-stuff' (which could e.g. live\n+# in /usr/bin/git-do-stuff), name the completion function '_git_do_stuff'.\n+# See _git_show, _git_bisect etc. below for more examples.\n+#\n # Compatible with bash 3.2.57.\n #\n # You can set the following environment variables to influence the behavior of\n-- \n2.39.2\n\n"},{"id":"493438","messageId":"20240424210549.256256-1-rhi@pengutronix.de","threadId":"61364","inReplyTo":null,"subject":"[PATCH 1/2] completion: add 'symbolic-ref'","fromName":"Roland Hieber","fromEmail":"rhi@pengutronix.de","sentAt":"2024-04-24T21:05:47Z","receivedAt":"2024-04-24T21:06:00Z","isPatch":true,"sender":{"key":"rhi@pengutronix.de","avatar":"https://avatars.githubusercontent.com/u/192014?v=4"},"body":"Even 'symbolic-ref' is only completed when\nGIT_COMPLETION_SHOW_ALL_COMMANDS=1 is set, it currently defaults to\ncompleting file names, which is not very helpful. Add a simple\ncompletion function which completes options and refs.\n\nSigned-off-by: Roland Hieber <rhi@pengutronix.de>\n---\n contrib/completion/git-completion.bash | 11 +++++++++++\n t/t9902-completion.sh                  | 16 ++++++++++++++++\n 2 files changed, 27 insertions(+)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 75193ded4bde..ffcc55484bcd 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -3581,6 +3581,17 @@ _git_svn ()\n \tfi\n }\n \n+_git_symbolic_ref () {\n+\tcase \"$cur\" in\n+\t--*)\n+\t\t__gitcomp \"--delete --quiet --short --recurse --no-recurse\"\n+\t\treturn\n+\t\t;;\n+\tesac\n+\t\n+\t__git_complete_refs\n+}\n+\n _git_tag ()\n {\n \tlocal i c=\"$__git_cmd_idx\" f=0\ndiff --git a/t/t9902-completion.sh b/t/t9902-completion.sh\nindex 569cf2310434..a34953da6c96 100755\n--- a/t/t9902-completion.sh\n+++ b/t/t9902-completion.sh\n@@ -2518,6 +2518,22 @@ test_expect_success 'complete tree filename with metacharacters' '\n \tEOF\n '\n \n+test_expect_success 'symbolic-ref completes short ref names ' '\n+\ttest_completion \"git symbolic-ref foo m\" <<-\\EOF\n+\tmain Z\n+\tmybranch Z\n+\tmytag Z\n+\tEOF\n+'\n+test_expect_success 'symbolic-ref completes full ref names' '\n+\ttest_completion \"git symbolic-ref foo refs/\" <<-\\EOF\n+\trefs/heads/main Z\n+\trefs/heads/mybranch Z\n+\trefs/tags/mytag Z\n+\trefs/tags/A Z\n+\tEOF\n+'\n+\n test_expect_success PERL 'send-email' '\n \ttest_completion \"git send-email --cov\" <<-\\EOF &&\n \t--cover-from-description=Z\n-- \n2.39.2\n\n"},{"id":"493439","messageId":"20240424211709.ppljgyxzu2rmkamw@pengutronix.de","threadId":"61364","inReplyTo":"20240424210549.256256-2-rhi@pengutronix.de","subject":"Re: [PATCH 2/2] completion: add docs on how to add subcommand completions","fromName":"Roland Hieber","fromEmail":"rhi@pengutronix.de","sentAt":"2024-04-24T21:17:09Z","receivedAt":"2024-04-24T21:17:12Z","isPatch":true,"sender":{"key":"rhi@pengutronix.de","avatar":"https://avatars.githubusercontent.com/u/192014?v=4"},"body":"On Wed, Apr 24, 2024 at 11:05:48PM +0200, Roland Hieber wrote:\n> It took me more than a few tries and a good lecture of __git_main to\n> understand that the two paragraphs above really only refer to adding\n> completion functions for executables that are not called through git's\n> subcommand magic. Add a few sentences for that case.\n> \n> Signed-off-by: Roland Hieber <rhi@pengutronix.de>\n> ---\n>  contrib/completion/git-completion.bash | 7 +++++++\n>  1 file changed, 7 insertions(+)\n> \n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index ffcc55484bcd..f0c8353c1cdb 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -40,6 +40,13 @@\n>  #\n>  #   __git_complete gk gitk\n>  #\n> +# To add completion for git subcommands that live in external scripts,\n> +# define a function of the form '_git_${subcommand}' while replacing all dashes\n> +# with underscores, and the main git completion will make use of it.\n> +# For example, to add completeion after 'git do-my-stuff' (which could e.g. live\n\nAh, of course its s/completeion/completion/ …\n\n - Roland\n\n> +# in /usr/bin/git-do-stuff), name the completion function '_git_do_stuff'.\n> +# See _git_show, _git_bisect etc. below for more examples.\n> +#\n>  # Compatible with bash 3.2.57.\n>  #\n>  # You can set the following environment variables to influence the behavior of\n> -- \n> 2.39.2\n> \n> \n\n-- \nRoland Hieber, Pengutronix e.K.          | r.hieber@pengutronix.de     |\nSteuerwalder Str. 21                     | https://www.pengutronix.de/ |\n31137 Hildesheim, Germany                | Phone: +49-5121-206917-0    |\nAmtsgericht Hildesheim, HRA 2686         | Fax:   +49-5121-206917-5555 |\n"},{"id":"493442","messageId":"xmqqedauxx2c.fsf@gitster.g","threadId":"61364","inReplyTo":"20240424210549.256256-2-rhi@pengutronix.de","subject":"Re: [PATCH 2/2] completion: add docs on how to add subcommand completions","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-04-24T21:36:27Z","receivedAt":"2024-04-24T21:36:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Roland Hieber <rhi@pengutronix.de> writes:\n\n> +# To add completion for git subcommands that live in external scripts,\n> +# define a function of the form '_git_${subcommand}' while replacing all dashes\n> +# with underscores, and the main git completion will make use of it.\n> +# For example, to add completeion after 'git do-my-stuff' (which could e.g. live\n> +# in /usr/bin/git-do-stuff), name the completion function '_git_do_stuff'.\n\nYou have either an extra \"-my\", or two \"-my\"s missing, in the above.\n\n> +# See _git_show, _git_bisect etc. below for more examples.\n> +#\n>  # Compatible with bash 3.2.57.\n>  #\n>  # You can set the following environment variables to influence the behavior of\n"},{"id":"493443","messageId":"20240424214147.qlpyy3cdmb43n47v@pengutronix.de","threadId":"61364","inReplyTo":"xmqqedauxx2c.fsf@gitster.g","subject":"Re: [PATCH 2/2] completion: add docs on how to add subcommand completions","fromName":"Roland Hieber","fromEmail":"rhi@pengutronix.de","sentAt":"2024-04-24T21:41:47Z","receivedAt":"2024-04-24T21:41:50Z","isPatch":true,"sender":{"key":"rhi@pengutronix.de","avatar":"https://avatars.githubusercontent.com/u/192014?v=4"},"body":"On Wed, Apr 24, 2024 at 02:36:27PM -0700, Junio C Hamano wrote:\n> Roland Hieber <rhi@pengutronix.de> writes:\n> \n> > +# To add completion for git subcommands that live in external scripts,\n> > +# define a function of the form '_git_${subcommand}' while replacing all dashes\n> > +# with underscores, and the main git completion will make use of it.\n> > +# For example, to add completeion after 'git do-my-stuff' (which could e.g. live\n> > +# in /usr/bin/git-do-stuff), name the completion function '_git_do_stuff'.\n> \n> You have either an extra \"-my\", or two \"-my\"s missing, in the above.\n\nAh, and I deleted one '-my' in the line before sending it…\nWill send a v2.\n\n - Roland\n\n> \n> > +# See _git_show, _git_bisect etc. below for more examples.\n> > +#\n> >  # Compatible with bash 3.2.57.\n> >  #\n> >  # You can set the following environment variables to influence the behavior of\n> \n\n-- \nRoland Hieber, Pengutronix e.K.          | r.hieber@pengutronix.de     |\nSteuerwalder Str. 21                     | https://www.pengutronix.de/ |\n31137 Hildesheim, Germany                | Phone: +49-5121-206917-0    |\nAmtsgericht Hildesheim, HRA 2686         | Fax:   +49-5121-206917-5555 |\n"},{"id":"493448","messageId":"xmqqo79ywgd3.fsf@gitster.g","threadId":"61364","inReplyTo":"20240424210549.256256-2-rhi@pengutronix.de","subject":"Re: [PATCH 2/2] completion: add docs on how to add subcommand completions","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-04-24T22:22:32Z","receivedAt":"2024-04-24T22:22:44Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Roland Hieber <rhi@pengutronix.de> writes:\n\n> It took me more than a few tries and a good lecture of __git_main to\n> understand that the two paragraphs above really only refer to adding\n> completion functions for executables that are not called through git's\n> subcommand magic. Add a few sentences for that case.\n\nOK.  Perhaps the two examples also need some more explanation to\nsave the next person from wasting their time figuring out what they\nare trying to say?  That would be a separate topic, but it would be\nnice to fix it while our minds are fresh on that issue.\n\nAs I already said, modulo confusion around \"-my\", the patch looks\ngood to me.\n\nThanks.\n"}]}