summaryrefslogtreecommitdiff
path: root/builtin/merge.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2011-05-12 11:09:46 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-05-16 20:00:30 (GMT)
commit161807349aa1ee853880a5c6e39c53f55b10077d (patch)
treeaaf6d538b6c81fddf445b6f649042aed125571f9 /builtin/merge.c
parent96dbe93da541cb930bacd4e2df0a95e41d4c6441 (diff)
downloadgit-161807349aa1ee853880a5c6e39c53f55b10077d.zip
git-161807349aa1ee853880a5c6e39c53f55b10077d.tar.gz
git-161807349aa1ee853880a5c6e39c53f55b10077d.tar.bz2
cherry-pick: handle root commits with external strategies
The merge-recursive strategy already handles root commits; it cherry-picks the difference between the empty tree and the root commit's tree. However, for external strategies, we dereference NULL and segfault while building the argument list. Instead, let's handle this by passing the empty tree sha1 to the merge script. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/merge.c')
-rw-r--r--builtin/merge.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/builtin/merge.c b/builtin/merge.c
index d54e7dd..8a0f690 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -590,6 +590,14 @@ static void write_tree_trivial(unsigned char *sha1)
die(_("git write-tree failed to write a tree"));
}
+static const char *merge_argument(struct commit *commit)
+{
+ if (commit)
+ return sha1_to_hex(commit->object.sha1);
+ else
+ return EMPTY_TREE_SHA1_HEX;
+}
+
int try_merge_command(const char *strategy, size_t xopts_nr,
const char **xopts, struct commit_list *common,
const char *head_arg, struct commit_list *remotes)
@@ -610,11 +618,11 @@ int try_merge_command(const char *strategy, size_t xopts_nr,
args[i++] = s;
}
for (j = common; j; j = j->next)
- args[i++] = xstrdup(sha1_to_hex(j->item->object.sha1));
+ args[i++] = xstrdup(merge_argument(j->item));
args[i++] = "--";
args[i++] = head_arg;
for (j = remotes; j; j = j->next)
- args[i++] = xstrdup(sha1_to_hex(j->item->object.sha1));
+ args[i++] = xstrdup(merge_argument(j->item));
args[i] = NULL;
ret = run_command_v_opt(args, RUN_GIT_CMD);
strbuf_release(&buf);