Git development
 help / color / mirror / Atom feed
* [PATCH] var: add GIT_COMMENT_STRING
@ 2026-11-24 10:37 Phillip Wood
  2026-11-24 15:02 ` Kristoffer Haugsbakk
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Phillip Wood @ 2026-11-24 10:37 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Phillip Wood

From: Phillip Wood <phillip.wood@dunelm.org.uk>

Since commit 9ccf3e9b22 (config: add core.commentString, 2024-03-27) we
have two separate config keys that set the comment string used by git
when creating template commit messages etc. As that commit notes, when
core.commentString is set to a multi-byte string, it can be useful to
keep core.commentChar set to a single chararcter for compatibilty with
older versions of git. That makes it awkward for scripts to determine
what the comment chararcter is because they need to do something like

    {
        echo ' #'
        git config --get-regex '^core.comment(char|string)$'
    } | sed -n '$s/^[^ ] //p'

Add GIT_COMMENT_STRING to "git var" to make it easier for scripts to
determine the comment character.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
base-commit: f7de81456940dd6f3274e461149bba12965de609
Published-As: https://github.com/phillipwood/git/releases/tag/pw%2Fvar-comment-string%2Fv1
View-Changes-At: https://github.com/phillipwood/git/compare/f7de81456...fa8b80af2
Fetch-It-Via: git fetch https://github.com/phillipwood/git pw/var-comment-string/v1

 Documentation/git-var.adoc |  4 ++++
 builtin/var.c              |  9 +++++++++
 t/t0007-git-var.sh         | 10 ++++++++++
 3 files changed, 23 insertions(+)

diff --git a/Documentation/git-var.adoc b/Documentation/git-var.adoc
index 5f240eb56e3..04aeccd7aa6 100644
--- a/Documentation/git-var.adoc
+++ b/Documentation/git-var.adoc
@@ -130,6 +130,10 @@ endif::git-default-pager[]
     The path to the global (per-user) configuration files, if any.
     This variable can have multiple values.
 
+`GIT_COMMENT_STRING`::
+    The comment string used in template commit messages and rebase todo
+    lists etc.
+
 `GIT_HOSTNAME`::
     The hostname of the machine, as reported by the operating system.
     This is the hostname matched by `includeIf "hostname:..."` (see
diff --git a/builtin/var.c b/builtin/var.c
index eb85a985b15..6dc8ec4ba9f 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -188,6 +188,11 @@ static char *hostname(int ident_flag UNUSED)
 	return xstrdup(buf);
 }
 
+static char *comment_string(int ident_flag UNUSED)
+{
+	return xstrdup(comment_line_str);
+}
+
 struct git_var {
 	const char *name;
 	char *(*read)(int);
@@ -262,6 +267,10 @@ static struct git_var git_vars[] = {
 		.name = "GIT_CONFIG_GLOBAL",
 		.multiread = git_config_val_global,
 	},
+	{
+		.name = "GIT_COMMENT_STRING",
+		.read = comment_string,
+	},
 	{
 		.name = "GIT_HOSTNAME",
 		.read = hostname,
diff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh
index 883a45399e2..f228cb5bb6f 100755
--- a/t/t0007-git-var.sh
+++ b/t/t0007-git-var.sh
@@ -434,4 +434,14 @@ test_expect_success 'git var -l lists the identity components' '
 	test_grep "^GIT_COMMITTER_DATE=" actual
 '
 
+test_expect_success 'GIT_COMMENT_STRING' '
+	git var GIT_COMMENT_STRING >actual &&
+	echo "#" >expect &&
+	test_cmp expect actual &&
+	git -c core.commentChar=: -c core.commentString=%% \
+		var GIT_COMMENT_STRING >actual &&
+	echo %%>expect &&
+	test_cmp expect actual
+'
+
 test_done
-- 
2.56.1.576.g0cfbda1d5c7.dirty


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] var: add GIT_COMMENT_STRING
  2026-11-24 10:37 [PATCH] var: add GIT_COMMENT_STRING Phillip Wood
@ 2026-11-24 15:02 ` Kristoffer Haugsbakk
  2026-11-25 16:19   ` Phillip Wood
  2026-11-24 20:24 ` Junio C Hamano
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 12+ messages in thread
From: Kristoffer Haugsbakk @ 2026-11-24 15:02 UTC (permalink / raw)
  To: Phillip Wood, git; +Cc: Jeff King, Phillip Wood

On Tue, Nov 24, 2026, at 11:37, Phillip Wood wrote:
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> Since commit 9ccf3e9b22 (config: add core.commentString, 2024-03-27) we
> have two separate config keys that set the comment string used by git
> when creating template commit messages etc. As that commit notes, when
> core.commentString is set to a multi-byte string, it can be useful to
> keep core.commentChar set to a single chararcter for compatibilty with
> older versions of git. That makes it awkward for scripts to determine
> what the comment chararcter is because they need to do something like
>
>     {
>         echo ' #'
>         git config --get-regex '^core.comment(char|string)$'
>     } | sed -n '$s/^[^ ] //p'

Yeah that’s inconvenient.

>
> Add GIT_COMMENT_STRING to "git var" to make it easier for scripts to
> determine the comment character.

s/determine the comment character/determine the comment string/ ?

