Skip to content

Commit 5cd75c7

Browse files
vfr-nlgitster
authored andcommitted
builtin-branch: Fix crash on invalid use of --force
The option --force should not put us in 'create branch' mode. The fact that this option is only valid in 'create branch' mode is already caught by the the next 'if' in which we assure that we are in the correct mode. Without this patch, "git branch -f" without any other argument ends up calling create_branch without any branch name. Signed-off-by: Vincent van Ravesteijn <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b15aa97 commit 5cd75c7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

builtin/branch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
705705
argc = parse_options(argc, argv, prefix, options, builtin_branch_usage,
706706
0);
707707

708-
if (!delete && !rename && !force_create && argc == 0)
708+
if (!delete && !rename && argc == 0)
709709
list = 1;
710710

711711
if (!!delete + !!rename + !!force_create + !!list > 1)
@@ -726,7 +726,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
726726
rename_branch(argv[0], argv[1], rename > 1);
727727
else
728728
usage_with_options(builtin_branch_usage, options);
729-
} else if (argc <= 2) {
729+
} else if (argc > 0 && argc <= 2) {
730730
if (kinds != REF_LOCAL_BRANCH)
731731
die(_("-a and -r options to 'git branch' do not make sense with a branch name"));
732732
create_branch(head, argv[0], (argc == 2) ? argv[1] : head,

0 commit comments

Comments
 (0)