Skip to content

Commit 2854395

Browse files
To1negitster
authored andcommitted
replay: support replaying down from root commit
git-replay(1) doesn't allow replaying commits all the way down to the root commit. Fix that. Signed-off-by: Toon Claes <toon@iotcl.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent ca1db8a commit 2854395

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

replay.c

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

228-
base = pickme->parents->item;
229-
replayed_base = mapped_commit(replayed_commits, base, onto);
228+
if (pickme->parents) {
229+
base = pickme->parents->item;
230+
replayed_base = mapped_commit(replayed_commits, base, onto);
231+
base_tree = repo_get_commit_tree(repo, base);
232+
} else {
233+
base = NULL;
234+
replayed_base = onto;
235+
base_tree = lookup_tree(repo, repo->hash_algo->empty_tree);
236+
}
230237

231238
replayed_base_tree = repo_get_commit_tree(repo, replayed_base);
232239
pickme_tree = repo_get_commit_tree(repo, pickme);
233-
base_tree = repo_get_commit_tree(repo, base);
234240

235241
merge_opt->branch1 = short_commit_name(repo, replayed_base);
236242
merge_opt->branch2 = short_commit_name(repo, pickme);
@@ -293,8 +299,6 @@ int replay_revisions(struct rev_info *revs,
293299
set_up_replay_mode(revs->repo, &revs->cmdline, opts->onto,
294300
&detached_head, &advance, &onto, &update_refs);
295301

296-
/* FIXME: Should allow replaying commits with the first as a root commit */
297-
298302
if (prepare_revision_walk(revs) < 0) {
299303
ret = error(_("error preparing revisions"));
300304
goto out;
@@ -309,9 +313,7 @@ int replay_revisions(struct rev_info *revs,
309313
khint_t pos;
310314
int hr;
311315

312-
if (!commit->parents)
313-
die(_("replaying down from root commit is not supported yet!"));
314-
if (commit->parents->next)
316+
if (commit->parents && commit->parents->next)
315317
die(_("replaying merge commits is not supported yet!"));
316318

317319
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 'option --onto or --advance is mandatory' '
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)