git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] completion: improve doc for complex aliases

From
LALinus Arver <linusa@google.com>
Date
Sep 14, 2023, 22:50 UTC
Message-ID
<owlyjzssjro2.fsf@fine.c.googlers.com>
In-Reply-To
<xmqqo7i6khxv.fsf@gitster.g>
Junio C Hamano <gitster@pobox.com> writes:
Show 27 quoted lines
> "Philippe Blain via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
>> From: Philippe Blain <levraiphilippeblain@gmail.com>
>>
>> The completion code can be told to use a particular completion for
>> aliases that shell out by using ': git <cmd> ;' as the first command of
>> the alias. This only works if <cmd> and the semicolon are separated by a
>> space, since if the space is missing __git_aliased_command returns (for
>> example) 'checkout;' instead of just 'checkout', and then
>> __git_complete_command fails to find a completion for 'checkout;'.
>>
>> The examples have that space but it's not clear if it's just for
>> style or if it's mandatory. Explicitly mention it.
>>
>> Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
>> ---
>
> Thanks.  I scanned the case statement in the loop in the function
> and thought "hmph, everybody says ': git <cmd> ;' but is 'git'
> really needed?"
>
> I had "git l3" alias that invokes "$HOM#/bin/git-l" command, like so:
>
>     [alias]
>             l3 = "!sh -c ': git log ; git l \"$@\"' -"
>
> but if I did 's/: git log/: log/' it still completes just fine.

Interesting! I searched for the 'git <cmd>' and got some hits in "t9902-completion.sh" when running "git grep -nE 'git <cmd>'":

    t/t9902-completion.sh:2432:test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" '
    t/t9902-completion.sh:2441:test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' '
    t/t9902-completion.sh:2450:test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' '

When I did 's/: git log/: log/' in the test at line 2450, the test still passed. Perhaps we should add this "git"-less version as another test case?

Show 22 quoted lines
> I wonder if this hack is worth adding, instead of (or in addition
> to) requiring the user to insert $IFS to please the "parser", we can
> honor the rather obvious wish of the user in a more direct way.
>
>
>
>  contrib/completion/git-completion.bash | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git c/contrib/completion/git-completion.bash w/contrib/completion/git-completion.bash
> index 19139ac121..e31d71955f 100644
> --- c/contrib/completion/git-completion.bash
> +++ w/contrib/completion/git-completion.bash
> @@ -1183,7 +1183,7 @@ __git_aliased_command ()
>  			:)	: skip null command ;;
>  			\'*)	: skip opening quote after sh -c ;;
>  			*)
> -				cur="$word"
> +				cur="${word%;}"
>  				break
>  			esac
>  		done

I think this is a good defensive technique. This obviously changes the guidance that Phillipe gave in their patch (we no longer have to worry about adding a space or not between "word" and ";", so there's no need to mention this explicitly any more), but to me this seems like a better experience for our users because it's one less thing they have to worry about.

Previous: Junio C HamanoNext: Linus Arver
Message 7 of 12 in “completion: improve doc for complex aliases”
  1. completion: improve doc for complex aliasesPhilippe Blain via GitGitGadget, Sep 9, 2023
  2. Eric SunshineSep 10, 2023
  3. Linus ArverSep 12, 2023
  4. Philippe BlainSep 12, 2023
  5. completion: improve doc for complex aliasesPhilippe Blain via GitGitGadget, Sep 12, 2023
  6. Junio C HamanoSep 13, 2023
  7. Linus ArverSep 14, 2023
  8. Linus ArverSep 14, 2023
  9. completion: loosen and document the requirement around completing aliasJunio C Hamano, Sep 20, 2023
  10. Junio C HamanoSep 20, 2023
  11. Linus ArverSep 22, 2023
  12. Junio C HamanoSep 22, 2023

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.