>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
> base-commit: f7de81456940dd6f3274e461149bba12965de609
> Published-As:
> https://github.com/phillipwood/git/releases/tag/pw%2Fvar-comment-string%2Fv1
> View-Changes-At:
> https://github.com/phillipwood/git/compare/f7de81456...fa8b80af2
> Fetch-It-Via: git fetch https://github.com/phillipwood/git
> pw/var-comment-string/v1
>
>  Documentation/git-var.adoc |  4 ++++
>  builtin/var.c              |  9 +++++++++
>  t/t0007-git-var.sh         | 10 ++++++++++
>  3 files changed, 23 insertions(+)
>
> diff --git a/Documentation/git-var.adoc b/Documentation/git-var.adoc
> index 5f240eb56e3..04aeccd7aa6 100644
> --- a/Documentation/git-var.adoc
> +++ b/Documentation/git-var.adoc
> @@ -130,6 +130,10 @@ endif::git-default-pager[]
>      The path to the global (per-user) configuration files, if any.
>      This variable can have multiple values.
>
> +`GIT_COMMENT_STRING`::
> +    The comment string used in template commit messages and rebase todo
> +    lists etc.

This could also mention the config variables and git-config(1)?

> +
>  `GIT_HOSTNAME`::
>      The hostname of the machine, as reported by the operating system.
>      This is the hostname matched by `includeIf "hostname:..."` (see
> diff --git a/builtin/var.c b/builtin/var.c
> index eb85a985b15..6dc8ec4ba9f 100644
> --- a/builtin/var.c
> +++ b/builtin/var.c
> @@ -188,6 +188,11 @@ static char *hostname(int ident_flag UNUSED)
>  	return xstrdup(buf);
>  }
>
> +static char *comment_string(int ident_flag UNUSED)
> +{
> +	return xstrdup(comment_line_str);
> +}
> +
>  struct git_var {
>  	const char *name;
>  	char *(*read)(int);
> @@ -262,6 +267,10 @@ static struct git_var git_vars[] = {
>  		.name = "GIT_CONFIG_GLOBAL",
>  		.multiread = git_config_val_global,
>  	},
> +	{
> +		.name = "GIT_COMMENT_STRING",
> +		.read = comment_string,
> +	},
>  	{
>  		.name = "GIT_HOSTNAME",
>  		.read = hostname,
> diff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh
> index 883a45399e2..f228cb5bb6f 100755
> --- a/t/t0007-git-var.sh
> +++ b/t/t0007-git-var.sh
> @@ -434,4 +434,14 @@ test_expect_success 'git var -l lists the identity
> components' '
>  	test_grep "^GIT_COMMITTER_DATE=" actual
>  '
>
> +test_expect_success 'GIT_COMMENT_STRING' '
> +	git var GIT_COMMENT_STRING >actual &&
> +	echo "#" >expect &&
> +	test_cmp expect actual &&

This tests the default.

> +	git -c core.commentChar=: -c core.commentString=%% \
> +		var GIT_COMMENT_STRING >actual &&
> +	echo %%>expect &&
> +	test_cmp expect actual

Then it tests that `commentString` overriding `*Char` works as it
should. That makes sense and seems to cover all testing bases.

This happens if you have an invalid comment string:

    $ bin-wrappers/git -c core.commentString= var GIT_COMMENT_STRING
    error: core.commentstring must have at least one character
    fatal: unable to parse 'core.commentstring' from command-line config

With non-zero exit status.

> +'
> +
>  test_done
> --
> 2.56.1.576.g0cfbda1d5c7.dirty

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] var: add GIT_COMMENT_STRING
  2026-11-24 10:37 [PATCH] var: add GIT_COMMENT_STRING Phillip Wood
  2026-11-24 15:02 ` Kristoffer Haugsbakk
@ 2026-11-24 20:24 ` Junio C Hamano
  2026-11-26 16:25 ` [PATCH v2] " Phillip Wood
  2026-11-29 16:18 ` [PATCH v3] " Phillip Wood
  3 siblings, 0 replies; 12+ messages in thread
From: Junio C Hamano @ 2026-11-24 20:24 UTC (permalink / raw)
  To: Phillip Wood; +Cc: git, Jeff King

Phillip Wood <phillip.wood123@gmail.com> writes:

> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> Since commit 9ccf3e9b22 (config: add core.commentString, 2024-03-27) we
> have two separate config keys that set the comment string used by git
> when creating template commit messages etc. As that commit notes, when
> core.commentString is set to a multi-byte string, it can be useful to
> keep core.commentChar set to a single chararcter for compatibilty with
> older versions of git. That makes it awkward for scripts to determine
> what the comment chararcter is because they need to do something like
>
>     {
>         echo ' #'
>         git config --get-regex '^core.comment(char|string)$'
>     } | sed -n '$s/^[^ ] //p'
>
> Add GIT_COMMENT_STRING to "git var" to make it easier for scripts to
> determine the comment character.

It is somewhat unfortunate that we honor last-one-wins across two
variables (otherwise it would have been just the matter of using
core.commentString, falling back to core.commentChar).

But the motivation is good.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] var: add GIT_COMMENT_STRING
  2026-11-24 15:02 ` Kristoffer Haugsbakk
@ 2026-11-25 16:19   ` Phillip Wood
  2026-11-25 20:09     ` Kristoffer Haugsbakk
  0 siblings, 1 reply; 12+ messages in thread
From: Phillip Wood @ 2026-11-25 16:19 UTC (permalink / raw)
  To: Kristoffer Haugsbakk, Phillip Wood, git; +Cc: Jeff King

On 24/11/2026 15:02, Kristoffer Haugsbakk wrote:
> On Tue, Nov 24, 2026, at 11:37, Phillip Wood wrote:
>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>
>> Add GIT_COMMENT_STRING to "git var" to make it easier for scripts to
>> determine the comment character.
> 
> s/determine the comment character/determine the comment string/ ?

Yes, that would be more consistent

>> diff --git a/Documentation/git-var.adoc b/Documentation/git-var.adoc
>> index 5f240eb56e3..04aeccd7aa6 100644
>> --- a/Documentation/git-var.adoc
>> +++ b/Documentation/git-var.adoc
>> @@ -130,6 +130,10 @@ endif::git-default-pager[]
>>       The path to the global (per-user) configuration files, if any.
>>       This variable can have multiple values.
>>
>> +`GIT_COMMENT_STRING`::
>> +    The comment string used in template commit messages and rebase todo
>> +    lists etc.
> 
> This could also mention the config variables and git-config(1)?

I had decided not do to that as the point of GIT_COMMENT_STRING is to be 
able to query the comment string without the user having to worry about 
the intricacies of the config setting or what the default value is. I 
guess saying "see `core.commentString` and `core.commentChar`in 
git-config(1)" doesn't really do any harm but I don't think users are 
going to get much additional useful information by reading the config 
documentation. Perhaps saying "as set by `core.commentString`" would be 
more better as it does not promise the reader that the config 
documentation contains additional, useful, information?

The documentation for GIT_PAGER, GIT_EDITOR and GIT_SEQUENCE_EDITOR 
mention the relevant config settings when describing how we determine 
which program to use, but the documentation for things like 
GIT_DEFAULT_BRANCH does do not.

I have added a note to the documentation for `core.commentString` that 
the comment string can be queried with `git var GIT_COMMENT_STRING`

Thanks

Phillip

> 
>> +
>>   `GIT_HOSTNAME`::
>>       The hostname of the machine, as reported by the operating system.
>>       This is the hostname matched by `includeIf "hostname:..."` (see
>> diff --git a/builtin/var.c b/builtin/var.c
>> index eb85a985b15..6dc8ec4ba9f 100644
>> --- a/builtin/var.c
>> +++ b/builtin/var.c
>> @@ -188,6 +188,11 @@ static char *hostname(int ident_flag UNUSED)
>>   	return xstrdup(buf);
>>   }
>>
>> +static char *comment_string(int ident_flag UNUSED)
>> +{
>> +	return xstrdup(comment_line_str);
>> +}
>> +
>>   struct git_var {
>>   	const char *name;
>>   	char *(*read)(int);
>> @@ -262,6 +267,10 @@ static struct git_var git_vars[] = {
>>   		.name = "GIT_CONFIG_GLOBAL",
>>   		.multiread = git_config_val_global,
>>   	},
>> +	{
>> +		.name = "GIT_COMMENT_STRING",
>> +		.read = comment_string,
>> +	},
>>   	{
>>   		.name = "GIT_HOSTNAME",
>>   		.read = hostname,
>> diff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh
>> index 883a45399e2..f228cb5bb6f 100755
>> --- a/t/t0007-git-var.sh
>> +++ b/t/t0007-git-var.sh
>> @@ -434,4 +434,14 @@ test_expect_success 'git var -l lists the identity
>> components' '
>>   	test_grep "^GIT_COMMITTER_DATE=" actual
>>   '
>>
>> +test_expect_success 'GIT_COMMENT_STRING' '
>> +	git var GIT_COMMENT_STRING >actual &&
>> +	echo "#" >expect &&
>> +	test_cmp expect actual &&
> 
> This tests the default.
> 
>> +	git -c core.commentChar=: -c core.commentString=%% \
>> +		var GIT_COMMENT_STRING >actual &&
>> +	echo %%>expect &&
>> +	test_cmp expect actual
> 
> Then it tests that `commentString` overriding `*Char` works as it
> should. That makes sense and seems to cover all testing bases.
> 
> This happens if you have an invalid comment string:
> 
>      $ bin-wrappers/git -c core.commentString= var GIT_COMMENT_STRING
>      error: core.commentstring must have at least one character
>      fatal: unable to parse 'core.commentstring' from command-line config
> 
> With non-zero exit status.
> 
>> +'
>> +
>>   test_done
>> --
>> 2.56.1.576.g0cfbda1d5c7.dirty
> 


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] var: add GIT_COMMENT_STRING
  2026-11-25 16:19   ` Phillip Wood
