Thread View: linux.kernel.git
12 messages
12 total messages
Started by Phillip Wood
Tue, 24 Nov 2026 10:37
[PATCH] var: add GIT_COMMENT_STRING
Author: Phillip Wood
Date: Tue, 24 Nov 2026 10:37
Date: Tue, 24 Nov 2026 10:37
94 lines
13590 bytes
13590 bytes
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
Re: [PATCH] var: add GIT_COMMENT_STRING
Author: "Kristoffer Haugsbakk"
Date: Tue, 24 Nov 2026 15:02
Date: Tue, 24 Nov 2026 15:02
125 lines
16824 bytes
16824 bytes
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
Re: [PATCH] var: add GIT_COMMENT_STRING
Author: Junio C Hamano
Date: Tue, 24 Nov 2026 20:24
Date: Tue, 24 Nov 2026 20:24
26 lines
13566 bytes
13566 bytes
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.
Re: [PATCH] var: add GIT_COMMENT_STRING
Author: Phillip Wood
Date: Wed, 25 Nov 2026 16:19
Date: Wed, 25 Nov 2026 16:19
118 lines
13193 bytes
13193 bytes
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
>
Re: [PATCH] var: add GIT_COMMENT_STRING
Author: "Kristoffer Haugsbakk"
Date: Wed, 25 Nov 2026 20:09
Date: Wed, 25 Nov 2026 20:09
64 lines
15187 bytes
15187 bytes
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.
[PATCH v2] var: add GIT_COMMENT_STRING
Author: Phillip Wood
Date: Thu, 26 Nov 2026 16:25
Date: Thu, 26 Nov 2026 16:25
170 lines
17532 bytes
17532 bytes
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
Re: [PATCH] var: add GIT_COMMENT_STRING
Author: Phillip Wood
Date: Thu, 26 Nov 2026 16:29
Date: Thu, 26 Nov 2026 16:29
29 lines
12296 bytes
12296 bytes
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
Re: [PATCH v2] var: add GIT_COMMENT_STRING
Author: Junio C Hamano
Date: Thu, 26 Nov 2026 20:56
Date: Thu, 26 Nov 2026 20:56
87 lines
15740 bytes
15740 bytes
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.
Re: [PATCH v2] var: add GIT_COMMENT_STRING
Author: "Kristoffer Haugsbakk"
Date: Thu, 26 Nov 2026 21:14
Date: Thu, 26 Nov 2026 21:14
48 lines
14588 bytes
14588 bytes
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.
Re: [PATCH v2] var: add GIT_COMMENT_STRING
Author: Phillip Wood
Date: Fri, 27 Nov 2026 16:42
Date: Fri, 27 Nov 2026 16:42
88 lines
13954 bytes
13954 bytes
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.
[PATCH v3] var: add GIT_COMMENT_STRING
Author: Phillip Wood
Date: Sun, 29 Nov 2026 16:18
Date: Sun, 29 Nov 2026 16:18
143 lines
16007 bytes
16007 bytes
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
Re: [PATCH v3] var: add GIT_COMMENT_STRING
Author: Junio C Hamano
Date: Sun, 29 Nov 2026 19:15
Date: Sun, 29 Nov 2026 19:15
33 lines
13796 bytes
13796 bytes
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.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads