Skip to content

Commit 17b7965

Browse files
LemmingAvalanchegitster
authored andcommitted
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>
1 parent 76eab50 commit 17b7965

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

builtin/replay.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,14 @@ static void set_up_replay_mode(struct repository *repo,
192192
if (!*advance_name)
193193
BUG("expected either onto_name or *advance_name in this function");
194194

195-
*onto = peel_committish(repo, *advance_name);
196195
if (repo_dwim_ref(repo, *advance_name, strlen(*advance_name),
197196
&oid, &fullname, 0) == 1) {
198197
free(*advance_name);
199198
*advance_name = fullname;
200199
} else {
201200
die(_("argument to --advance must be a reference"));
202201
}
202+
*onto = peel_committish(repo, *advance_name);
203203
if (rinfo.positive_refexprs > 1)
204204
die(_("cannot advance target with multiple sources because ordering would be ill-defined"));
205205
}

t/t3650-replay-basics.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ test_expect_success 'setup bare' '
5151
git clone --bare . bare
5252
'
5353

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+
5461
test_expect_success 'using replay to rebase two branches, one on top of other' '
5562
git replay --ref-action=print --onto main topic1..topic2 >result &&
5663

0 commit comments

Comments
 (0)