@ 2026-11-25 20:09     ` Kristoffer Haugsbakk
  2026-11-26 16:29       ` Phillip Wood
  0 siblings, 1 reply; 12+ messages in thread
From: Kristoffer Haugsbakk @ 2026-11-25 20:09 UTC (permalink / raw)
  To: Phillip Wood, git; +Cc: Jeff King

On Wed, Nov 25, 2026, at 17:19, Phillip Wood wrote:
> On 24/11/2026 15:02, Kristoffer Haugsbakk wrote:
>> On Tue, Nov 24, 2026, at 11:37, Phillip Wood wrote:
>[snip]
>
>>> diff --git a/Documentation/git-var.adoc b/Documentation/git-var.adoc
>>> index 5f240eb56e3..04aeccd7aa6 100644
>>> --- a/Documentation/git-var.adoc
>>> +++ b/Documentation/git-var.adoc
>>> @@ -130,6 +130,10 @@ endif::git-default-pager[]
>>>       The path to the global (per-user) configuration files, if any.
>>>       This variable can have multiple values.
>>>
>>> +`GIT_COMMENT_STRING`::
>>> +    The comment string used in template commit messages and rebase todo
>>> +    lists etc.
>>
>> This could also mention the config variables and git-config(1)?
>
> I had decided not do to that as the point of GIT_COMMENT_STRING is to be
> able to query the comment string without the user having to worry about
> the intricacies of the config setting or what the default value is.

