aboutsummaryrefslogtreecommitdiff
path: root/diff.c
diff options
context:
space:
mode:
authorMichael Montalbo <mmontalbo@gmail.com>2026-02-28 20:31:16 +0000
committerJunio C Hamano <gitster@pobox.com>2026-03-02 08:29:48 -0800
commitb0ddc7947cc6f0a077543204a96710c53daa48a5 (patch)
treea75361ee03fc41ba6215da67dc284252629ca5d3 /diff.c
parentf368df439b31b422169975cc3c95f7db6a46eada (diff)
downloadgit-b0ddc7947cc6f0a077543204a96710c53daa48a5.tar.xz
diff: fix crash with --find-object outside repository
When "git diff --find-object=<oid>" is run outside a git repository, the option parsing callback eagerly resolves the OID via repo_get_oid(), which reaches get_main_ref_store() and hits a BUG() assertion because no repository has been set up. Check startup_info->have_repository before attempting to resolve the OID, and return a user-friendly error instead. Signed-off-by: Michael Montalbo <mmontalbo@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'diff.c')
-rw-r--r--diff.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/diff.c b/diff.c
index 90e8003dd1..fd9aedbec7 100644
--- a/diff.c
+++ b/diff.c
@@ -5139,6 +5139,8 @@ static int diff_opt_find_object(const struct option *option,
struct object_id oid;
BUG_ON_OPT_NEG(unset);
+ if (!startup_info->have_repository)
+ return error(_("--find-object requires a git repository"));
if (repo_get_oid(the_repository, arg, &oid))
return error(_("unable to resolve '%s'"), arg);