Skip to content

Commit 0fbdf03

Browse files
committed
branch: add a no-prefix option
This patch adds a '--no-prefix' option to 'git branch' to selectively override the 'branch.addCurrentBranchAsPrefix' configuration parameter. Signed-off-by: VALERI Yoann <yoann.valeri@cea.fr>
1 parent 49641fb commit 0fbdf03

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

builtin/branch.c

Lines changed: 7 additions & 2 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_prefix = 0;
717718
const char *new_upstream = NULL;
718719
int noncreate_actions = 0;
719720
/* possible options */
@@ -776,6 +777,7 @@ int cmd_branch(int argc,
776777
OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")),
777778
OPT_BOOL(0, "recurse-submodules", &recurse_submodules_explicit, N_("recurse through submodules")),
778779
OPT_STRING( 0 , "format", &format.format, N_("format"), N_("format to use for the output")),
780+
OPT_BOOL(0, "no-prefix", &no_prefix, N_("do not add a prefix to the branch being created")),
779781
OPT_END(),
780782
};
781783

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

1007-
add_branch_prefix(start_name, branch_name, &new_branch_name);
1009+
if (!no_prefix)
1010+
add_branch_prefix(start_name, branch_name, &new_branch_name);
1011+
else
1012+
strbuf_addstr(&new_branch_name, branch_name);
10081013

10091014
if (recurse_submodules)
10101015
create_branches_recursively(the_repository, new_branch_name.buf,

t/t3200-branch.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1725,9 +1725,11 @@ test_expect_success 'create branch with prefix' '
17251725
git branch branch-with-prefix &&
17261726
git checkout branch-with-prefix &&
17271727
git branch branch-with-prefix &&
1728+
git branch branch-with-no-prefix --no-prefix &&
17281729
test_ref_exists refs/heads/branch-with-prefix &&
17291730
test_ref_exists refs/heads/main-branch-with-prefix &&
1730-
test_ref_exists refs/heads/branch-with-prefix-branch-with-prefix
1731+
test_ref_exists refs/heads/branch-with-prefix-branch-with-prefix &&
1732+
test_ref_exists refs/heads/branch-with-no-prefix
17311733
'
17321734

17331735
test_done

0 commit comments

Comments
 (0)