public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: "VALERI Yoann via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Patrick Steinhardt <ps@pks.im>,
	Junio C Hamano <gitster@pobox.com>,
	Yoann Valeri <yoann.valeri@cea.fr>,
	Yoann Valeri <yoann.valeri@cea.fr>,
	VALERI Yoann <yoann.valeri@cea.fr>
Subject: [PATCH v3 2/3] branch: add 'branch.namePrefix' config param
Date: Fri, 06 Mar 2026 13:14:31 +0000	[thread overview]
Message-ID: <d51f71708ceb0263c8e10b6d7915f7a426c88f2e.1772802872.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2202.v3.git.git.1772802872.gitgitgadget@gmail.com>

From: VALERI Yoann <yoann.valeri@cea.fr>

This patch adds a new configuration parameter for the branch creation
feature: 'branch.namePrefix'. It corresponds to the '--name-prefix'
option of 'git branch' made as configuration parameter, and behaves
exactly like it.

Signed-off-by: VALERI Yoann <yoann.valeri@cea.fr>
---
 Documentation/config/branch.adoc |  5 +++++
 branch.c                         | 18 +++++++++++-------
 t/t3200-branch.sh                | 12 ++++++++++++
 3 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/Documentation/config/branch.adoc b/Documentation/config/branch.adoc
index a4db9fa5c8..202c9048b4 100644
--- a/Documentation/config/branch.adoc
+++ b/Documentation/config/branch.adoc
@@ -35,6 +35,11 @@ This option defaults to `never`.
 	value of this variable will be used as the default.
 	See linkgit:git-for-each-ref[1] field names for valid values.
 
+`branch.namePrefix`::
+	When a new branch is created with `git branch`, use the provided value as
+	prefix for its name. Can be '@{current}' to use the current branch's name
+	as prefix.
+
 `branch.<name>.remote`::
 	When on branch _<name>_, it tells `git fetch` and `git push`
 	which remote to fetch from or push to.  The remote to push to
diff --git a/branch.c b/branch.c
index c24d7ce823..5fb7280d47 100644
--- a/branch.c
+++ b/branch.c
@@ -368,18 +368,22 @@ int read_branch_desc(struct strbuf *buf, const char *branch_name)
 void add_branch_prefix(const char *name_prefix,
 					   const char *current_branch, struct strbuf *buf)
 {
-	int value = 0;
+	char *config_prefix = NULL;
 
-	if (!name_prefix)
-		return;
+	if (!name_prefix) {
+		if (repo_config_get_string(the_repository, "branch.namePrefix",
+								   &config_prefix))
+			return;
 
-	if (name_prefix[0] != '@') {
-		strbuf_addstr(buf, name_prefix);
-		return;
+		name_prefix = config_prefix;
 	}
 
-	if (strcmp(name_prefix, "@{current}") == 0)
+	if (name_prefix[0] != '@')
+		strbuf_addstr(buf, name_prefix);
+	else if (strcmp(name_prefix, "@{current}") == 0)
 		strbuf_addstr(buf, current_branch);
+
+    free(config_prefix);
 }
 
 /*
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index 550989a2bb..847a8355cf 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -1734,4 +1734,16 @@ test_expect_success 'create branch with --name-prefix' '
 	git branch -D blob-with-prefix-with-prefix
 '
 
+test_expect_success 'create branch with config prefix' '
+	test_config branch.namePrefix blob &&
+	git branch -- -with-prefix &&
+	test_must_fail git branch -- -with-prefix &&
+	test_config branch.namePrefix "@{current}" &&
+	git checkout main &&
+	git branch -- -with-prefix &&
+	test_ref_exists refs/heads/blob-with-prefix &&
+	test_ref_exists refs/heads/main-with-prefix &&
+	git branch -D blob-with-prefix main-with-prefix
+'
+
 test_done
-- 
gitgitgadget


  parent reply	other threads:[~2026-03-06 13:14 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-20  8:07 [PATCH] branch: add 'branch.addCurrentBranchAsPrefix' config param Yoann Valeri via GitGitGadget
2026-02-20 15:59 ` Junio C Hamano
2026-02-20 16:08 ` Junio C Hamano
2026-02-27 15:48 ` [PATCH v2 0/2] " Yoann Valeri via GitGitGadget
2026-02-27 15:48   ` [PATCH v2 1/2] " VALERI Yoann via GitGitGadget
2026-02-27 15:48   ` [PATCH v2 2/2] branch: add a no-prefix option VALERI Yoann via GitGitGadget
2026-02-27 17:07     ` Junio C Hamano
2026-03-06 13:14   ` [PATCH v3 0/3] branch: add prefixes to new branch names Yoann Valeri via GitGitGadget
2026-03-06 13:14     ` [PATCH v3 1/3] branch: add '--name-prefix' option VALERI Yoann via GitGitGadget
2026-03-07  7:06       ` Eric Sunshine
2026-03-08  7:06       ` Junio C Hamano
2026-03-06 13:14     ` VALERI Yoann via GitGitGadget [this message]
2026-03-07  7:07       ` [PATCH v3 2/3] branch: add 'branch.namePrefix' config param Eric Sunshine
2026-03-06 13:14     ` [PATCH v3 3/3] branch: add '--no-name-prefix' option VALERI Yoann via GitGitGadget
2026-03-06 21:38       ` Junio C Hamano
2026-03-06 21:01     ` [PATCH v3 0/3] branch: add prefixes to new branch names Junio C Hamano
2026-03-07  7:05     ` Eric Sunshine
2026-03-08  6:48       ` 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=d51f71708ceb0263c8e10b6d7915f7a426c88f2e.1772802872.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=ps@pks.im \
    --cc=yoann.valeri@cea.fr \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox