Skip to content

Commit 2ce082c

Browse files
committed
Merge branch 'master' into next
* master: receive-pack: do not expect object 0{40} to exist t3200: add test case for 'branch -m' branch -m: handle no arg properly Conflicts: builtin/branch.c
2 parents a028561 + ee6dfb2 commit 2ce082c

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

builtin/branch.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -771,12 +771,14 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
771771
usage_with_options(builtin_branch_usage, options);
772772
if (edit_branch_description(branch_name))
773773
return 1;
774-
}
775-
else if (rename && (argc == 1))
776-
rename_branch(head, argv[0], rename > 1);
777-
else if (rename && (argc == 2))
778-
rename_branch(argv[0], argv[1], rename > 1);
779-
else if (argc <= 2) {
774+
} else if (rename) {
775+
if (argc == 1)
776+
rename_branch(head, argv[0], rename > 1);
777+
else if (argc == 2)
778+
rename_branch(argv[0], argv[1], rename > 1);
779+
else
780+
usage_with_options(builtin_branch_usage, options);
781+
} else if (argc <= 2) {
780782
if (kinds != REF_LOCAL_BRANCH)
781783
die(_("-a and -r options to 'git branch' do not make sense with a branch name"));
782784
create_branch(head, argv[0], (argc == 2) ? argv[1] : head,

builtin/receive-pack.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ static int command_singleton_iterator(void *cb_data, unsigned char sha1[20])
634634
struct command **cmd_list = cb_data;
635635
struct command *cmd = *cmd_list;
636636

637-
if (!cmd)
637+
if (!cmd || is_null_sha1(cmd->new_sha1))
638638
return -1; /* end of list */
639639
*cmd_list = NULL; /* this returns only one */
640640
hashcpy(sha1, cmd->new_sha1);
@@ -659,11 +659,16 @@ static int iterate_receive_command_list(void *cb_data, unsigned char sha1[20])
659659
struct command **cmd_list = cb_data;
660660
struct command *cmd = *cmd_list;
661661

662-
if (!cmd)
663-
return -1; /* end of list */
664-
*cmd_list = cmd->next;
665-
hashcpy(sha1, cmd->new_sha1);
666-
return 0;
662+
while (cmd) {
663+
if (!is_null_sha1(cmd->new_sha1)) {
664+
hashcpy(sha1, cmd->new_sha1);
665+
*cmd_list = cmd->next;
666+
return 0;
667+
}
668+
cmd = cmd->next;
669+
}
670+
*cmd_list = NULL;
671+
return -1; /* end of list */
667672
}
668673

669674
static void execute_commands(struct command *commands, const char *unpacker_error)

t/t3200-branch.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ test_expect_success \
7474
git branch -d l/m &&
7575
git branch l'
7676

77+
test_expect_success \
78+
'git branch -m dumps usage' \
79+
'test_expect_code 129 git branch -m 2>err &&
80+
grep "[Uu]sage: git branch" err'
81+
7782
test_expect_success \
7883
'git branch -m m m/m should work' \
7984
'git branch -l m &&

0 commit comments

Comments
 (0)