replay: find *onto only after testing for ref name
We are about to make `peel_committish` die when it cannot find a commit-ish instead of returning `NULL`. But that would make e.g. `git replay --advance=refs/non-existent` die with a less descriptive error message; the highest-level error message is that the name does not exist as a ref, not that we cannot find a commit-ish based on the name. Let’s try to find the ref and only after that try to peel to as a commit-ish. Also add a regression test to protect this error order from future modifications. Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Kristoffer Haugsbakk <code@khaugsbakk.name> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Kristoffer Haugsbakk committed
Jan 5, 2026 at 20:53 UTC
17b7965a03bd38215cb78ae1c4b9646d0ee73a40
2 files changed
+8
-1
builtin/replay.c
+1
-1
@@ -192,7 +192,6 @@ static void set_up_replay_mode(struct repository *repo,
192
if (!*advance_name)
193
BUG("expected either onto_name or *advance_name in this function");
194
195
- *onto = peel_committish(repo, *advance_name);
195
if (repo_dwim_ref(repo, *advance_name, strlen(*advance_name),
196
&oid, &fullname, 0) == 1) {
197
free(*advance_name);
@@ -200,6 +199,7 @@ static void set_up_replay_mode(struct repository *repo,
199
} else {
200
die(_("argument to --advance must be a reference"));
201
}
202
+ *onto = peel_committish(repo, *advance_name);
203
if (rinfo.positive_refexprs > 1)
204
die(_("cannot advance target with multiple sources because ordering would be ill-defined"));
205
}
t/t3650-replay-basics.sh
+7
@@ -51,6 +51,13 @@ test_expect_success 'setup bare' '
51
git clone --bare . bare
52
'
53
54
+test_expect_success 'argument to --advance must be a reference' '
55
+ echo "fatal: argument to --advance must be a reference" >expect &&
56
+ oid=$(git rev-parse main) &&
57
+ test_must_fail git replay --advance=$oid topic1..topic2 2>actual &&
58
+ test_cmp expect actual
59
+'
60
+
61
test_expect_success 'using replay to rebase two branches, one on top of other' '
62
git replay --ref-action=print --onto main topic1..topic2 >result &&
63