🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.kernel.git
Article #4072

[PATCH v3] var: add GIT_COMMENT_STRING

#4072
From: Phillip Wood
Date: Sun, 29 Nov 2026 16:18
143 lines
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
Technical Details
Message-ID: <e3dcd520771325cdb376178b12ff9b9769f72cf7.1795969120.git.phillip.wood@dunelm.org.uk>
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76627-linux-kernel-git=dewy.ru
References: <fa8b80af26481e0dc96fd8f80f3c7ba84f60f9d4.1795516651.git.phillip.wood@dunelm.org.uk>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-wdc.pugleaf.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!usenet.network!.POSTED!vger.kernel.org!git+bounces-76627-linux-kernel-git=dewy.ru
From: phillip.wood123@gmail.com (Phillip Wood)
Newsgroups: linux.kernel.git
Subject: [PATCH v3] var: add GIT_COMMENT_STRING
Date: Sun, 29 Nov 2026 16:18:46 +0000
Organization: Usenet Network
Message-ID: <e3dcd520771325cdb376178b12ff9b9769f72cf7.1795969120.git.phillip.wood@dunelm.org.uk>
References: <fa8b80af26481e0dc96fd8f80f3c7ba84f60f9d4.1795516651.git.phillip.wood@dunelm.org.uk>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Injection-Info: usenet.network;
	logging-data="1207603"; mail-complaints-to="abuse@usenet.network"
Cancel-Lock: sha1:V7lWUrtM/P4ptslg0V3bz4Qp95A= sha256:OkQnqKHRDGWiADVfQBRqE0bH89tEJPntaKRJDHC1mHo=
	sha1:jIjjQNvgggqhdESqYR64KEkJkt8= sha256:0+mMEL1xu6IYIpcPGzOOuoW2iWENpF7OBgXBPpDMdoE=
List-ID: <git.vger.kernel.org>
X-Mailpost-Empty-Hdrs: X-Spam-Level
X-Received: from localhost (localhost [127.0.0.1])
	by mail.dewy.ru (Postfix) with ESMTP id 4890C125F98; Sun, 29 Nov 2026 19:19:29 +0300 (MSK)
X-Virus-Scanned: Debian amavisd-new at usenet.network
X-Spam-Flag: NO
X-Spam-Score: -1.949
X-Spam-Status: No, score=-1.949 tagged_above=-9999 required=6.31
	tests=[DCC_CHECK=1.1, DCC_REPUT_70_89=0.1, DKIM_SIGNED=0.1,
	DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FORGED_FROMDOMAIN=0.001,
	FREEMAIL_FROM=0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249,
	MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
	SPF_PASS=-0.001] autolearn=ham autolearn_force=no
X-Authentication-Results: mail.dewy.ru (amavisd-new); dkim=pass (2048-bit key)
	header.d=gmail.com