I don’t agree about it being an intricacy. The concrete name links them
with no doubt even if they would have diverging description for example:

• String that marks lines to be discarded on save
• Marks the beginning of a comment. A comment is not part of the saved
  commit.

Granted that is completely invented...

> I guess saying "see `core.commentString` and `core.commentChar`in
> git-config(1)" doesn't really do any harm but I don't think users are
> going to get much additional useful information by reading the config
> documentation.

Yeah that is correct. The link isn’t worth the space.

> Perhaps saying "as set by `core.commentString`" would be
> more better as it does not promise the reader that the config
> documentation contains additional, useful, information?

Yeah, this sounds like the sweet spot.

>
> The documentation for GIT_PAGER, GIT_EDITOR and GIT_SEQUENCE_EDITOR
> mention the relevant config settings when describing how we determine
> which program to use, but the documentation for things like
> GIT_DEFAULT_BRANCH does do not.

After reading just a little, I much prefer the verbosity of `GIT_EDITOR`
compared to the terseness of `GIT_DEFAULT_BRANCH`.

>
> I have added a note to the documentation for `core.commentString` that
> the comment string can be queried with `git var GIT_COMMENT_STRING`

Sounds good.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v2] var: add GIT_COMMENT_STRING
  2026-11-24 10:37 [PATCH] var: add GIT_COMMENT_STRING Phillip Wood
  2026-11-24 15:02 ` Kristoffer Haugsbakk
  2026-11-24 20:24 ` Junio C Hamano
@ 2026-11-26 16:25 ` Phillip Wood
  2026-11-26 20:56   ` Junio C Hamano
  2026-11-26 21:14   ` Kristoffer Haugsbakk
  2026-11-29 16:18 ` [PATCH v3] " Phillip Wood
  3 siblings, 2 replies; 12+ messages in thread
From: Phillip Wood @ 2026-11-26 16:25 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Kristoffer Haugsbakk, Phillip Wood

From: Phillip Wood <phillip.wood@dunelm.org.uk>

Since commit 9ccf3e9b22 (config: add core.commentString, 2024-03-27)
we have two separate config keys that set the comment string used by git
when creating template commit messages etc. As that commit notes, when
core.commentString is set to a multi-byte string, it can be useful to
keep core.commentChar set to a single character for compatibility with
older versions of git. That makes it awkward for scripts to determine
what the comment string is because they need to do something like

    {
        echo ' #'
        git config --get-regex '^core.comment(char|string)$'
    } | sed -n '$s/^[^ ] //p'

Add GIT_COMMENT_STRING to "git var" to make it easier for scripts to
determine the comment string.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
Changes since V1:
 - Fixed typos in commit message
 - Added a reference to `git var GIT_COMMENT_STRING` to the
   documentation for core.commentString
 - Added a reference to the relevant config keys to the documentation
   for GIT_COMMENT_STRING

base-commit: f7de81456940dd6f3274e461149bba12965de609
Published-As: https://github.com/phillipwood/git/releases/tag/pw%2Fvar-comment-string%2Fv2
View-Changes-At: https://github.com/phillipwood/git/compare/f7de81456...6e310e0af
Fetch-It-Via: git fetch https://github.com/phillipwood/git pw/var-comment-string/v2

 Documentation/config/core.adoc |  3 ++-
 Documentation/git-var.adoc     |  4 ++++
 builtin/var.c                  |  9 +++++++++
 t/t0007-git-var.sh             | 10 ++++++++++
 4 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/Documentation/config/core.adoc b/Documentation/config/core.adoc
index bdc74d291cc..e348d8895d1 100644
--- a/Documentation/config/core.adoc
+++ b/Documentation/config/core.adoc
@@ -549,7 +549,8 @@ core.commentString::
 	Commands such as `commit` and `tag` that let you edit
 	messages consider a line that begins with this character
 	commented, and removes them after the editor returns
-	(default '#').
+	(default '#'). Scripts can query the comment string with
+	"`git var GIT_COMMENT_STRING`".
 +
 ifndef::with-breaking-changes[]
 If set to "auto", `git-commit` will select a character that is not
diff --git a/Documentation/git-var.adoc b/Documentation/git-var.adoc
index 5f240eb56e3..9c3778b2535 100644
--- a/Documentation/git-var.adoc
+++ b/Documentation/git-var.adoc
@@ -130,6 +130,10 @@ endif::git-default-pager[]
     The path to the global (per-user) configuration files, if any.
     This variable can have multiple values.
 
+`GIT_COMMENT_STRING`::
+    The comment string used in template commit messages and rebase todo
+    lists etc. as set by `core.commentString` or `core.commentChar`.
+
 `GIT_HOSTNAME`::
     The hostname of the machine, as reported by the operating system.
     This is the hostname matched by `includeIf "hostname:..."` (see
diff --git a/builtin/var.c b/builtin/var.c
index eb85a985b15..6dc8ec4ba9f 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -188,6 +188,11 @@ static char *hostname(int ident_flag UNUSED)
 	return xstrdup(buf);
 }
 
