diff --git a/builtin/branch.c b/builtin/branch.c index 477442938c..58ee7a4e30 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -771,12 +771,14 @@ int cmd_branch(int argc, const char **argv, const char *prefix) usage_with_options(builtin_branch_usage, options); if (edit_branch_description(branch_name)) return 1; - } - 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, diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 261b610d24..7ec68a1e80 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -634,7 +634,7 @@ static int command_singleton_iterator(void *cb_data, unsigned char sha1[20]) struct command **cmd_list = cb_data; struct command *cmd = *cmd_list; - if (!cmd) + if (!cmd || is_null_sha1(cmd->new_sha1)) return -1; /* end of list */ *cmd_list = NULL; /* this returns only one */ hashcpy(sha1, cmd->new_sha1); @@ -659,11 +659,16 @@ static int iterate_receive_command_list(void *cb_data, unsigned char sha1[20]) struct command **cmd_list = cb_data; struct command *cmd = *cmd_list; - if (!cmd) - return -1; /* end of list */ - *cmd_list = cmd->next; - hashcpy(sha1, cmd->new_sha1); - return 0; + while (cmd) { + if (!is_null_sha1(cmd->new_sha1)) { + hashcpy(sha1, cmd->new_sha1); + *cmd_list = cmd->next; + return 0; + } + cmd = cmd->next; + } + *cmd_list = NULL; + return -1; /* end of list */ } static void execute_commands(struct command *commands, const char *unpacker_error) diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 2f5eada0d2..bc73c2099b 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -74,6 +74,11 @@ test_expect_success \ git branch -d l/m && git branch l' +test_expect_success \ + 'git branch -m dumps usage' \ + 'test_expect_code 129 git branch -m 2>err && + grep "[Uu]sage: git branch" err' + test_expect_success \ 'git branch -m m m/m should work' \ 'git branch -l m &&