From 3706ed298cbb5d4052ca0793ca36d9f28b4885bc Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Thu, 3 Nov 2011 00:17:12 +0800 Subject: [PATCH] branch -m: handle no arg properly MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Modify the option parsing heuristic to handle all -m (rename) cases, including the no-arg case. Previously, this "fell through" to the (argc <= 2) case and caused segfault. Reported-by: Stefan Näwe Signed-off-by: Tay Ray Chuan Signed-off-by: Junio C Hamano --- builtin/branch.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/builtin/branch.c b/builtin/branch.c index 009b7138a..51ca6a02d 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -719,11 +719,14 @@ int cmd_branch(int argc, const char **argv, const char *prefix) else if (list) return print_ref_list(kinds, detached, verbose, abbrev, with_commit, argv); - else if (rename && (argc == 1)) - rename_branch(head, argv[0], rename > 1); - else if (rename && (argc == 2)) - rename_branch(argv[0], argv[1], rename > 1); - else if (argc <= 2) { + else if (rename) { + if (argc == 1) + rename_branch(head, argv[0], rename > 1); + else if (argc == 2) + rename_branch(argv[0], argv[1], rename > 1); + else + usage_with_options(builtin_branch_usage, options); + } else if (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, -- 2.30.2