struct commit *commit,
struct commit *fallback)
{
- khint_t pos = kh_get_oid_map(replayed_commits, commit->object.oid);
+ khint_t pos;
+ if (!commit)
+ return fallback;
+ pos = kh_get_oid_map(replayed_commits, commit->object.oid);
if (pos == kh_end(replayed_commits))
return fallback;
return kh_value(replayed_commits, pos);
struct commit *base, *replayed_base;
struct tree *pickme_tree, *base_tree, *replayed_base_tree;
- base = pickme->parents->item;
- replayed_base = mapped_commit(replayed_commits, base, onto);
+ if (pickme->parents) {
+ base = pickme->parents->item;
+ base_tree = repo_get_commit_tree(repo, base);
+ } else {
+ base = NULL;
+ base_tree = lookup_tree(repo, repo->hash_algo->empty_tree);
+ }
+ replayed_base = mapped_commit(replayed_commits, base, onto);
replayed_base_tree = repo_get_commit_tree(repo, replayed_base);
pickme_tree = repo_get_commit_tree(repo, pickme);
- base_tree = repo_get_commit_tree(repo, base);
merge_opt->branch1 = short_commit_name(repo, replayed_base);
merge_opt->branch2 = short_commit_name(repo, pickme);
- merge_opt->ancestor = xstrfmt("parent of %s", merge_opt->branch2);
+ if (pickme->parents)
+ merge_opt->ancestor = xstrfmt("parent of %s", merge_opt->branch2);
+ else
+ merge_opt->ancestor = xstrdup("empty tree");
merge_incore_nonrecursive(merge_opt,
base_tree,
set_up_replay_mode(revs->repo, &revs->cmdline, opts->onto,
&detached_head, &advance, &onto, &update_refs);
- /* FIXME: Should allow replaying commits with the first as a root commit */
-
if (prepare_revision_walk(revs) < 0) {
ret = error(_("error preparing revisions"));
goto out;
khint_t pos;
int hr;
- if (!commit->parents)
- die(_("replaying down from root commit is not supported yet!"));
- if (commit->parents->next)
+ if (commit->parents && commit->parents->next)
die(_("replaying merge commits is not supported yet!"));
last_commit = pick_regular_commit(revs->repo, commit, replayed_commits,
test_cmp expect actual
'
-test_expect_success 'no base or negative ref gives no-replaying down to root error' '
- echo "fatal: replaying down from root commit is not supported yet!" >expect &&
- test_must_fail git replay --onto=topic1 topic2 2>actual &&
+test_expect_success 'replay down to root onto another branch' '
+ git replay --ref-action=print --onto main topic2 >result &&
+
+ test_line_count = 1 result &&
+
+ git log --format=%s $(cut -f 3 -d " " result) >actual &&
+ test_write_lines E D C M L B A >expect &&
test_cmp expect actual
'