{"thread":{"id":"60204","subject":"[PATCH] completion: commit: complete configured trailer tokens","startedAt":"2023-09-07T17:43:06Z","lastAt":"2023-09-16T13:31:42Z","messageCount":9,"participants":["Philippe Blain via GitGitGadget","Junio C Hamano","Martin Ågren","Philippe Blain","ZheNing Hu"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"481490","messageId":"pull.1583.git.1694108551683.gitgitgadget@gmail.com","threadId":"60204","inReplyTo":null,"subject":"[PATCH] completion: commit: complete configured trailer tokens","fromName":"Philippe Blain via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2023-09-07T17:42:31Z","receivedAt":"2023-09-07T17:43:06Z","isPatch":true,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"From: Philippe Blain <levraiphilippeblain@gmail.com>\n\nSince 2daae3d1d1 (commit: add --trailer option, 2021-03-23), 'git\ncommit' can add trailers to commit messages. To make that feature more\npleasant to use at the command line, update the Bash completion code to\noffer configured trailer tokens.\n\nAdd a __git_trailer_tokens function to list the configured trailers\ntokens, and use it in _git_commit to suggest the configured tokens,\nsuffixing the completion words with ':' so that the user only has to add\nthe trailer value.\n\nSigned-off-by: Philippe Blain <levraiphilippeblain@gmail.com>\n---\n    completion: commit: complete configured trailer tokens\n    \n    Since 2daae3d1d1 (commit: add --trailer option, 2021-03-23), 'git\n    commit' can add trailers to commit messages. To make that feature more\n    pleasant to use at the command line, update the Bash completion code to\n    offer configured trailer tokens.\n    \n    Add a __git_trailer_tokens function to list the configured trailers\n    tokens, and use it in _git_commit to suggest the configured tokens,\n    suffixing the completion words with ':' so that the user only has to add\n    the trailer value.\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1583%2Fphil-blain%2Fcompletion-commit-trailers-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1583/phil-blain/completion-commit-trailers-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/1583\n\n contrib/completion/git-completion.bash | 9 +++++++++\n 1 file changed, 9 insertions(+)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 133ec92bfae..b5eb75aadc5 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1677,6 +1677,11 @@ _git_clone ()\n \n __git_untracked_file_modes=\"all no normal\"\n \n+__git_trailer_tokens ()\n+{\n+\tgit config --name-only --get-regexp trailer.\\*.key | awk -F. '{print $2}'\n+}\n+\n _git_commit ()\n {\n \tcase \"$prev\" in\n@@ -1701,6 +1706,10 @@ _git_commit ()\n \t\t__gitcomp \"$__git_untracked_file_modes\" \"\" \"${cur##--untracked-files=}\"\n \t\treturn\n \t\t;;\n+\t--trailer=*)\n+\t\t__gitcomp_nl \"$(__git_trailer_tokens)\" \"\" \"${cur##--trailer=}\" \":\"\n+\t\treturn\n+\t\t;;\n \t--*)\n \t\t__gitcomp_builtin commit\n \t\treturn\n\nbase-commit: 1fc548b2d6a3596f3e1c1f8b1930d8dbd1e30bf3\n-- \ngitgitgadget\n"},{"id":"481512","messageId":"xmqqpm2tka5v.fsf@gitster.g","threadId":"60204","inReplyTo":"pull.1583.git.1694108551683.gitgitgadget@gmail.com","subject":"Re: [PATCH] completion: commit: complete configured trailer tokens","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-09-07T20:20:28Z","receivedAt":"2023-09-07T20:20:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Philippe Blain via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Philippe Blain <levraiphilippeblain@gmail.com>\n>\n> Since 2daae3d1d1 (commit: add --trailer option, 2021-03-23), 'git\n> commit' can add trailers to commit messages. To make that feature more\n> pleasant to use at the command line, update the Bash completion code to\n> offer configured trailer tokens.\n>\n> Add a __git_trailer_tokens function to list the configured trailers\n> tokens, and use it in _git_commit to suggest the configured tokens,\n> suffixing the completion words with ':' so that the user only has to add\n> the trailer value.\n\nNice attention to the details.\n\nI do not use custom trailers myself, but I can see how this will be\nuseful.  The choice of the source of the information (i.e. the\nconfiguration variables trailer.*.key) sounds sensible, too.\n\nWill queue.  Thanks.\n\n> Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>\n> ---\n>     completion: commit: complete configured trailer tokens\n>     \n>     Since 2daae3d1d1 (commit: add --trailer option, 2021-03-23), 'git\n>     commit' can add trailers to commit messages. To make that feature more\n>     pleasant to use at the command line, update the Bash completion code to\n>     offer configured trailer tokens.\n>     \n>     Add a __git_trailer_tokens function to list the configured trailers\n>     tokens, and use it in _git_commit to suggest the configured tokens,\n>     suffixing the completion words with ':' so that the user only has to add\n>     the trailer value.\n>\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1583%2Fphil-blain%2Fcompletion-commit-trailers-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1583/phil-blain/completion-commit-trailers-v1\n> Pull-Request: https://github.com/gitgitgadget/git/pull/1583\n>\n>  contrib/completion/git-completion.bash | 9 +++++++++\n>  1 file changed, 9 insertions(+)\n>\n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 133ec92bfae..b5eb75aadc5 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -1677,6 +1677,11 @@ _git_clone ()\n>  \n>  __git_untracked_file_modes=\"all no normal\"\n>  \n> +__git_trailer_tokens ()\n> +{\n> +\tgit config --name-only --get-regexp trailer.\\*.key | awk -F. '{print $2}'\n> +}\n> +\n>  _git_commit ()\n>  {\n>  \tcase \"$prev\" in\n> @@ -1701,6 +1706,10 @@ _git_commit ()\n>  \t\t__gitcomp \"$__git_untracked_file_modes\" \"\" \"${cur##--untracked-files=}\"\n>  \t\treturn\n>  \t\t;;\n> +\t--trailer=*)\n> +\t\t__gitcomp_nl \"$(__git_trailer_tokens)\" \"\" \"${cur##--trailer=}\" \":\"\n> +\t\treturn\n> +\t\t;;\n>  \t--*)\n>  \t\t__gitcomp_builtin commit\n>  \t\treturn\n>\n> base-commit: 1fc548b2d6a3596f3e1c1f8b1930d8dbd1e30bf3\n"},{"id":"481697","messageId":"20230911102017.1927468-1-martin.agren@gmail.com","threadId":"60204","inReplyTo":"pull.1583.git.1694108551683.gitgitgadget@gmail.com","subject":"Re: [PATCH] completion: commit: complete configured trailer tokens","fromName":"Martin Ågren","fromEmail":"martin.agren@gmail.com","sentAt":"2023-09-11T10:20:15Z","receivedAt":"2023-09-11T21:39:18Z","isPatch":true,"sender":{"key":"martin.agren@gmail.com","avatar":null},"body":"Hi Philippe,\n\n> Add a __git_trailer_tokens function to list the configured trailers\n> tokens, and use it in _git_commit to suggest the configured tokens,\n> suffixing the completion words with ':' so that the user only has to add\n> the trailer value.\n\nMakes sense.\n\nI've never dabbled in the completion scripts, so take the following with\nsome salt.\n\n> +__git_trailer_tokens ()\n> +{\n> +\tgit config --name-only --get-regexp trailer.\\*.key | awk -F. '{print $2}'\n> +}\n\nThe rest of this script uses `__git config` rather than `git config`.\nThe purpose of `__git` seems to be to respect options given on the\ncommand line, so I think we would want to use it here.\n\nThese \".\" in \"trailer.\" and \".key\" will match any character. We also\ndon't anchor this at beginning and end. Maybe tighten this a bit and use\n'^trailer\\..*\\.key$' to behave better in the face of config such as\nthis:\n\n\t[strailer]\n\t\tskeying = \"s\"\n\t[trailerx]\n\t\tkeyx = \"x\"\n\nAnother thing. Consider such a config:\n\n\t[trailer \"q.p\"]\n\t\tkey = \"Q-p-by\"\n\nThe \"trailer.q.p.key\" config above ends up completing as just \"q\"\nbecause of how you use `print $2`. I see that `git commit --trailer=`\nitself is fairly relaxed here, so `--trailer=q` effectively ends up\npicking up \"q.p\" in the end. Tightening that is obviously out of scope\nhere and I have no opinion if the current behavior there is intended.\nBut maybe we should be a bit less relaxed here and complete to \"q.p\"? At\nany rate, it gets weird when you also have \"trailer.q.x.key\" in your\nconfig but we still just suggest the one \"q\".\n\nI see your patch is in next, but maybe some of this tightening might be\nworthwhile doing on top of it?\n\nMartin\n"},{"id":"481757","messageId":"50d4fa5c-8648-a51a-43a0-416d7f2e3df6@gmail.com","threadId":"60204","inReplyTo":"20230911102017.1927468-1-martin.agren@gmail.com","subject":"Re: [PATCH] completion: commit: complete configured trailer tokens","fromName":"Philippe Blain","fromEmail":"levraiphilippeblain@gmail.com","sentAt":"2023-09-12T12:02:29Z","receivedAt":"2023-09-12T12:02:52Z","isPatch":true,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"Hi Martin,\n\nLe 2023-09-11 à 06:20, Martin Ågren a écrit :\n> Hi Philippe,\n> \n>> Add a __git_trailer_tokens function to list the configured trailers\n>> tokens, and use it in _git_commit to suggest the configured tokens,\n>> suffixing the completion words with ':' so that the user only has to add\n>> the trailer value.\n> \n> Makes sense.\n> \n> I've never dabbled in the completion scripts, so take the following with\n> some salt.\n> \n>> +__git_trailer_tokens ()\n>> +{\n>> +\tgit config --name-only --get-regexp trailer.\\*.key | awk -F. '{print $2}'\n>> +}\n> \n> The rest of this script uses `__git config` rather than `git config`.\n> The purpose of `__git` seems to be to respect options given on the\n> command line, so I think we would want to use it here.\n> \n> These \".\" in \"trailer.\" and \".key\" will match any character. We also\n> don't anchor this at beginning and end. Maybe tighten this a bit and use\n> '^trailer\\..*\\.key$' to behave better in the face of config such as\n> this:\n> \n> \t[strailer]\n> \t\tskeying = \"s\"\n> \t[trailerx]\n> \t\tkeyx = \"x\"\n> \n> Another thing. Consider such a config:\n> \n> \t[trailer \"q.p\"]\n> \t\tkey = \"Q-p-by\"\n> \n> The \"trailer.q.p.key\" config above ends up completing as just \"q\"\n> because of how you use `print $2`. I see that `git commit --trailer=`\n> itself is fairly relaxed here, so `--trailer=q` effectively ends up\n> picking up \"q.p\" in the end. Tightening that is obviously out of scope\n> here and I have no opinion if the current behavior there is intended.\n> But maybe we should be a bit less relaxed here and complete to \"q.p\"? At\n> any rate, it gets weird when you also have \"trailer.q.x.key\" in your\n> config but we still just suggest the one \"q\".\n> \n> I see your patch is in next, but maybe some of this tightening might be\n> worthwhile doing on top of it?\n> \n> Martin\n> \n\nThese are all good suggestions. I'll send a new version with these fixes \non top.\n\nThanks,\n\nPhilippe.\n"},{"id":"481778","messageId":"a31d7a29af91284f6b8720c810a88076edf5cdd1.1694539827.git.gitgitgadget@gmail.com","threadId":"60204","inReplyTo":"pull.1583.v2.git.1694539827.gitgitgadget@gmail.com","subject":"[PATCH v2 1/2] completion: commit: complete configured trailer tokens","fromName":"Philippe Blain via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2023-09-12T17:30:26Z","receivedAt":"2023-09-12T17:30:34Z","isPatch":true,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"From: Philippe Blain <levraiphilippeblain@gmail.com>\n\nSince 2daae3d1d1 (commit: add --trailer option, 2021-03-23), 'git\ncommit' can add trailers to commit messages. To make that feature more\npleasant to use at the command line, update the Bash completion code to\noffer configured trailer tokens.\n\nAdd a __git_trailer_tokens function to list the configured trailers\ntokens, and use it in _git_commit to suggest the configured tokens,\nsuffixing the completion words with ':' so that the user only has to add\nthe trailer value.\n\nSigned-off-by: Philippe Blain <levraiphilippeblain@gmail.com>\n---\n contrib/completion/git-completion.bash | 9 +++++++++\n 1 file changed, 9 insertions(+)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex 133ec92bfae..b5eb75aadc5 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1677,6 +1677,11 @@ _git_clone ()\n \n __git_untracked_file_modes=\"all no normal\"\n \n+__git_trailer_tokens ()\n+{\n+\tgit config --name-only --get-regexp trailer.\\*.key | awk -F. '{print $2}'\n+}\n+\n _git_commit ()\n {\n \tcase \"$prev\" in\n@@ -1701,6 +1706,10 @@ _git_commit ()\n \t\t__gitcomp \"$__git_untracked_file_modes\" \"\" \"${cur##--untracked-files=}\"\n \t\treturn\n \t\t;;\n+\t--trailer=*)\n+\t\t__gitcomp_nl \"$(__git_trailer_tokens)\" \"\" \"${cur##--trailer=}\" \":\"\n+\t\treturn\n+\t\t;;\n \t--*)\n \t\t__gitcomp_builtin commit\n \t\treturn\n-- \ngitgitgadget\n\n"},{"id":"481779","messageId":"pull.1583.v2.git.1694539827.gitgitgadget@gmail.com","threadId":"60204","inReplyTo":"pull.1583.git.1694108551683.gitgitgadget@gmail.com","subject":"[PATCH v2 0/2] completion: commit: complete configured trailer tokens","fromName":"Philippe Blain via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2023-09-12T17:30:25Z","receivedAt":"2023-09-12T17:30:35Z","isPatch":true,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"v2: This series adds support for completing configured trailer tokens in\n'git commit --trailer'.\n\nChanges since v1:\n\n * added all Martin's suggestions as an additional commit on top since\n   pb/complete-commit-trailer is already in next.\n\nPhilippe Blain (2):\n  completion: commit: complete configured trailer tokens\n  completion: commit: complete trailers tokens more robustly\n\n contrib/completion/git-completion.bash | 9 +++++++++\n 1 file changed, 9 insertions(+)\n\n\nbase-commit: 1fc548b2d6a3596f3e1c1f8b1930d8dbd1e30bf3\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1583%2Fphil-blain%2Fcompletion-commit-trailers-v2\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1583/phil-blain/completion-commit-trailers-v2\nPull-Request: https://github.com/gitgitgadget/git/pull/1583\n\nRange-diff vs v1:\n\n 1:  a31d7a29af9 = 1:  a31d7a29af9 completion: commit: complete configured trailer tokens\n -:  ----------- > 2:  9cb33c20294 completion: commit: complete trailers tokens more robustly\n\n-- \ngitgitgadget\n"},{"id":"481780","messageId":"9cb33c20294e096f5345fb1ea9d80a23e899ae6f.1694539827.git.gitgitgadget@gmail.com","threadId":"60204","inReplyTo":"pull.1583.v2.git.1694539827.gitgitgadget@gmail.com","subject":"[PATCH v2 2/2] completion: commit: complete trailers tokens more robustly","fromName":"Philippe Blain via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2023-09-12T17:30:27Z","receivedAt":"2023-09-12T17:30:37Z","isPatch":true,"sender":{"key":"levraiphilippeblain@gmail.com","avatar":"https://avatars.githubusercontent.com/u/44212482?v=4"},"body":"From: Philippe Blain <levraiphilippeblain@gmail.com>\n\nIn the previous commit, we added support for completing configured\ntrailer tokens in 'git commit --trailer'.\n\nMake the implementation more robust by:\n\n- using '__git' instead of plain 'git', as the rest of the completion\n  script does\n- using a stricter pattern for --get-regexp to avoid false hits\n- using 'cut' and 'rev' instead of 'awk' to account for tokens including\n  dots.\n\nSigned-off-by: Philippe Blain <levraiphilippeblain@gmail.com>\n---\n contrib/completion/git-completion.bash | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\nindex b5eb75aadc5..c23465886e0 100644\n--- a/contrib/completion/git-completion.bash\n+++ b/contrib/completion/git-completion.bash\n@@ -1679,7 +1679,7 @@ __git_untracked_file_modes=\"all no normal\"\n \n __git_trailer_tokens ()\n {\n-\tgit config --name-only --get-regexp trailer.\\*.key | awk -F. '{print $2}'\n+\t__git config --name-only --get-regexp '^trailer\\..*\\.key$' | cut -d. -f 2- | rev | cut -d. -f2- | rev\n }\n \n _git_commit ()\n-- \ngitgitgadget\n"},{"id":"481798","messageId":"xmqqsf7ikj1s.fsf@gitster.g","threadId":"60204","inReplyTo":"9cb33c20294e096f5345fb1ea9d80a23e899ae6f.1694539827.git.gitgitgadget@gmail.com","subject":"Re: [PATCH v2 2/2] completion: commit: complete trailers tokens more robustly","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-09-13T00:34:23Z","receivedAt":"2023-09-13T00:34:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Philippe Blain via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n> From: Philippe Blain <levraiphilippeblain@gmail.com>\n>\n> In the previous commit, we added support for completing configured\n> trailer tokens in 'git commit --trailer'.\n>\n> Make the implementation more robust by:\n>\n> - using '__git' instead of plain 'git', as the rest of the completion\n>   script does\n> - using a stricter pattern for --get-regexp to avoid false hits\n> - using 'cut' and 'rev' instead of 'awk' to account for tokens including\n>   dots.\n>\n> Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>\n> ---\n\nThanks, both, for a quick fix.\n\nQueued.\n"},{"id":"481927","messageId":"CAOLTT8SxSXgHxQiT4LYy2kKBpwwRPvJguukKS36GOm73JbtzRQ@mail.gmail.com","threadId":"60204","inReplyTo":"pull.1583.git.1694108551683.gitgitgadget@gmail.com","subject":"Re: [PATCH] completion: commit: complete configured trailer tokens","fromName":"ZheNing Hu","fromEmail":"adlternative@gmail.com","sentAt":"2023-09-16T13:30:52Z","receivedAt":"2023-09-16T13:31:42Z","isPatch":true,"sender":{"key":"adlternative@gmail.com","avatar":"https://avatars.githubusercontent.com/u/58138461?v=4"},"body":"Thank you for the improvement, I believe this interactive mode with tab\ncompletion will be very useful.\n\nPhilippe Blain via GitGitGadget <gitgitgadget@gmail.com> 于2023年9月8日周五 01:42写道：\n>\n> From: Philippe Blain <levraiphilippeblain@gmail.com>\n>\n> Since 2daae3d1d1 (commit: add --trailer option, 2021-03-23), 'git\n> commit' can add trailers to commit messages. To make that feature more\n> pleasant to use at the command line, update the Bash completion code to\n> offer configured trailer tokens.\n>\n> Add a __git_trailer_tokens function to list the configured trailers\n> tokens, and use it in _git_commit to suggest the configured tokens,\n> suffixing the completion words with ':' so that the user only has to add\n> the trailer value.\n>\n> Signed-off-by: Philippe Blain <levraiphilippeblain@gmail.com>\n> ---\n>     completion: commit: complete configured trailer tokens\n>\n>     Since 2daae3d1d1 (commit: add --trailer option, 2021-03-23), 'git\n>     commit' can add trailers to commit messages. To make that feature more\n>     pleasant to use at the command line, update the Bash completion code to\n>     offer configured trailer tokens.\n>\n>     Add a __git_trailer_tokens function to list the configured trailers\n>     tokens, and use it in _git_commit to suggest the configured tokens,\n>     suffixing the completion words with ':' so that the user only has to add\n>     the trailer value.\n>\n> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1583%2Fphil-blain%2Fcompletion-commit-trailers-v1\n> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1583/phil-blain/completion-commit-trailers-v1\n> Pull-Request: https://github.com/gitgitgadget/git/pull/1583\n>\n>  contrib/completion/git-completion.bash | 9 +++++++++\n>  1 file changed, 9 insertions(+)\n>\n> diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash\n> index 133ec92bfae..b5eb75aadc5 100644\n> --- a/contrib/completion/git-completion.bash\n> +++ b/contrib/completion/git-completion.bash\n> @@ -1677,6 +1677,11 @@ _git_clone ()\n>\n>  __git_untracked_file_modes=\"all no normal\"\n>\n> +__git_trailer_tokens ()\n> +{\n> +       git config --name-only --get-regexp trailer.\\*.key | awk -F. '{print $2}'\n> +}\n> +\n>  _git_commit ()\n>  {\n>         case \"$prev\" in\n> @@ -1701,6 +1706,10 @@ _git_commit ()\n>                 __gitcomp \"$__git_untracked_file_modes\" \"\" \"${cur##--untracked-files=}\"\n>                 return\n>                 ;;\n> +       --trailer=*)\n> +               __gitcomp_nl \"$(__git_trailer_tokens)\" \"\" \"${cur##--trailer=}\" \":\"\n> +               return\n> +               ;;\n>         --*)\n>                 __gitcomp_builtin commit\n>                 return\n>\n> base-commit: 1fc548b2d6a3596f3e1c1f8b1930d8dbd1e30bf3\n> --\n> gitgitgadget\n"}]}