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. Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Philippe Blain committed Sep 7, 2023 at 17:42 UTC c7153fad2d7e11b28d1cde21db040f8accae1900
1 file changed +9
contrib/completion/git-completion.bash
+9
@@ -1677,6 +1677,11 @@ _git_clone ()
1677
1678 __git_untracked_file_modes="all no normal"
1679
1680 +__git_trailer_tokens ()
1681 +{
1682 + git config --name-only --get-regexp trailer.\*.key | awk -F. '{print $2}'
1683 +}
1684 +
1685 _git_commit ()
1686 {
1687 case "$prev" in
@@ -1701,6 +1706,10 @@ _git_commit ()
1706 __gitcomp "$__git_untracked_file_modes" "" "${cur##--untracked-files=}"
1707 return
1708 ;;
1709 + --trailer=*)
1710 + __gitcomp_nl "$(__git_trailer_tokens)" "" "${cur##--trailer=}" ":"
1711 + return
1712 + ;;
1713 --*)
1714 __gitcomp_builtin commit
1715 return