+static char *comment_string(int ident_flag UNUSED)
+{
+	return xstrdup(comment_line_str);
+}
+
 struct git_var {
 	const char *name;
 	char *(*read)(int);
@@ -262,6 +267,10 @@ static struct git_var git_vars[] = {
 		.name = "GIT_CONFIG_GLOBAL",
 		.multiread = git_config_val_global,
 	},
+	{
+		.name = "GIT_COMMENT_STRING",
+		.read = comment_string,
+	},
 	{
 		.name = "GIT_HOSTNAME",
 		.read = hostname,
diff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh
index 883a45399e2..f228cb5bb6f 100755
--- a/t/t0007-git-var.sh
+++ b/t/t0007-git-var.sh
@@ -434,4 +434,14 @@ test_expect_success 'git var -l lists the identity components' '
 	test_grep "^GIT_COMMITTER_DATE=" actual
 '
 
+test_expect_success 'GIT_COMMENT_STRING' '
+	git var GIT_COMMENT_STRING >actual &&
+	echo "#" >expect &&
+	test_cmp expect actual &&
+	git -c core.commentChar=: -c core.commentString=%% \
+		var GIT_COMMENT_STRING >actual &&
+	echo %%>expect &&
+	test_cmp expect actual
+'
+
 test_done

Range-diff against v1:
1:  fa8b80af264 ! 1:  6e310e0af58 var: add GIT_COMMENT_STRING
    @@ Metadata
      ## Commit message ##
         var: add GIT_COMMENT_STRING
     
    -    Since commit 9ccf3e9b22 (config: add core.commentString, 2024-03-27) we
    -    have two separate config keys that set the comment string used by git
    +    Since commit 9ccf3e9b22 (config: add core.commentString, 2024-03-27)
    +    we have two separate config keys that set the comment string used by git
         when creating template commit messages etc. As that commit notes, when
         core.commentString is set to a multi-byte string, it can be useful to
    -    keep core.commentChar set to a single chararcter for compatibilty with
    +    keep core.commentChar set to a single character for compatibility with
         older versions of git. That makes it awkward for scripts to determine
    -    what the comment chararcter is because they need to do something like
    +    what the comment string is because they need to do something like
     
             {
                 echo ' #'
                 git config --get-regex '^core.comment(char|string)$'
             } | sed -n '$s/^[^ ] //p'
     
         Add GIT_COMMENT_STRING to "git var" to make it easier for scripts to
    -    determine the comment character.
    +    determine the comment string.
     
         Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
     
    + ## Documentation/config/core.adoc ##
    +@@ Documentation/config/core.adoc: core.commentString::
    + 	Commands such as `commit` and `tag` that let you edit
    + 	messages consider a line that begins with this character
    + 	commented, and removes them after the editor returns
    +-	(default '#').
    ++	(default '#'). Scripts can query the comment string with
    ++	"`git var GIT_COMMENT_STRING`".
    + +
    + ifndef::with-breaking-changes[]
    + If set to "auto", `git-commit` will select a character that is not
    +
      ## Documentation/git-var.adoc ##
     @@ Documentation/git-var.adoc: endif::git-default-pager[]
          The path to the global (per-user) configuration files, if any.
          This variable can have multiple values.
      
     +`GIT_COMMENT_STRING`::
     +    The comment string used in template commit messages and rebase todo
    -+    lists etc.
    ++    lists etc. as set by `core.commentString` or `core.commentChar`.
     +
      `GIT_HOSTNAME`::
          The hostname of the machine, as reported by the operating system.
-- 
2.56.1.576.g0cfbda1d5c7.dirty


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH] var: add GIT_COMMENT_STRING
  2026-11-25 20:09     ` Kristoffer Haugsbakk
@ 2026-11-26 16:29       ` Phillip Wood
  0 siblings, 0 replies; 12+ messages in thread
From: Phillip Wood @ 2026-11-26 16:29 UTC (permalink / raw)
  To: Kristoffer Haugsbakk, Phillip Wood, git; +Cc: Jeff King

On 25/11/2026 20:09, Kristoffer Haugsbakk wrote:
> On Wed, Nov 25, 2026, at 17:19, Phillip Wood wrote:
>> On 24/11/2026 15:02, Kristoffer Haugsbakk wrote:
>>> On Tue, Nov 24, 2026, at 11:37, Phillip Wood wrote:
> 
>> Perhaps saying "as set by `core.commentString`" would be
>> more better as it does not promise the reader that the config
>> documentation contains additional, useful, information?
> 
> Yeah, this sounds like the sweet spot.

That's what I've used in v2

>> The documentation for GIT_PAGER, GIT_EDITOR and GIT_SEQUENCE_EDITOR
>> mention the relevant config settings when describing how we determine
>> which program to use, but the documentation for things like
>> GIT_DEFAULT_BRANCH does do not.
> 
> After reading just a little, I much prefer the verbosity of `GIT_EDITOR`
> compared to the terseness of `GIT_DEFAULT_BRANCH`.

In a way that extra verbosity is because determining the editor is more 
complicated than determining the default branch name, though we could 
mention the config settings for that and also GIT_COMMITTER_NAME etc.

Thanks

Phillip


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] var: add GIT_COMMENT_STRING
  2026-11-26 16:25 ` [PATCH v2] " Phillip Wood
@ 2026-11-26 20:56   ` Junio C Hamano
  2026-11-27 16:42     ` Phillip Wood
  2026-11-26 21:14   ` Kristoffer Haugsbakk
  1 sibling, 1 reply; 12+ messages in thread
From: Junio C Hamano @ 2026-11-26 20:56 UTC (permalink / raw)
  To: Phillip Wood; +Cc: git, Jeff King, Kristoffer Haugsbakk

Phillip Wood <phillip.wood123@gmail.com> writes:

> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> Since commit 9ccf3e9b22 (config: add core.commentString, 2024-03-27)
> we have two separate config keys that set the comment string used by git
> when creating template commit messages etc. As that commit notes, when
> core.commentString is set to a multi-byte string, it can be useful to
> keep core.commentChar set to a single character for compatibility with
> older versions of git. That makes it awkward for scripts to determine
> what the comment string is because they need to do something like
>
>     {
>         echo ' #'
>         git config --get-regex '^core.comment(char|string)$'
>     } | sed -n '$s/^[^ ] //p'

Did you mean 

	sed -n '$s/^[^ ]* //p'

to catch both " #" (the fallback) and "core.commentstring //"?

> diff --git a/Documentation/config/core.adoc b/Documentation/config/core.adoc
> index bdc74d291cc..e348d8895d1 100644
> --- a/Documentation/config/core.adoc
> +++ b/Documentation/config/core.adoc
> @@ -549,7 +549,8 @@ core.commentString::
>  	Commands such as `commit` and `tag` that let you edit
>  	messages consider a line that begins with this character
>  	commented, and removes them after the editor returns
> -	(default '#').
> +	(default '#'). Scripts can query the comment string with
> +	"`git var GIT_COMMENT_STRING`".

Elsewhere in the documentation (such as Documentation/config.adoc and
Documentation/git-var.adoc), 'git var' invocations in backticks are
written without surrounding double quotes, so dropping the outer quotes
here would match the surrounding style.

> diff --git a/builtin/var.c b/builtin/var.c
> index eb85a985b15..6dc8ec4ba9f 100644
> --- a/builtin/var.c
> +++ b/builtin/var.c
> @@ -188,6 +188,11 @@ static char *hostname(int ident_flag UNUSED)
>  	return xstrdup(buf);
>  }
>  
> +static char *comment_string(int ident_flag UNUSED)
> +{
> +	return xstrdup(comment_line_str);
> +}
> +

OK, like other .read() functions like committer(), we return a copy to
the caller to be consumed by list_vars(), which will free() it
afterwards.

> diff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh
> index 883a45399e2..f228cb5bb6f 100755
> --- a/t/t0007-git-var.sh
> +++ b/t/t0007-git-var.sh
> @@ -434,4 +434,14 @@ test_expect_success 'git var -l lists the identity components' '
>  	test_grep "^GIT_COMMITTER_DATE=" actual
>  '
>  
> +test_expect_success 'GIT_COMMENT_STRING' '
> +	git var GIT_COMMENT_STRING >actual &&
> +	echo "#" >expect &&
> +	test_cmp expect actual &&
> +	git -c core.commentChar=: -c core.commentString=%% \
> +		var GIT_COMMENT_STRING >actual &&
> +	echo %%>expect &&
> +	test_cmp expect actual
> +'
> +

Checking the default and core.commentString overriding core.commentChar
looks good.  If you happen to reroll for anything else, testing the
reverse order (core.commentString followed by core.commentChar) would
exercise last-one-wins in both directions, though it is certainly not
necessary on its own.

Looking very good.  Will queue.

Thanks.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] var: add GIT_COMMENT_STRING
  2026-11-26 16:25 ` [PATCH v2] " Phillip Wood
  2026-11-26 20:56   ` Junio C Hamano
@ 2026-11-26 21:14   ` Kristoffer Haugsbakk
  1 sibling, 0 replies; 12+ messages in thread
From: Kristoffer Haugsbakk @ 2026-11-26 21:14 UTC (permalink / raw)
  To: Phillip Wood, git; +Cc: Jeff King, Phillip Wood

On Thu, Nov 26, 2026, at 17:25, Phillip Wood wrote:
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> Since commit 9ccf3e9b22 (config: add core.commentString, 2024-03-27)
> we have two separate config keys that set the comment string used by git
> when creating template commit messages etc. As that commit notes, when
> core.commentString is set to a multi-byte string, it can be useful to
> keep core.commentChar set to a single character for compatibility with
> older versions of git. That makes it awkward for scripts to determine
> what the comment string is because they need to do something like
>
>     {
>         echo ' #'
>         git config --get-regex '^core.comment(char|string)$'
>     } | sed -n '$s/^[^ ] //p'
>
> Add GIT_COMMENT_STRING to "git var" to make it easier for scripts to
> determine the comment string.
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---

Looks good.

> Changes since V1:
>  - Fixed typos in commit message
>  - Added a reference to `git var GIT_COMMENT_STRING` to the
>    documentation for core.commentString

Oh, I didn’t think of that. That’s a good improvement.

>  - Added a reference to the relevant config keys to the documentation
>    for GIT_COMMENT_STRING
>
> base-commit: f7de81456940dd6f3274e461149bba12965de609
> Published-As:
> https://github.com/phillipwood/git/releases/tag/pw%2Fvar-comment-string%2Fv2
> View-Changes-At:
> https://github.com/phillipwood/git/compare/f7de81456...6e310e0af
> Fetch-It-Via: git fetch https://github.com/phillipwood/git
> pw/var-comment-string/v2
>[snip]

I think this is good. I have nothing to add in addition to what
Junio wrote.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH v2] var: add GIT_COMMENT_STRING
  2026-11-26 20:56   ` Junio C Hamano
