Merge branch 'rs/diff-exit-code-fix' into maint-2.46

In a few corner cases "git diff --exit-code" failed to report
"changes" (e.g., renamed without any content change), which has
been corrected.

* rs/diff-exit-code-fix:
  diff: report dirty submodules as changes in builtin_diff()
  diff: report copies and renames as changes in run_diff_cmd()
This commit is contained in:
Junio C Hamano
2024-09-23 10:32:58 -07:00
2 changed files with 42 additions and 0 deletions

5
diff.c
View File

@ -3565,6 +3565,7 @@ static void builtin_diff(const char *name_a,
show_submodule_diff_summary(o, one->path ? one->path : two->path,
&one->oid, &two->oid,
two->dirty_submodule);
o->found_changes = 1;
return;
} else if (o->submodule_format == DIFF_SUBMODULE_INLINE_DIFF &&
(!one->mode || S_ISGITLINK(one->mode)) &&
@ -3573,6 +3574,7 @@ static void builtin_diff(const char *name_a,
show_submodule_inline_diff(o, one->path ? one->path : two->path,
&one->oid, &two->oid,
two->dirty_submodule);
o->found_changes = 1;
return;
}
@ -4587,6 +4589,9 @@ static void run_diff_cmd(const struct external_diff *pgm,
builtin_diff(name, other ? other : name,
one, two, xfrm_msg, must_show_header,
o, complete_rewrite);
if (p->status == DIFF_STATUS_COPIED ||
p->status == DIFF_STATUS_RENAMED)
o->found_changes = 1;
} else {
fprintf(o->file, "* Unmerged path %s\n", name);
o->found_changes = 1;

View File

@ -143,4 +143,41 @@ test_expect_success 'option errors are not confused by --exit-code' '
grep '^usage:' err
'
for option in --exit-code --quiet
do
test_expect_success "git diff $option returns 1 for copied file" "
git reset --hard &&
cp a copy &&
git add copy &&
test_expect_code 1 git diff $option --cached --find-copies-harder
"
test_expect_success "git diff $option returns 1 for renamed file" "
git reset --hard &&
git mv a renamed &&
test_expect_code 1 git diff $option --cached
"
done
test_expect_success 'setup dirty subrepo' '
git reset --hard &&
test_create_repo subrepo &&
test_commit -C subrepo subrepo-file &&
test_tick &&
git add subrepo &&
git commit -m subrepo &&
test_commit -C subrepo another-subrepo-file
'
for option in --exit-code --quiet
do
for submodule_format in diff log short
do
opts="$option --submodule=$submodule_format" &&
test_expect_success "git diff $opts returns 1 for dirty subrepo" "
test_expect_code 1 git diff $opts
"
done
done
test_done