Skip to content

Commit 1618073

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 96dbe93 commit 1618073

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

builtin/merge.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,14 @@ static void write_tree_trivial(unsigned char *sha1)
590590
die(_("git write-tree failed to write a tree"));
591591
}
592592

593+
static const char *merge_argument(struct commit *commit)
594+
{
595+
if (commit)
596+
return sha1_to_hex(commit->object.sha1);
597+
else
598+
return EMPTY_TREE_SHA1_HEX;
599+
}
600+
593601
int try_merge_command(const char *strategy, size_t xopts_nr,
594602
const char **xopts, struct commit_list *common,
595603
const char *head_arg, struct commit_list *remotes)
@@ -610,11 +618,11 @@ int try_merge_command(const char *strategy, size_t xopts_nr,
610618
args[i++] = s;
611619
}
612620
for (j = common; j; j = j->next)
613-
args[i++] = xstrdup(sha1_to_hex(j->item->object.sha1));
621+
args[i++] = xstrdup(merge_argument(j->item));
614622
args[i++] = "--";
615623
args[i++] = head_arg;
616624
for (j = remotes; j; j = j->next)
617-
args[i++] = xstrdup(sha1_to_hex(j->item->object.sha1));
625+
args[i++] = xstrdup(merge_argument(j->item));
618626
args[i] = NULL;
619627
ret = run_command_v_opt(args, RUN_GIT_CMD);
620628
strbuf_release(&buf);

0 commit comments

Comments
 (0)