From 3706ed298cbb5d4052ca0793ca36d9f28b4885bc Mon Sep 17 00:00:00 2001 From: Tay Ray Chuan Date: Thu, 3 Nov 2011 00:17:12 +0800 Subject: [PATCH 1/3] branch -m: handle no arg properly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 009b7138ac..51ca6a02d7 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, From db85b3a74fd1c50f007c198e4dc7265fdc1f2749 Mon Sep 17 00:00:00 2001 From: Stefan Naewe Date: Wed, 2 Nov 2011 16:07:05 +0100 Subject: [PATCH 2/3] t3200: add test case for 'branch -m' Signed-off-by: Stefan Naewe Signed-off-by: Junio C Hamano --- t/t3200-branch.sh | 5 +++++ 1 file changed, 5 insertions(+) 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 && From ee6dfb2d83ba1b057943e705f707fa27e34e47f9 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 3 Nov 2011 12:15:08 -0700 Subject: [PATCH 3/3] receive-pack: do not expect object 0{40} to exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When pushing to delete a ref, it uses 0{40} as an object name to signal that the request is a deletion. We shouldn't trigger "deletion of a corrupt ref" warning in such a case, which was designed to notice that a ref points at an object that is truly missing from the repository. Reported-by: Stefan Näwe Signed-off-by: Junio C Hamano --- builtin/receive-pack.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) 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)