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

Re: [PATCH] completion: commit: complete configured trailer tokens

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 7, 2023, 20:20 UTC
Message-ID
<xmqqpm2tka5v.fsf@gitster.g>
In-Reply-To
<pull.1583.git.1694108551683.gitgitgadget@gmail.com>
"Philippe Blain via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 11 quoted lines
> From: Philippe Blain <levraiphilippeblain@gmail.com>
>
> Since 2daae3d1d1 (commit: add --trailer option, 2021-03-23), 'git
> commit' can add trailers to commit messages. To make that feature more
> pleasant to use at the command line, update the Bash completion code to
> offer configured trailer tokens.
>
> Add a __git_trailer_tokens function to list the configured trailers
> tokens, and use it in _git_commit to suggest the configured tokens,
> suffixing the completion words with ':' so that the user only has to add
> the trailer value.
Nice attention to the details.

I do not use custom trailers myself, but I can see how this will be useful. The choice of the source of the information (i.e. the configuration variables trailer.*.key) sounds sensible, too.

Will queue.  Thanks.
Show 50 quoted lines
> Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>
> ---
>     completion: commit: complete configured trailer tokens
>     
>     Since 2daae3d1d1 (commit: add --trailer option, 2021-03-23), 'git
>     commit' can add trailers to commit messages. To make that feature more
>     pleasant to use at the command line, update the Bash completion code to
>     offer configured trailer tokens.
>     
>     Add a __git_trailer_tokens function to list the configured trailers
>     tokens, and use it in _git_commit to suggest the configured tokens,
>     suffixing the completion words with ':' so that the user only has to add
>     the trailer value.
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1583%2Fphil-blain%2Fcompletion-commit-trailers-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1583/phil-blain/completion-commit-trailers-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/1583
>
>  contrib/completion/git-completion.bash | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
> index 133ec92bfae..b5eb75aadc5 100644
> --- a/contrib/completion/git-completion.bash
> +++ b/contrib/completion/git-completion.bash
> @@ -1677,6 +1677,11 @@ _git_clone ()
>  
>  __git_untracked_file_modes="all no normal"
>  
> +__git_trailer_tokens ()
> +{
> +	git config --name-only --get-regexp trailer.\*.key | awk -F. '{print $2}'
> +}
> +
>  _git_commit ()
>  {
>  	case "$prev" in
> @@ -1701,6 +1706,10 @@ _git_commit ()
>  		__gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
>  		return
>  		;;
> +	--trailer=*)
> +		__gitcomp_nl "$(__git_trailer_tokens)" "" "${cur##--trailer=}" ":"
> +		return
> +		;;
>  	--*)
>  		__gitcomp_builtin commit
>  		return
>
> base-commit: 1fc548b2d6a3596f3e1c1f8b1930d8dbd1e30bf3
Previous: Philippe Blain via GitGitGadgetNext: Martin Ågren
Message 2 of 9 in “completion: commit: complete configured trailer tokens”
  1. completion: commit: complete configured trailer tokensPhilippe Blain via GitGitGadget, Sep 7, 2023
  2. Junio C HamanoSep 7, 2023
  3. Martin ÅgrenSep 11, 2023
  4. Philippe BlainSep 12, 2023
  5. 0/2 completion: commit: complete configured trailer tokensPhilippe Blain via GitGitGadget, Sep 12, 2023
  6. 1/2 completion: commit: complete configured trailer tokensPhilippe Blain via GitGitGadget, Sep 12, 2023
  7. 2/2 completion: commit: complete trailers tokens more robustlyPhilippe Blain via GitGitGadget, Sep 12, 2023
  8. Junio C HamanoSep 13, 2023
  9. ZheNing HuSep 16, 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.