X-Received: from mail.dewy.ru ([127.0.0.1])
	by localhost (mail.dewy.ru [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id M5WKawwremhV;
	Sun, 29 Nov 2026 19:19:25 +0300 (MSK)
X-Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=172.234.253.10; helo=sea.lore.kernel.org; envelope-from=git+bounces-76627-linux-kernel-git=dewy.ru@vger.kernel.org; receiver=<UNKNOWN> 
X-Authentication-Results: OpenDMARC; dmarc=fail (p=none dis=none) header.from=gmail.com
X-Received: from sea.lore.kernel.org (sea.lore.kernel.org [172.234.253.10])
	by mail.dewy.ru (Postfix) with ESMTPS id C4357125F96; Sun, 29 Nov 2026 19:19:16 +0300 (MSK)
X-Received: from smtp.subspace.kernel.org (conduit.subspace.kernel.org [100.77.114.92])
	by sea.lore.kernel.org (Postfix) with ESMTP id 40C25240E9; Sun, 29 Nov 2026 16:19:15 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass;
	t=1795969155;
	b=QLk6fYKgdVy+v4WiRxnbmMY5CJXuSuOVegmwXQAMWMWxFa+woy24z75NGs9wwJio/t6q
	 wytdhMCw4imoVwy6G0h+gPnguEcAGPCBX6gLQ3BueW8l34aa2FQ9IySDLuKImfAmRxQJA
	 pNAz/cmuqHTP9H8cNozta2AJfTqaqLku4AgZ1thIASyV1i9HFvn/SANouzRUdKHkeG0cO
	 v/uxoT8qmq6jRi7Xh0sgsWG7Lt1vEyOsJhdXL+vhyoJ5nLKCPvMHW+hrrqHttfDIf86as
	 p+EV1SLdZQgoYLPgTo1LRmn0FvrqtJX1O477DVwXDeqUNlrbdqlvEo5hz5B9bD/OHhw==
X-ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795969155;
	h=X-Original-To:Received:DMARC-Filter:Received:DKIM-Signature:
	 X-Google-DKIM-Signature:X-Gm-Message-State:X-Gm-Gg:X-Received:
	 Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:
	 References:Reply-To:X-Mailing-List:List-Id:List-Post:List-Help:
	 List-Subscribe:List-Unsubscribe:List-Owner:Precedence:MIME-Version:
	 Content-Transfer-Encoding;
	bh=+WZF0wyIT7AQjP2ZZbMYEBTcrs2NBPj7tg3rvgcoq9I=;
	b=SOv7qxd0hOdZ7EQSXWe45jCIaOeTakYlsAtNGf1x8GYJvXF1zckbEbvAbEV52HX9kMMB
	 9u228IG3n87CtKj2oFjxGX1OP/o0vip5pFVagN+Qpns3CYeFM1PXGGDhu3jOXj8zYqoBe
	 c0qqNJsnsKCrh+l19D/puQhJ/vISTElGAVdIVlOO2kmod8MCKSr1J5k0hMPnxubueng2D
	 HKQ/VHrzyoNsoT0PAR4D2TkP0eXLdh5sGzU4/8IwVqs2Mm/wqkJR6q2xsFar/ZSfG9pUI
	 PkqYDqHntESVi/+s6ZLcFAWhQN5xN6yx9ccbUk2HptAknsL8ft/epDJssmOufOwrowg==
X-ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; 
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Bj+ClZi2;
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	arc=pass header.oldest-pass=0 smtp.remote-ip=127.0.0.1
X-Received: from localhost.localdomain (localhost [127.0.0.1])
	by smtp.subspace.kernel.org (Postfix) with ESMTP id 17B01606A325;
	Sun, 29 Nov 2026 16:19:15 +0000 (UTC)
X-Authentication-Results: smtp.subspace.kernel.org;
	dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Bj+ClZi2
X-Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.41
X-ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none;
	t=1795969154;
	b=qZ5F3gc10QvRLsgF9yMSaRUY+/25znFcHEluFnSGMB5P8O8kL/rZ8y/2SuaQgpe05sW4
	 Yez9+OFdCs8DDAXoyphtQzV13n/W/xSJBQNTR6bkLActKyjxhexR/rIwJTf0K/i4kKofc
	 DHTJSjFSlNu55VMmxPpY8jlWP8ORgTj4tAh7HwIgr35JYshbxsPQNdYSfOiibdcR90SFD
	 IkGISR8VZth3bnSW2y/EU7/b5f6i1bGeaJWO59tnYfRzu5lNGyUuL3yKKLiuZTIr8OVsC
	 taOLAO6sKFqMzDxMdy3iKbZdNtVuCuRu/UJEKLySO7XJ/e64IXo5ijpKQsUnYSg2VAQ==
X-ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015;
	a=rsa-sha256; c=relaxed/relaxed; t=1795969154;
	h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature:
	 X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject:
	 Date:Message-ID:X-Mailer:In-Reply-To:References:Reply-To:MIME-Version:
	 Content-Transfer-Encoding;
	bh=+WZF0wyIT7AQjP2ZZbMYEBTcrs2NBPj7tg3rvgcoq9I=;
	b=vKB6EnAQixeslupLUyCkhoxnuubKpKPLFNUh0/l6wGLy11oF8Tgi7JUBivzumwudLwDq
	 WUhkLIueAMZX1r8i1gfxoq88Gg4WezHVNrZJxlo4Lk2uiQ3D/BZBisrKwUJpJNCMLNvGH
	 sZ5fmPtHxHuv51XouFK0VIswku/AbBZqUohtXYTEEbDkTUGmpVhd4ZF3K//U0ggxpWNaQ
	 uRJLUiJPI9oawfggmiFVzGKTgfEuB/nZVWzd6oRKQIqOSuawpyi0ya46iZ4L6AFGdG5mM
	 tJ6/em6MIZBrKhDPSm0Ss0xCNkqwJl/01qYzuqKPds0VqKqgN859Vxykh7qqAisQBtQ==
X-ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; 
	dmarc=pass header.from=gmail.com;
	spf=pass smtp.mailfrom=gmail.com;
	dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Bj+ClZi2;
	arc=none smtp.remote-ip=209.85.128.41
X-Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41])
	(using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)
	 key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256)
	(No client certificate requested)
	by smtp.subspace.kernel.org (Postfix) with ESMTPS id D705A606A31C
	for <git@vger.kernel.org>; Sun, 29 Nov 2026 16:19:13 +0000 (UTC)
