Skip to content

Commit

Permalink
builtin-branch: Fix crash on invalid use of --force
Browse files Browse the repository at this point in the history
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 <vfr@lyx.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Vincent van Ravesteijn authored and Junio C Hamano committed Nov 23, 2011
1 parent b15aa97 commit 5cd75c7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions builtin/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, options, builtin_branch_usage,
0);

if (!delete && !rename && !force_create && argc == 0)
if (!delete && !rename && argc == 0)
list = 1;

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

0 comments on commit 5cd75c7

Please sign in to comment.