Skip to content

Commit af9dbc8

Browse files
committed
branch: add '--no-name-prefix' option
This patch adds the '--no-name-prefix' option to prevent adding any prefix to the branch being created, whether through the '--name-prefix' option or the 'branch.namePrefix' configuration parameter. Signed-off-by: VALERI Yoann <yoann.valeri@cea.fr>
1 parent 0ab9803 commit af9dbc8

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

builtin/branch.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,8 @@ int cmd_branch(int argc,
713713
{
714714
/* possible actions */
715715
int delete = 0, rename = 0, copy = 0, list = 0,
716-
unset_upstream = 0, show_current = 0, edit_description = 0;
716+
unset_upstream = 0, show_current = 0, edit_description = 0,
717+
no_name_prefix = 0;
717718
const char *new_upstream = NULL;
718719
int noncreate_actions = 0;
719720
/* possible options */
@@ -777,7 +778,8 @@ int cmd_branch(int argc,
777778
OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")),
778779
OPT_BOOL(0, "recurse-submodules", &recurse_submodules_explicit, N_("recurse through submodules")),
779780
OPT_STRING( 0 , "format", &format.format, N_("format"), N_("format to use for the output")),
780-
OPT_STRING(0, "name-prefix", &name_prefix, N_("name"), N_("prefix for the branch to create")),
781+
OPT_STRING_F(0, "name-prefix", &name_prefix, N_("name"), N_("prefix for the branch to create"), PARSE_OPT_NONEG),
782+
OPT_BOOL(0, "no-name-prefix", &no_name_prefix, N_("do not use any prefix for the branch to create")),
781783
OPT_END(),
782784
};
783785

@@ -1006,7 +1008,8 @@ int cmd_branch(int argc,
10061008
if (track == BRANCH_TRACK_OVERRIDE)
10071009
die(_("the '--set-upstream' option is no longer supported. Please use '--track' or '--set-upstream-to' instead"));
10081010

1009-
add_branch_prefix(name_prefix, start_name, &new_branch_name);
1011+
if (!no_name_prefix)
1012+
add_branch_prefix(name_prefix, start_name, &new_branch_name);
10101013
strbuf_addstr(&new_branch_name, branch_name);
10111014

10121015
if (recurse_submodules)

t/t3200-branch.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,13 +1725,15 @@ test_expect_success 'create branch with --name-prefix' '
17251725
git switch blob-with-prefix &&
17261726
git branch --name-prefix "@{current}" -- -with-prefix &&
17271727
test_must_fail git branch --name-prefix "@{current}" -- -with-prefix &&
1728+
git branch --name-prefix "blob" --no-name-prefix branch-with-no-prefix &&
17281729
test_ref_exists refs/heads/branch-with-prefix &&
17291730
test_ref_exists refs/heads/main-with-prefix &&
17301731
test_ref_exists refs/heads/blob-with-prefix &&
17311732
test_ref_exists refs/heads/blob-with-prefix-with-prefix &&
1733+
test_ref_exists refs/heads/branch-with-no-prefix &&
17321734
git checkout main &&
17331735
git branch -D branch-with-prefix main-with-prefix blob-with-prefix &&
1734-
git branch -D blob-with-prefix-with-prefix
1736+
git branch -D blob-with-prefix-with-prefix branch-with-no-prefix
17351737
'
17361738

17371739
test_expect_success 'create branch with config prefix' '
@@ -1741,9 +1743,11 @@ test_expect_success 'create branch with config prefix' '
17411743
test_config branch.namePrefix "@{current}" &&
17421744
git checkout main &&
17431745
git branch -- -with-prefix &&
1746+
git branch --no-name-prefix branch-with-no-prefix &&
17441747
test_ref_exists refs/heads/blob-with-prefix &&
17451748
test_ref_exists refs/heads/main-with-prefix &&
1746-
git branch -D blob-with-prefix main-with-prefix
1749+
test_ref_exists refs/heads/branch-with-no-prefix &&
1750+
git branch -D blob-with-prefix main-with-prefix branch-with-no-prefix
17471751
'
17481752

17491753
test_done

0 commit comments

Comments
 (0)