aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2026-03-10 14:23:22 -0700
committerJunio C Hamano <gitster@pobox.com>2026-03-10 14:23:22 -0700
commit015cf12578691d77638c7b99f27c15f4d73446e4 (patch)
tree17a9dd45b8344ac985b008a1a7f037e7d0b7fb24
parent0f34e8c17441685159c5c0ea5b742bd8257e10ce (diff)
parentb0ddc7947cc6f0a077543204a96710c53daa48a5 (diff)
downloadgit-015cf12578691d77638c7b99f27c15f4d73446e4.tar.xz
Merge branch 'mm/diff-no-index-find-object'
"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
-rw-r--r--diff.c2
-rwxr-xr-xt/t4053-diff-no-index.sh10
2 files changed, 12 insertions, 0 deletions
diff --git a/diff.c b/diff.c
index da6e9e7f49..e87847fa4b 100644
--- a/diff.c
+++ b/diff.c
@@ -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);
diff --git a/t/t4053-diff-no-index.sh b/t/t4053-diff-no-index.sh
index 69599279e9..15076dfe0d 100755
--- a/t/t4053-diff-no-index.sh
+++ b/t/t4053-diff-no-index.sh
@@ -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 &&