branch -m: handle no arg properly

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 <stefan.naewe@atlas-elektronik.com>
Signed-off-by: Tay Ray Chuan <rctay89@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Tay Ray Chuan 2011-11-03 00:17:12 +08:00 коммит произвёл Junio C Hamano
Родитель 87bf9a7048
Коммит 3706ed298c
1 изменённых файлов: 8 добавлений и 5 удалений

Просмотреть файл

@ -719,11 +719,14 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
else if (list) else if (list)
return print_ref_list(kinds, detached, verbose, abbrev, return print_ref_list(kinds, detached, verbose, abbrev,
with_commit, argv); with_commit, argv);
else if (rename && (argc == 1)) else if (rename) {
rename_branch(head, argv[0], rename > 1); if (argc == 1)
else if (rename && (argc == 2)) rename_branch(head, argv[0], rename > 1);
rename_branch(argv[0], argv[1], rename > 1); else if (argc == 2)
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) if (kinds != REF_LOCAL_BRANCH)
die(_("-a and -r options to 'git branch' do not make sense with a branch name")); 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, create_branch(head, argv[0], (argc == 2) ? argv[1] : head,