Skip to content

Commit 356e91f

Browse files
Michael J Grubergitster
authored andcommitted
branch: allow -f with -m and -d
-f/--force is the standard way to force an action, and is used by branch for the recreation of existing branches, but not for deleting unmerged branches nor for renaming to an existing branch. Make "-m -f" equivalent to "-M" and "-d -f" equivalent to" -D", i.e. allow -f/--force to be used with -m/-d also. For the list modes, "-f" is simply ignored. Signed-off-by: Michael J Gruber <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ff7aa81 commit 356e91f

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

builtin/branch.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,7 @@ static int edit_branch_description(const char *branch_name)
790790

791791
int cmd_branch(int argc, const char **argv, const char *prefix)
792792
{
793-
int delete = 0, rename = 0, force_create = 0, list = 0;
793+
int delete = 0, rename = 0, force = 0, list = 0;
794794
int verbose = 0, abbrev = -1, detached = 0;
795795
int reflog = 0, edit_description = 0;
796796
int quiet = 0, unset_upstream = 0;
@@ -838,7 +838,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
838838
OPT_BOOL('l', "create-reflog", &reflog, N_("create the branch's reflog")),
839839
OPT_BOOL(0, "edit-description", &edit_description,
840840
N_("edit the description for the branch")),
841-
OPT__FORCE(&force_create, N_("force creation (when already exists)")),
841+
OPT__FORCE(&force, N_("force creation, move/rename, deletion")),
842842
{
843843
OPTION_CALLBACK, 0, "no-merged", &merge_filter_ref,
844844
N_("commit"), N_("print only not merged branches"),
@@ -884,7 +884,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
884884
if (with_commit || merge_filter != NO_FILTER)
885885
list = 1;
886886

887-
if (!!delete + !!rename + !!force_create + !!new_upstream +
887+
if (!!delete + !!rename + !!new_upstream +
888888
list + unset_upstream > 1)
889889
usage_with_options(builtin_branch_usage, options);
890890

@@ -897,6 +897,11 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
897897
colopts = 0;
898898
}
899899

900+
if (force) {
901+
delete *= 2;
902+
rename *= 2;
903+
}
904+
900905
if (delete) {
901906
if (!argc)
902907
die(_("branch name required"));
@@ -1013,7 +1018,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
10131018

10141019
branch_existed = ref_exists(branch->refname);
10151020
create_branch(head, argv[0], (argc == 2) ? argv[1] : head,
1016-
force_create, reflog, 0, quiet, track);
1021+
force, reflog, 0, quiet, track);
10171022

10181023
/*
10191024
* We only show the instructions if the user gave us

t/t3200-branch.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ test_expect_success 'git branch -M o/q o/p should work when o/p exists' '
106106
git branch -M o/q o/p
107107
'
108108

109+
test_expect_success 'git branch -m -f o/q o/p should work when o/p exists' '
110+
git branch o/q &&
111+
git branch -m -f o/q o/p
112+
'
113+
109114
test_expect_success 'git branch -m q r/q should fail when r exists' '
110115
git branch q &&
111116
git branch r &&

0 commit comments

Comments
 (0)