Skip to content

Commit b70dbdf

Browse files
committed
Merge branch 'tc/replay-down-to-root' into seen
git replay now supports replaying down to the root commit. * tc/replay-down-to-root: replay: support replaying down from root commit
2 parents 7d4936c + 2854395 commit b70dbdf

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

replay.c

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,18 @@ static struct commit *pick_regular_commit(struct repository *repo,
271271
struct commit *base, *replayed_base;
272272
struct tree *pickme_tree, *base_tree, *replayed_base_tree;
273273

274-
base = pickme->parents->item;
275-
replayed_base = mapped_commit(replayed_commits, base, onto);
274+
if (pickme->parents) {
275+
base = pickme->parents->item;
276+
replayed_base = mapped_commit(replayed_commits, base, onto);
277+
base_tree = repo_get_commit_tree(repo, base);
278+
} else {
279+
base = NULL;
280+
replayed_base = onto;
281+
base_tree = lookup_tree(repo, repo->hash_algo->empty_tree);
282+
}
276283

277284
replayed_base_tree = repo_get_commit_tree(repo, replayed_base);
278285
pickme_tree = repo_get_commit_tree(repo, pickme);
279-
base_tree = repo_get_commit_tree(repo, base);
280286

281287
if (mode == REPLAY_MODE_PICK) {
282288
/* Cherry-pick: normal order */
@@ -364,8 +370,6 @@ int replay_revisions(struct rev_info *revs,
364370
set_up_replay_mode(revs->repo, &revs->cmdline, opts->onto,
365371
&detached_head, &advance, &revert, &onto, &update_refs);
366372

367-
/* FIXME: Should allow replaying commits with the first as a root commit */
368-
369373
if (prepare_revision_walk(revs) < 0) {
370374
ret = error(_("error preparing revisions"));
371375
goto out;
@@ -380,9 +384,7 @@ int replay_revisions(struct rev_info *revs,
380384
khint_t pos;
381385
int hr;
382386

383-
if (!commit->parents)
384-
die(_("replaying down from root commit is not supported yet!"));
385-
if (commit->parents->next)
387+
if (commit->parents && commit->parents->next)
386388
die(_("replaying merge commits is not supported yet!"));
387389

388390
last_commit = pick_regular_commit(revs->repo, commit, replayed_commits,

t/t3650-replay-basics.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,13 @@ test_expect_success 'exactly one of --onto, --advance, or --revert is required'
8181
test_cmp expect actual
8282
'
8383

84-
test_expect_success 'no base or negative ref gives no-replaying down to root error' '
85-
echo "fatal: replaying down from root commit is not supported yet!" >expect &&
86-
test_must_fail git replay --onto=topic1 topic2 2>actual &&
84+
test_expect_success 'replay down to root onto another branch' '
85+
git replay --ref-action=print --onto main topic2 >result &&
86+
87+
test_line_count = 1 result &&
88+
89+
git log --format=%s $(cut -f 3 -d " " result) >actual &&
90+
test_write_lines E D C M L B A >expect &&
8791
test_cmp expect actual
8892
'
8993

0 commit comments

Comments
 (0)