[PATCH 0/3] builtin/grep: fix reading objects from wrong repository
- From
Patrick Steinhardt <ps@pks.im>
- Date
- Oct 30, 2026, 10:21 UTC
- Message-ID
- <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.
Thanks!
Patrick
[1]: <CAMtVYEjWd2XwJpXdk3PV2jbNdoOaqS3x+08EMu5byy55RxfRmA@mail.gmail.com>
---
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 repositorybuiltin/grep.c | 6 +++--- t/t7814-grep-recurse-submodules.sh | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-)
--- base-commit: a018953688f1b10bddf91bff8747068f5f4746a4 change-id: 20261030-pks-grep-recurse-submodule-20177cc7794c