Merge branch 'mm/diff-no-index-find-object' into next

"git diff --no-index --find-object=<object-name>" outside a
repository of course wouldn't be able to find the object and died
while parsing the command line, which is made to die in a bit more
user-friendly way.

* mm/diff-no-index-find-object:
  diff: fix crash with --find-object outside repository
This commit is contained in:
Junio C Hamano
2026-03-03 13:41:21 -08:00
2 changed files with 12 additions and 0 deletions

2
diff.c
View File

@@ -5224,6 +5224,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);

View File

@@ -76,6 +76,16 @@ test_expect_success 'git diff --no-index executed outside repo gives correct err
)
'
test_expect_success 'git diff --find-object outside repo fails gracefully' '
(
GIT_CEILING_DIRECTORIES=$TRASH_DIRECTORY/non &&
export GIT_CEILING_DIRECTORIES &&
cd non/git &&
test_must_fail git diff --find-object=abc123 2>err &&
test_grep "find-object requires a git repository" err
)
'
test_expect_success 'diff D F and diff F D' '
(
cd repo &&