@ 2026-11-27 16:42     ` Phillip Wood
  0 siblings, 0 replies; 12+ messages in thread
From: Phillip Wood @ 2026-11-27 16:42 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Jeff King, Kristoffer Haugsbakk

On 26/11/2026 20:56, Junio C Hamano wrote:
> Phillip Wood <phillip.wood123@gmail.com> writes:
> 
>> what the comment string is because they need to do something like
>>
>>      {
>>          echo ' #'
>>          git config --get-regex '^core.comment(char|string)$'
>>      } | sed -n '$s/^[^ ] //p'
> 
> Did you mean
> 
> 	sed -n '$s/^[^ ]* //p'
> 
> to catch both " #" (the fallback) and "core.commentstring //"?

Well spotted (though I did say "something like" :-/)

>> diff --git a/Documentation/config/core.adoc b/Documentation/config/core.adoc
>> index bdc74d291cc..e348d8895d1 100644
>> --- a/Documentation/config/core.adoc
>> +++ b/Documentation/config/core.adoc
>> @@ -549,7 +549,8 @@ core.commentString::
>>   	Commands such as `commit` and `tag` that let you edit
>>   	messages consider a line that begins with this character
>>   	commented, and removes them after the editor returns
>> -	(default '#').
>> +	(default '#'). Scripts can query the comment string with
>> +	"`git var GIT_COMMENT_STRING`".
> 
> Elsewhere in the documentation (such as Documentation/config.adoc and
> Documentation/git-var.adoc), 'git var' invocations in backticks are
> written without surrounding double quotes, so dropping the outer quotes
> here would match the surrounding style.

I change it to match the existing style

Thanks

Phillip

>> diff --git a/builtin/var.c b/builtin/var.c
>> index eb85a985b15..6dc8ec4ba9f 100644
>> --- a/builtin/var.c
>> +++ b/builtin/var.c
>> @@ -188,6 +188,11 @@ static char *hostname(int ident_flag UNUSED)
>>   	return xstrdup(buf);
>>   }
>>   
>> +static char *comment_string(int ident_flag UNUSED)
>> +{
>> +	return xstrdup(comment_line_str);
>> +}
>> +
> 
> OK, like other .read() functions like committer(), we return a copy to
> the caller to be consumed by list_vars(), which will free() it
> afterwards.
> 
>> diff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh
>> index 883a45399e2..f228cb5bb6f 100755
>> --- a/t/t0007-git-var.sh
>> +++ b/t/t0007-git-var.sh
>> @@ -434,4 +434,14 @@ test_expect_success 'git var -l lists the identity components' '
>>   	test_grep "^GIT_COMMITTER_DATE=" actual
>>   '
>>   
>> +test_expect_success 'GIT_COMMENT_STRING' '
>> +	git var GIT_COMMENT_STRING >actual &&
>> +	echo "#" >expect &&
>> +	test_cmp expect actual &&
>> +	git -c core.commentChar=: -c core.commentString=%% \
>> +		var GIT_COMMENT_STRING >actual &&
>> +	echo %%>expect &&
>> +	test_cmp expect actual
>> +'
>> +
> 
> Checking the default and core.commentString overriding core.commentChar
> looks good.  If you happen to reroll for anything else, testing the
> reverse order (core.commentString followed by core.commentChar) would
> exercise last-one-wins in both directions, though it is certainly not
> necessary on its own.
> 
> Looking very good.  Will queue.
> 
> Thanks.


^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH v3] var: add GIT_COMMENT_STRING
  2026-11-24 10:37 [PATCH] var: add GIT_COMMENT_STRING Phillip Wood
                   ` (2 preceding siblings ...)
  2026-11-26 16:25 ` [PATCH v2] " Phillip Wood
@ 2026-11-29 16:18 ` Phillip Wood
  2026-11-29 19:15   ` Junio C Hamano
  3 siblings, 1 reply; 12+ messages in thread
From: Phillip Wood @ 2026-11-29 16:18 UTC (permalink / raw)
  To: git; +Cc: Jeff King, Junio C Hamano, Kristoffer Haugsbakk, Phillip Wood

From: Phillip Wood <phillip.wood@dunelm.org.uk>

Since commit 9ccf3e9b22 (config: add core.commentString, 2024-03-27)
we have two separate config keys that set the comment string used by git
when creating template commit messages etc. As that commit notes, when
core.commentString is set to a multi-byte string, it can be useful to
keep core.commentChar set to a single character for compatibility with
older versions of git. That makes it awkward for scripts to determine
what the comment string is because they need to do something like

    {
        echo ' #'
        git config --get-regex '^core.comment(char|string)$'
    } | sed -n '$s/^[^ ]* //p'

Add GIT_COMMENT_STRING to "git var" to make it easier for scripts to
determine the comment string.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
Thanks to Junio and Kristoffer for their comments

Changes since V2:
 - Fixed sed expression in commit message
 - Remove quotes around "git var" command in the documentation

Changes since V1:
 - Fixed typos in commit message
 - Added a reference to `git var GIT_COMMENT_STRING` to the
   documentation for core.commentString
 - Added a reference to the relevant config keys to the documentation
   for GIT_COMMENT_STRING

base-commit: f7de81456940dd6f3274e461149bba12965de609
Published-As: https://github.com/phillipwood/git/releases/tag/pw%2Fvar-comment-string%2Fv3
View-Changes-At: https://github.com/phillipwood/git/compare/f7de81456...e3dcd5207
Fetch-It-Via: git fetch https://github.com/phillipwood/git pw/var-comment-string/v3

 Documentation/config/core.adoc |  3 ++-
 Documentation/git-var.adoc     |  4 ++++
 builtin/var.c                  |  9 +++++++++
 t/t0007-git-var.sh             | 10 ++++++++++
 4 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/Documentation/config/core.adoc b/Documentation/config/core.adoc
index bdc74d291cc..796131006ac 100644
--- a/Documentation/config/core.adoc
+++ b/Documentation/config/core.adoc
@@ -549,7 +549,8 @@ core.commentString::
 	Commands such as `commit` and `tag` that let you edit
 	messages consider a line that begins with this character
 	commented, and removes them after the editor returns
-	(default '#').
+	(default '#'). Scripts can query the comment string with
+	`git var GIT_COMMENT_STRING`.
 +
 ifndef::with-breaking-changes[]
 If set to "auto", `git-commit` will select a character that is not
diff --git a/Documentation/git-var.adoc b/Documentation/git-var.adoc
index 5f240eb56e3..9c3778b2535 100644
--- a/Documentation/git-var.adoc
+++ b/Documentation/git-var.adoc
@@ -130,6 +130,10 @@ endif::git-default-pager[]
     The path to the global (per-user) configuration files, if any.
     This variable can have multiple values.
 
+`GIT_COMMENT_STRING`::
+    The comment string used in template commit messages and rebase todo
+    lists etc. as set by `core.commentString` or `core.commentChar`.
+
 `GIT_HOSTNAME`::
     The hostname of the machine, as reported by the operating system.
     This is the hostname matched by `includeIf "hostname:..."` (see
diff --git a/builtin/var.c b/builtin/var.c
index eb85a985b15..6dc8ec4ba9f 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -188,6 +188,11 @@ static char *hostname(int ident_flag UNUSED)
 	return xstrdup(buf);
 }
 
+static char *comment_string(int ident_flag UNUSED)
+{
+	return xstrdup(comment_line_str);
+}
+
 struct git_var {
 	const char *name;
 	char *(*read)(int);
@@ -262,6 +267,10 @@ static struct git_var git_vars[] = {
 		.name = "GIT_CONFIG_GLOBAL",
 		.multiread = git_config_val_global,
 	},
+	{
+		.name = "GIT_COMMENT_STRING",
+		.read = comment_string,
+	},
 	{
 		.name = "GIT_HOSTNAME",
 		.read = hostname,
diff --git a/t/t0007-git-var.sh b/t/t0007-git-var.sh
index 883a45399e2..f228cb5bb6f 100755
--- a/t/t0007-git-var.sh
+++ b/t/t0007-git-var.sh
@@ -434,4 +434,14 @@ test_expect_success 'git var -l lists the identity components' '
 	test_grep "^GIT_COMMITTER_DATE=" actual
 '
 
+test_expect_success 'GIT_COMMENT_STRING' '
+	git var GIT_COMMENT_STRING >actual &&
+	echo "#" >expect &&
+	test_cmp expect actual &&
+	git -c core.commentChar=: -c core.commentString=%% \
+		var GIT_COMMENT_STRING >actual &&
+	echo %%>expect &&
+	test_cmp expect actual
+'
+
 test_done

Range-diff against v2:
1:  6e310e0af58 ! 1:  e3dcd520771 var: add GIT_COMMENT_STRING
    @@ Commit message
             {
                 echo ' #'
                 git config --get-regex '^core.comment(char|string)$'
    -        } | sed -n '$s/^[^ ] //p'
    +        } | sed -n '$s/^[^ ]* //p'
     
         Add GIT_COMMENT_STRING to "git var" to make it easier for scripts to
         determine the comment string.
    @@ Documentation/config/core.adoc: core.commentString::
      	commented, and removes them after the editor returns
     -	(default '#').
     +	(default '#'). Scripts can query the comment string with
    -+	"`git var GIT_COMMENT_STRING`".
    ++	`git var GIT_COMMENT_STRING`.
      +
      ifndef::with-breaking-changes[]
      If set to "auto", `git-commit` will select a character that is not
-- 
2.56.1.576.g0cfbda1d5c7.dirty


^ permalink raw reply related	[flat|nested] 12+ messages in thread

* Re: [PATCH v3] var: add GIT_COMMENT_STRING
  2026-11-29 16:18 ` [PATCH v3] " Phillip Wood
