From: Toon Claes <toon@iotcl.com>
To: git@vger.kernel.org
Cc: Toon Claes <toon@iotcl.com>
Subject: [PATCH] replay: support replaying down from root commit
Date: Tue, 17 Mar 2026 19:56:26 +0100 [thread overview]
Message-ID: <20260317-toon-replay-down-to-root-v1-1-cb5c249e15fd@iotcl.com> (raw)
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>
---
These changes might conflict Siddharth's series[1] to add '--revert' to
git-replay(1), although resolving that should be trivial.
[1]: https://lore.kernel.org/git/20260313054035.26605-1-siddharthasthana31@gmail.com/
---
replay.c | 18 ++++++++++--------
t/t3650-replay-basics.sh | 10 +++++++---
2 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/replay.c b/replay.c
index a63f6714c4..63ff56552e 100644
--- a/replay.c
+++ b/replay.c
@@ -225,12 +225,18 @@ static struct commit *pick_regular_commit(struct repository *repo,
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;
+ replayed_base = mapped_commit(replayed_commits, base, onto);
+ base_tree = repo_get_commit_tree(repo, base);
+ } else {
+ base = NULL;
+ replayed_base = onto;
+ base_tree = lookup_tree(repo, repo->hash_algo->empty_tree);
+ }
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);
@@ -293,8 +299,6 @@ int replay_revisions(struct rev_info *revs,
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;
@@ -309,9 +313,7 @@ int replay_revisions(struct rev_info *revs,
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,
diff --git a/t/t3650-replay-basics.sh b/t/t3650-replay-basics.sh
index a03f8f9293..9c55b62757 100755
--- a/t/t3650-replay-basics.sh
+++ b/t/t3650-replay-basics.sh
@@ -81,9 +81,13 @@ test_expect_success 'option --onto or --advance is mandatory' '
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
'
---
base-commit: ca1db8a0f7dc0dbea892e99f5b37c5fe5861be71
change-id: 20260317-toon-replay-down-to-root-d412048f1741
next reply other threads:[~2026-03-17 18:57 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-17 18:56 Toon Claes [this message]
2026-03-17 19:59 ` [PATCH] replay: support replaying down from root commit Junio C Hamano
2026-03-24 17:25 ` Toon Claes
2026-03-24 19:35 ` [PATCH v2] " Toon Claes
2026-03-24 19:53 ` Junio C Hamano
2026-03-25 10:00 ` Christian Couder
2026-03-25 12:19 ` Ben Knoble
2026-03-25 15:35 ` Make git-replay(1) warn if revision-range isn't a range (was: Re: [PATCH v2] replay: support replaying down from root commit) Toon Claes
2026-03-25 15:32 ` [PATCH v2] replay: support replaying down from root commit Toon Claes
2026-03-25 15:37 ` Toon Claes
2026-03-27 16:45 ` Junio C Hamano
2026-03-31 10:34 ` Christian Couder
2026-03-31 16:20 ` Junio C Hamano
2026-04-02 9:08 ` Toon Claes
2026-04-02 17:02 ` Junio C Hamano
2026-04-03 6:49 ` Christian Couder
2026-03-25 16:49 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260317-toon-replay-down-to-root-v1-1-cb5c249e15fd@iotcl.com \
--to=toon@iotcl.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).