{"thread":{"id":"66926","subject":"[PATCH] var: add GIT_COMMENT_STRING","startedAt":"2026-11-24T10:37:38Z","lastAt":"2026-11-24T20:24:21Z","messageCount":3,"participants":["Phillip Wood","Kristoffer Haugsbakk","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"559222","messageId":"fa8b80af26481e0dc96fd8f80f3c7ba84f60f9d4.1795516651.git.phillip.wood@dunelm.org.uk","threadId":"66926","inReplyTo":null,"subject":"[PATCH] var: add GIT_COMMENT_STRING","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2026-11-24T10:37:38Z","receivedAt":"2026-11-24T10:37:38Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"From: Phillip Wood <phillip.wood@dunelm.org.uk>\n\nSince commit 9ccf3e9b22 (config: add core.commentString, 2024-03-27) we\nhave two separate config keys that set the comment string used by git\nwhen creating template commit messages etc. As that commit notes, when\ncore.commentString is set to a multi-byte string, it can be useful to\nkeep core.commentChar set to a single chararcter for compatibilty with\nolder versions of git. That makes it awkward for scripts to determine\nwhat the comment chararcter is because they need to do something like\n\n    {\n        echo ' #'\n        git config --get-regex '^core.comment(char|string)$'\n    } | sed -n '$s/^[^ ] //p'\n\nAdd GIT_COMMENT_STRING to \"git var\" to make it easier for scripts to\ndetermine the comment character.\n\nSigned-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>\n---\nbase-commit: f7de81456940dd6f3274e461149bba12965de609\nPublished-As: https://github.com/phillipwood/git/releases/tag/pw%2Fvar-comment-string%2Fv1\nView-Changes-At: https://github.com/phillipwood/git/compare/f7de81456...fa8b80af2\nFetch-It-Via: git fetch https://github.com/phillipwood/git pw/var-comment-string/v1\n\n Documentation/git-var.adoc |  4 ++++\n builtin/var.c              |  9 +++++++++\n t/t0007-git-var.sh         | 10 ++++++++++\n 3 files changed, 23 insertions(+)\n\ndiff --git a/Documentation/git-var.adoc b/Documentation/git-var.adoc\nindex 5f240eb56e3..04aeccd7aa6 100644\n--- a/Documentation/git-var.adoc\n+++ b/Documentation/git-var.adoc\n@@ -130,6 +130,10 @@ endif::git-default-pager[]\n     The path to the global (per-user) configuration files, if any.\n     This variable can have multiple values.\n \n+`GIT_COMMENT_STRING`::\n+    The comment string used in template commit messages and rebase todo\n+    lists etc.\n+\n `GIT_HOSTNAME`::\n     The hostname of the machine, as reported by the operating system.\n     This is the hostname matched by `includeIf \"hostname:...\"` (see\ndiff --git a/builtin/var.c b/builtin/var.c\nindex eb85a985b15..6dc8ec4ba9f 100644\n--- a/builtin/var.c\n+++ b/builtin/var.c\n@@ -188,6 +188,11 @@ static char *hostname(int ident_flag UNUSED)\n \treturn xstrdup(buf);\n }\n \n+static char *comment_string(int ident_flag UNUSED)\n+{\n+\treturn xstrdup(comment_line_str);\n+}\n+\n struct git_var {\n \tconst char *name;\n \tchar *(*read)(int);\n@@ -262,6 +267,10 @@ static struct git_var git_vars[] = {\n \t\t.name = \"GIT_CONFIG_GLOBAL\",\n \t\t.multiread = git_config_val_global,\n \t},\n+\t{\n+\t\t.name = \"GIT_COMMENT_STRING\",\n+\t\t.read = comment_string,\n+\t},\n \t{\n \t\t.name = \"GIT_HOSTNAME\",\n \t\t.read = hostname,\ndiff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh\nindex 883a45399e2..f228cb5bb6f 100755\n--- a/t/t0007-git-var.sh\n+++ b/t/t0007-git-var.sh\n@@ -434,4 +434,14 @@ test_expect_success 'git var -l lists the identity components' '\n \ttest_grep \"^GIT_COMMITTER_DATE=\" actual\n '\n \n+test_expect_success 'GIT_COMMENT_STRING' '\n+\tgit var GIT_COMMENT_STRING >actual &&\n+\techo \"#\" >expect &&\n+\ttest_cmp expect actual &&\n+\tgit -c core.commentChar=: -c core.commentString=%% \\\n+\t\tvar GIT_COMMENT_STRING >actual &&\n+\techo %%>expect &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.56.1.576.g0cfbda1d5c7.dirty\n\n\n"},{"id":"559234","messageId":"b8c40805-90f2-414c-ae70-e2f79a19170e@app.fastmail.com","threadId":"66926","inReplyTo":"fa8b80af26481e0dc96fd8f80f3c7ba84f60f9d4.1795516651.git.phillip.wood@dunelm.org.uk","subject":"Re: [PATCH] var: add GIT_COMMENT_STRING","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-11-24T15:02:06Z","receivedAt":"2026-11-24T15:02:06Z","isPatch":true,"sender":{"key":"kristofferhaugsbakk@fastmail.com","avatar":null},"body":"On Tue, Nov 24, 2026, at 11:37, Phillip Wood wrote:\n> From: Phillip Wood <phillip.wood@dunelm.org.uk>\n>\n> Since commit 9ccf3e9b22 (config: add core.commentString, 2024-03-27) we\n> have two separate config keys that set the comment string used by git\n> when creating template commit messages etc. As that commit notes, when\n> core.commentString is set to a multi-byte string, it can be useful to\n> keep core.commentChar set to a single chararcter for compatibilty with\n> older versions of git. That makes it awkward for scripts to determine\n> what the comment chararcter is because they need to do something like\n>\n>     {\n>         echo ' #'\n>         git config --get-regex '^core.comment(char|string)$'\n>     } | sed -n '$s/^[^ ] //p'\n\nYeah that’s inconvenient.\n\n>\n> Add GIT_COMMENT_STRING to \"git var\" to make it easier for scripts to\n> determine the comment character.\n\ns/determine the comment character/determine the comment string/ ?\n\n>\n> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>\n> ---\n> base-commit: f7de81456940dd6f3274e461149bba12965de609\n> Published-As:\n> https://github.com/phillipwood/git/releases/tag/pw%2Fvar-comment-string%2Fv1\n> View-Changes-At:\n> https://github.com/phillipwood/git/compare/f7de81456...fa8b80af2\n> Fetch-It-Via: git fetch https://github.com/phillipwood/git\n> pw/var-comment-string/v1\n>\n>  Documentation/git-var.adoc |  4 ++++\n>  builtin/var.c              |  9 +++++++++\n>  t/t0007-git-var.sh         | 10 ++++++++++\n>  3 files changed, 23 insertions(+)\n>\n> diff --git a/Documentation/git-var.adoc b/Documentation/git-var.adoc\n> index 5f240eb56e3..04aeccd7aa6 100644\n> --- a/Documentation/git-var.adoc\n> +++ b/Documentation/git-var.adoc\n> @@ -130,6 +130,10 @@ endif::git-default-pager[]\n>      The path to the global (per-user) configuration files, if any.\n>      This variable can have multiple values.\n>\n> +`GIT_COMMENT_STRING`::\n> +    The comment string used in template commit messages and rebase todo\n> +    lists etc.\n\nThis could also mention the config variables and git-config(1)?\n\n> +\n>  `GIT_HOSTNAME`::\n>      The hostname of the machine, as reported by the operating system.\n>      This is the hostname matched by `includeIf \"hostname:...\"` (see\n> diff --git a/builtin/var.c b/builtin/var.c\n> index eb85a985b15..6dc8ec4ba9f 100644\n> --- a/builtin/var.c\n> +++ b/builtin/var.c\n> @@ -188,6 +188,11 @@ static char *hostname(int ident_flag UNUSED)\n>  \treturn xstrdup(buf);\n>  }\n>\n> +static char *comment_string(int ident_flag UNUSED)\n> +{\n> +\treturn xstrdup(comment_line_str);\n> +}\n> +\n>  struct git_var {\n>  \tconst char *name;\n>  \tchar *(*read)(int);\n> @@ -262,6 +267,10 @@ static struct git_var git_vars[] = {\n>  \t\t.name = \"GIT_CONFIG_GLOBAL\",\n>  \t\t.multiread = git_config_val_global,\n>  \t},\n> +\t{\n> +\t\t.name = \"GIT_COMMENT_STRING\",\n> +\t\t.read = comment_string,\n> +\t},\n>  \t{\n>  \t\t.name = \"GIT_HOSTNAME\",\n>  \t\t.read = hostname,\n> diff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh\n> index 883a45399e2..f228cb5bb6f 100755\n> --- a/t/t0007-git-var.sh\n> +++ b/t/t0007-git-var.sh\n> @@ -434,4 +434,14 @@ test_expect_success 'git var -l lists the identity\n> components' '\n>  \ttest_grep \"^GIT_COMMITTER_DATE=\" actual\n>  '\n>\n> +test_expect_success 'GIT_COMMENT_STRING' '\n> +\tgit var GIT_COMMENT_STRING >actual &&\n> +\techo \"#\" >expect &&\n> +\ttest_cmp expect actual &&\n\nThis tests the default.\n\n> +\tgit -c core.commentChar=: -c core.commentString=%% \\\n> +\t\tvar GIT_COMMENT_STRING >actual &&\n> +\techo %%>expect &&\n> +\ttest_cmp expect actual\n\nThen it tests that `commentString` overriding `*Char` works as it\nshould. That makes sense and seems to cover all testing bases.\n\nThis happens if you have an invalid comment string:\n\n    $ bin-wrappers/git -c core.commentString= var GIT_COMMENT_STRING\n    error: core.commentstring must have at least one character\n    fatal: unable to parse 'core.commentstring' from command-line config\n\nWith non-zero exit status.\n\n> +'\n> +\n>  test_done\n> --\n> 2.56.1.576.g0cfbda1d5c7.dirty\n\n"},{"id":"559265","messageId":"xmqqh5h6ou4q.fsf@gitster.g","threadId":"66926","inReplyTo":"fa8b80af26481e0dc96fd8f80f3c7ba84f60f9d4.1795516651.git.phillip.wood@dunelm.org.uk","subject":"Re: [PATCH] var: add GIT_COMMENT_STRING","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-24T20:24:21Z","receivedAt":"2026-11-24T20:24:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Phillip Wood <phillip.wood123@gmail.com> writes:\n\n> From: Phillip Wood <phillip.wood@dunelm.org.uk>\n>\n> Since commit 9ccf3e9b22 (config: add core.commentString, 2024-03-27) we\n> have two separate config keys that set the comment string used by git\n> when creating template commit messages etc. As that commit notes, when\n> core.commentString is set to a multi-byte string, it can be useful to\n> keep core.commentChar set to a single chararcter for compatibilty with\n> older versions of git. That makes it awkward for scripts to determine\n> what the comment chararcter is because they need to do something like\n>\n>     {\n>         echo ' #'\n>         git config --get-regex '^core.comment(char|string)$'\n>     } | sed -n '$s/^[^ ] //p'\n>\n> Add GIT_COMMENT_STRING to \"git var\" to make it easier for scripts to\n> determine the comment character.\n\nIt is somewhat unfortunate that we honor last-one-wins across two\nvariables (otherwise it would have been just the matter of using\ncore.commentString, falling back to core.commentChar).\n\nBut the motivation is good.\n\n"}]}