@ 2026-11-29 19:15   ` Junio C Hamano
  0 siblings, 0 replies; 12+ messages in thread
From: Junio C Hamano @ 2026-11-29 19:15 UTC (permalink / raw)
  To: Phillip Wood; +Cc: git, Jeff King, Kristoffer Haugsbakk

Phillip Wood <phillip.wood123@gmail.com> writes:

> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> Since commit 9ccf3e9b22 (config: add core.commentString, 2024-03-27)
> we have two separate config keys that set the comment string used by git
> when creating template commit messages etc. As that commit notes, when
> core.commentString is set to a multi-byte string, it can be useful to
> keep core.commentChar set to a single character for compatibility with
> older versions of git. That makes it awkward for scripts to determine
> what the comment string is because they need to do something like
>
>     {
>         echo ' #'
>         git config --get-regex '^core.comment(char|string)$'
>     } | sed -n '$s/^[^ ]* //p'
>
> Add GIT_COMMENT_STRING to "git var" to make it easier for scripts to
> determine the comment string.
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
> Thanks to Junio and Kristoffer for their comments
>
> Changes since V2:
>  - Fixed sed expression in commit message
>  - Remove quotes around "git var" command in the documentation

This iteration matches what I expected to see after the review of
the previous one.  Looking good.

Thanks.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-11-29 19:15 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 10:37 [PATCH] var: add GIT_COMMENT_STRING Phillip Wood
2026-11-24 15:02 ` Kristoffer Haugsbakk
2026-11-25 16:19   ` Phillip Wood
2026-11-25 20:09     ` Kristoffer Haugsbakk
2026-11-26 16:29       ` Phillip Wood
2026-11-24 20:24 ` Junio C Hamano
2026-11-26 16:25 ` [PATCH v2] " Phillip Wood
2026-11-26 20:56   ` Junio C Hamano
2026-11-27 16:42     ` Phillip Wood
2026-11-26 21:14   ` Kristoffer Haugsbakk
2026-11-29 16:18 ` [PATCH v3] " Phillip Wood
2026-11-29 19:15   ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox