Skip to content

Commit 015cf12

Browse files
committed
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
2 parents 0f34e8c + b0ddc79 commit 015cf12

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

diff.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5224,6 +5224,8 @@ static int diff_opt_find_object(const struct option *option,
52245224
struct object_id oid;
52255225

52265226
BUG_ON_OPT_NEG(unset);
5227+
if (!startup_info->have_repository)
5228+
return error(_("--find-object requires a git repository"));
52275229
if (repo_get_oid(the_repository, arg, &oid))
52285230
return error(_("unable to resolve '%s'"), arg);
52295231

t/t4053-diff-no-index.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ test_expect_success 'git diff --no-index executed outside repo gives correct err
7676
)
7777
'
7878

79+
test_expect_success 'git diff --find-object outside repo fails gracefully' '
80+
(
81+
GIT_CEILING_DIRECTORIES=$TRASH_DIRECTORY/non &&
82+
export GIT_CEILING_DIRECTORIES &&
83+
cd non/git &&
84+
test_must_fail git diff --find-object=abc123 2>err &&
85+
test_grep "find-object requires a git repository" err
86+
)
87+
'
88+
7989
test_expect_success 'diff D F and diff F D' '
8090
(
8191
cd repo &&

0 commit comments

Comments
 (0)