[PATCH 1/4] object-name: do not read a peel suffix as a reflog selector
- From
- Caspar Duregger <caspar.duregger@gmail.com>
- Date
- Nov 13, 2026, 14:28 UTC
- Message-ID
- <20261113142804.7465-2-caspar.duregger@gmail.com>
- In-Reply-To
- <20260212040708.GA1894049@coredump.intra.peff.net>
To find a "@{...}" reflog selector, get_oid_basic() checks that the name ends in '}' and then takes the last "@{" in it.
For "HEAD@{1}^{blob}" the final '}' closes "^{blob}", nevertheless we take "1}^{blob" as the selector. That is not a number, so it goes to approxidate_careful(), which accepts it without complaint as "now". The name then resolves to the current value of HEAD.
We only parse the whole string like this after peel_onion() has failed, so a peel that should fail succeeds with the wrong object:
$ git rev-parse --verify 'HEAD@{1}^{/no-such-subject}'
<object name of HEAD>Only accept a selector whose "@{" is closed by the final '}'. Reflog selectors never contain a '}', so no valid selector is rejected.
Signed-off-by: Caspar Duregger <caspar.duregger@gmail.com> --- object-name.c | 6 ++++++ t/t1508-at-combinations.sh | 4 ++++ 2 files changed, 10 insertions(+)
diff --git a/object-name.c b/object-name.c index 6546685760..13e4dc0f21 100644 --- a/object-name.c +++ b/object-name.c @@ -712,6 +712,12 @@ static int get_oid_basic(struct repository *r, const char *str, int len, nth_prior = 1; continue; } + /* + * The final '}' must close this "@{", not a + * later suffix as in "ref@{1}^{tree}". + */ + if (memchr(str + at + 2, '}', len - at - 3)) + break; if (!upstream_mark(str + at, len - at) && !push_mark(str + at, len - at)) { reflog_len = (len-1) - (at+2); diff --git a/t/t1508-at-combinations.sh b/t/t1508-at-combinations.sh index 87a4286414..10a8c3ad9d 100755 --- a/t/t1508-at-combinations.sh +++ b/t/t1508-at-combinations.sh @@ -84,6 +84,10 @@ nonsense "@{-1}@{-1}" check "HEAD@{3}" commit old-two nonsense "@{3}" +# a failed peel must not be retried as a reflog date +nonsense "HEAD@{1}^{blob}" +nonsense "@{1}^{/no-such-subject}" + test_expect_success 'switch to old-branch' ' git checkout old-branch '
-- 2.56.1.windows.1