From: Junio C Hamano <gitster@pobox.com>
To: Phillip Wood <phillip.wood123@gmail.com>
Cc: git@vger.kernel.org, Jeff King <peff@peff.net>,
Kristoffer Haugsbakk <code@khaugsbakk.name>
Subject: Re: [PATCH v2] var: add GIT_COMMENT_STRING
Date: Thu, 26 Nov 2026 12:56:49 -0800 [thread overview]
Message-ID: <xmqq5wxjia5q.fsf@gitster.g> (raw)
In-Reply-To: <6e310e0af58cf693819a8d7384c1560e2e342d4b.1795710343.git.phillip.wood@dunelm.org.uk> (Phillip Wood's message of "Thu, 26 Nov 2026 16:25:52 +0000")
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.
next prev parent reply other threads:[~2026-11-26 20:56 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq5wxjia5q.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=code@khaugsbakk.name \
--cc=git@vger.kernel.org \
--cc=peff@peff.net \
--cc=phillip.wood123@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.