From: Patrick Steinhardt Date: Thu, 12 Feb 2026 12:44:35 GMT Subject: [PATCH 2/4] builtin/history: check for merges before asking for user input Message-ID: <20260212-b4-pks-history-dry-run-v1-2-1ce03d631c1b@pks.im> In-Reply-To: <20260212-b4-pks-history-dry-run-v1-0-1ce03d631c1b@pks.im> The replay infrastructure is not yet capable of replaying merge commits. Unfortunately, we only notice that we're about to replay merges after we have already asked the user for input, so any commit message that the user may have written will be discarded in that case. Fix this by checking whether the revwalk contains merge commits before we ask for user input. Signed-off-by: Patrick Steinhardt --- builtin/history.c | 40 ++++++++++++++++++++++++++++++++++++++++ t/t3451-history-reword.sh | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/builtin/history.c b/builtin/history.c index 1de51372ea..ca0cdb6a58 100644 --- a/builtin/history.c +++ b/builtin/history.c @@ -177,6 +177,42 @@ static int parse_ref_action(const struct option *opt, const char *value, int uns return 0; } +static int revwalk_contains_merges(struct repository *repo, + const struct strvec *revwalk_args) +{ + struct strvec args = STRVEC_INIT; + struct rev_info revs; + int ret; + + for (size_t i = 0; i < revwalk_args->nr; i++) + strvec_push(&args, revwalk_args->v[i]); + strvec_push(&args, "--min-parents=2"); + + repo_init_revisions(repo, &revs, NULL); + + setup_revisions_from_strvec(&args, &revs, NULL); + if (args.nr != 1) + BUG("revisions were set up with invalid argument"); + + if (prepare_revision_walk(&revs) < 0) { + ret = error(_("error preparing revisions")); + goto out; + } + + if (get_revision(&revs)) { + ret = error(_("replaying merge commits is not supported yet!")); + goto out; + } + + reset_revision_walk(); + ret = 0; + +out: + release_revisions(&revs); + strvec_clear(&args); + return ret; +} + static int setup_revwalk(struct repository *repo, enum ref_action action, struct commit *original, @@ -236,6 +272,10 @@ static int setup_revwalk(struct repository *repo, strvec_push(&args, "HEAD"); } + ret = revwalk_contains_merges(repo, &args); + if (ret < 0) + goto out; + setup_revisions_from_strvec(&args, revs, NULL); if (args.nr != 1) BUG("revisions were set up with invalid argument"); diff --git a/t/t3451-history-reword.sh b/t/t3451-history-reword.sh index 6775ed62f9..12a9a7d051 100755 --- a/t/t3451-history-reword.sh +++ b/t/t3451-history-reword.sh @@ -203,7 +203,7 @@ test_expect_success 'can reword a merge commit' ' # It is not possible to replay merge commits embedded in the # history (yet). - test_must_fail git history reword HEAD~ 2>err && + test_must_fail git -c core.editor=false history reword HEAD~ 2>err && test_grep "replaying merge commits is not supported yet" err && # But it is possible to reword a merge commit directly. -- 2.53.0.295.g64333814d3.dirty