git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 4/4] cat-file: report out-of-range reflog entries as missing

From
CDCaspar Duregger <caspar.duregger@gmail.com>
Date
Nov 13, 2026, 14:28 UTC
Message-ID
<20261113142804.7465-5-caspar.duregger@gmail.com>
In-Reply-To
<20260212040708.GA1894049@coredump.intra.peff.net>

The batch modes of "git cat-file" report a name that does not resolve as "missing" and go on with the next line. A reflog selector past the end of the reflog is an exception: get_oid_basic() dies, and takes the batch process and any requests queued behind it down with it:

    $ printf 'HEAD@{999999}\nHEAD\n' | git cat-file --batch-check
    fatal: log for 'HEAD' only has 3 entries

Pass GET_OID_GENTLY so that these lookups fail like any other. The previous commits make sure that this changes only lookups that would have died: selectors at the boundary or by date still resolve, an emptied reflog fails gently as well, and a peel suffix after the selector cannot resurrect the name through the reflog date parser.

Not every die() on the way is covered. "HEAD@{999999}~1" still dies, as get_parent() and get_nth_ancestor() do not pass the caller's flags down, and so does "@{upstream}" on a detached HEAD.

Reported-by: Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>
Signed-off-by: Caspar Duregger <caspar.duregger@gmail.com>
---
 builtin/cat-file.c  |  1 +
 t/t1006-cat-file.sh | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 8870a210ec..56dea8eb80 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -627,6 +627,7 @@ static void batch_one_object(const char *obj_name,
 	struct object_context ctx = {0};
 	int flags =
 		GET_OID_HASH_ANY |
+		GET_OID_GENTLY |
 		(opt->follow_symlinks ? GET_OID_FOLLOW_SYMLINKS : 0);
 	enum get_oid_result result;
 
diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh
index f2b24dd278..5fe2b4ad14 100755
--- a/t/t1006-cat-file.sh
+++ b/t/t1006-cat-file.sh
@@ -451,6 +451,41 @@ test_expect_success 'empty --batch-check notices missing object' '
 	test_cmp expect actual
 '
 
+test_expect_success '--batch-check reports reflog entries out of range as missing' '
+	test_when_finished "rm -rf reflog-range" &&
+	git init reflog-range &&
+	(
+		cd reflog-range &&
+		test_commit one &&
+		test_commit two &&
+		test_commit three &&
+		# keep a non-null "old" side in the oldest entry
+		git reflog delete HEAD@{2} &&
+		git branch empty &&
+		git reflog expire --expire=all refs/heads/empty &&
+		cat >in <<-\EOF &&
+		HEAD@{2}
+		HEAD@{1970-01-02}
+		HEAD@{3}
+		HEAD@{999999}^{tree}
+		HEAD@{999999}:one.t
+		empty@{1}
+		HEAD
+		EOF
+		cat >expect <<-EOF &&
+		$(git rev-parse one)
+		$(git rev-parse one)
+		HEAD@{3} missing
+		HEAD@{999999}^{tree} missing
+		HEAD@{999999}:one.t missing
+		empty@{1} missing
+		$(git rev-parse three)
+		EOF
+		git cat-file --batch-check="%(objectname)" <in >actual &&
+		test_cmp expect actual
+	)
+'
+
 batch_tests () {
     boid=$1
     loid=$2
-- 
2.56.1.windows.1
Previous: Caspar Duregger
Message 8 of 8 in “cat-file: dies with --batch if reflog entry is out of bounds”
  1. Kristoffer HaugsbakkFeb 11, 2026
  2. Junio C HamanoFeb 11, 2026
  3. Jeff KingFeb 12, 2026
  4. 0/4 cat-file: do not die on reflog entries out of rangeCaspar Duregger, Nov 13, 2026
  5. 1/4 object-name: do not read a peel suffix as a reflog selectorCaspar Duregger, Nov 13, 2026
  6. 2/4 object-name: let GET_OID_GENTLY affect only failing lookupsCaspar Duregger, Nov 13, 2026
  7. 3/4 refs: let read_ref_at() fail gently on an empty reflogCaspar Duregger, Nov 13, 2026
  8. 4/4 cat-file: report out-of-range reflog entries as missingCaspar Duregger, Nov 13, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.