Skip to content

Commit 1159185

Browse files
rscharfegitster
authored andcommitted
diff: report dirty submodules as changes in builtin_diff()
The diff machinery has two ways to detect changes to set the exit code: Just comparing hashes and comparing blob contents. The latter is needed if certain changes have to be ignored, e.g. with --ignore-space-change or --ignore-matching-lines. It's enabled by the diff_options flag diff_from_contents. The slower mode as never considered submodules (and subrepos) as changes with --submodule=diff or --submodule=log, which is inconsistent with --submodule=short (the default). Fix it. d7b97b7 (diff: let external diffs report that changes are uninteresting, 2024-06-09) set diff_from_contents if external diff programs are allowed. This is the default e.g. for git diff, and so that change exposed the inconsistency much more widely. Reported-by: David Hull <[email protected]> Signed-off-by: René Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 87cf960 commit 1159185

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

diff.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3565,6 +3565,7 @@ static void builtin_diff(const char *name_a,
35653565
show_submodule_diff_summary(o, one->path ? one->path : two->path,
35663566
&one->oid, &two->oid,
35673567
two->dirty_submodule);
3568+
o->found_changes = 1;
35683569
return;
35693570
} else if (o->submodule_format == DIFF_SUBMODULE_INLINE_DIFF &&
35703571
(!one->mode || S_ISGITLINK(one->mode)) &&
@@ -3573,6 +3574,7 @@ static void builtin_diff(const char *name_a,
35733574
show_submodule_inline_diff(o, one->path ? one->path : two->path,
35743575
&one->oid, &two->oid,
35753576
two->dirty_submodule);
3577+
o->found_changes = 1;
35763578
return;
35773579
}
35783580

t/t4017-diff-retval.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,25 @@ do
159159
"
160160
done
161161

162+
test_expect_success 'setup dirty subrepo' '
163+
git reset --hard &&
164+
test_create_repo subrepo &&
165+
test_commit -C subrepo subrepo-file &&
166+
test_tick &&
167+
git add subrepo &&
168+
git commit -m subrepo &&
169+
test_commit -C subrepo another-subrepo-file
170+
'
171+
172+
for option in --exit-code --quiet
173+
do
174+
for submodule_format in diff log short
175+
do
176+
opts="$option --submodule=$submodule_format" &&
177+
test_expect_success "git diff $opts returns 1 for dirty subrepo" "
178+
test_expect_code 1 git diff $opts
179+
"
180+
done
181+
done
182+
162183
test_done

0 commit comments

Comments
 (0)