X-DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D705A606A31C
X-Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com
X-Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com
X-Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-4bb606491faso50201355e9.3
        for <git@vger.kernel.org>; Sun, 29 Nov 2026 08:19:13 -0800 (PST)
X-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20260707; t=1795969152; x=1796573952; darn=vger.kernel.org;
        h=content-transfer-encoding:mime-version:reply-to:references
         :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject
         :date:message-id:reply-to:content-type;
        bh=+WZF0wyIT7AQjP2ZZbMYEBTcrs2NBPj7tg3rvgcoq9I=;
        b=Bj+ClZi2uFnMbiumodaEmWa80tVlI/kC0487jM4SeuW0HPHgIaljR3hvKl5gSiqqPI
         gm1v4mvlvn+0al3DMsisO80j0F5RGxSd1aut3cAWoGp6ruaxmIEDVmZaMqeTkPLNbRyf
         bgz2+xT346xWb7AIPF2lCn/t8PW2Evgm1xWX93iJBmLq+aFvc9h7+c3rGnNOi1KwKGmi
         YPxxKfgmuppN9rk2WdgKzUTAL3ChakS5GFwBwRljcDr3LXyuMeRTHgbW8XAt6+cuufmY
         rZvyp8UJNajcUF/zgGwqdMEq2CMlQhHP6YnSoYdkDzZVYxjSMv2CESTDxT/jAmpumt9K
         jtAA==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20260707; t=1795969152; x=1796573952;
        h=content-transfer-encoding:mime-version:reply-to:references
         :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg
         :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to
         :content-type;
        bh=+WZF0wyIT7AQjP2ZZbMYEBTcrs2NBPj7tg3rvgcoq9I=;
        b=S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hBjR9FHEFYbbYBE1xhyGhaS4Qy3QmVZxY
	uTdZyJoqhT32tIOw4DirhPvdid2/Di88tg==
X-Received: by 2002:a05:600c:674b:b0:4b2:61e5:b2f4 with SMTP id 5b1f17b1804b1-4bb8880f25cmr580739235e9.11.1795969152073;
        Sun, 29 Nov 2026 08:19:12 -0800 (PST)
X-Received: from berwick ([2a0a:ef40:724:6601:f3ff:aebc:61f8:d91f])
        by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bba6a0d65fsm377896705e9.3.2026.11.29.08.19.11
        (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);
        Sun, 29 Nov 2026 08:19:11 -0800 (PST)
X-Cc: Jeff King <peff@peff.net>,
	Junio C Hamano <gitster@pobox.com>,
	Kristoffer Haugsbakk <code@khaugsbakk.name>,
	Phillip Wood <phillip.wood123@gmail.com>
X-Mailer: git-send-email 2.56.1.576.g0cfbda1d5c7.dirty
X-In-Reply-To: <fa8b80af26481e0dc96fd8f80f3c7ba84f60f9d4.1795516651.git.phillip.wood@dunelm.org.uk>
X-Reply-To: Phillip Wood <phillip.wood@dunelm.org.uk>
X-Mailing-List: git@vger.kernel.org
X-List-Post: <mailto:git@vger.kernel.org>
X-List-Help: <mailto:git+help@vger.kernel.org>
X-List-Subscribe: <mailto:git+subscribe@vger.kernel.org>
X-List-Unsubscribe: <mailto:git+unsubscribe@vger.kernel.org>
X-List-Owner: <mailto:git+owner@vger.kernel.org>
X-Precedence: list