From: Patrick Steinhardt Date: Tue, 03 Nov 2026 12:43:19 GMT Subject: [PATCH v2 0/3] builtin/grep: fix reading objects from wrong repository Message-ID: <20261103-pks-grep-recurse-submodule-v2-0-b00e3b3dc865@pks.im> In-Reply-To: <20261030-pks-grep-recurse-submodule-v1-0-d4eb5c87d8fb@pks.im> Hi, this small patch series fixes the bug reported in [1], where doing `git grep --recurse-submodules` with nested submodule trees fails to read the trees. The only patch needed here is the first one, the other patches are only belt-and-suspenders as I've been checking whether we use the wrong repository anywhere else. At the end of this patch series we only use `the_repository` in `cmd_grep()` itself. Ideally we'd adapt "builtin/grep.c" to get rid of `the_repository` altogether, but unfortunately it's a bit on the involved side as we also have to worry about the case where git-grep(1) is executed outside of a repository with "--no-index". So I skipped that refactoring for now. The patch is based on v2.56.0 so that it can be easily backported. Changes in v2: - Mention that this was released as part of Git 2.56.0. - Link to v1: https://patch.msgid.link/20261030-pks-grep-recurse-submodule-v1-0-d4eb5c87d8fb@pks.im Thanks! Patrick [1]: --- Patrick Steinhardt (3): builtin/grep: read submodule trees via their repository builtin/grep: read sparse directory trees via passed-in repository builtin/grep: read ".gitmodules" via passed-in repository builtin/grep.c | 6 +++--- t/t7814-grep-recurse-submodules.sh | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) Range-diff versus v1: 1: e9ffa0cdee5 ! 1: 46d165815b5 builtin/grep: read submodule trees via their repository @@ Commit message In the latter case we continue grepping in the submodule repository's object graph. Historically this used to work by linking that submodule's object directory into the main object database. But in 93cd344e34f - (builtin/grep: stop registering submodule ODB as source, 2026-09-11) we - stopped doing that and instead expect to read submodule objects via the - submodule repository. + (builtin/grep: stop registering submodule ODB as source, 2026-09-11), + which was released as part of Git 2.56, we stopped doing that and + instead expect to read submodule objects via the submodule repository. This logic is broken though: while we indeed know to read blobs via the submodule's object database, we didn't adapt trees in the same way. The 2: dfe45977b15 = 2: f7516e29f68 builtin/grep: read sparse directory trees via passed-in repository 3: 4b914d9d07d = 3: dc19e6589d4 builtin/grep: read ".gitmodules" via passed-in repository --- base-commit: a018953688f1b10bddf91bff8747068f5f4746a4 change-id: 20261030-pks-grep-recurse-submodule-20177cc7794c