Skip to content

Commit e1165dd

Browse files
committed
Merge branch 'jl/maint-diff-ignore-submodules'
* jl/maint-diff-ignore-submodules: t4027,4041: Use test -s to test for an empty file Add optional parameters to the diff option "--ignore-submodules" git diff: rename test that had a conflicting name
2 parents c9eaaab + 6ed7dda commit e1165dd

File tree

5 files changed

+116
-5
lines changed

5 files changed

+116
-5
lines changed

Documentation/diff-options.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,14 @@ endif::git-format-patch[]
328328
--no-ext-diff::
329329
Disallow external diff drivers.
330330

331-
--ignore-submodules::
332-
Ignore changes to submodules in the diff generation.
331+
--ignore-submodules[=<when>]::
332+
Ignore changes to submodules in the diff generation. <when> can be
333+
either "untracked", "dirty" or "all", which is the default. When
334+
"untracked" is used submodules are not considered dirty when they only
335+
contain untracked content (but they are still scanned for modified
336+
content). Using "dirty" ignores all changes to the work tree of submodules,
337+
only changes to the commits stored in the superproject are shown (this was
338+
the behavior until 1.7.0). Using "all" hides all changes to submodules.
333339

334340
--src-prefix=<prefix>::
335341
Show the given source prefix instead of "a/".

diff-lib.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ static int match_stat_with_submodule(struct diff_options *diffopt,
7070
int changed = ce_match_stat(ce, st, ce_option);
7171
if (S_ISGITLINK(ce->ce_mode)
7272
&& !DIFF_OPT_TST(diffopt, IGNORE_SUBMODULES)
73+
&& !DIFF_OPT_TST(diffopt, IGNORE_DIRTY_SUBMODULES)
7374
&& (!changed || DIFF_OPT_TST(diffopt, DIRTY_SUBMODULES))) {
7475
*dirty_submodule = is_submodule_modified(ce->name, DIFF_OPT_TST(diffopt, IGNORE_UNTRACKED_IN_SUBMODULES));
7576
}

diff.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3169,7 +3169,16 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
31693169
DIFF_OPT_CLR(options, ALLOW_TEXTCONV);
31703170
else if (!strcmp(arg, "--ignore-submodules"))
31713171
DIFF_OPT_SET(options, IGNORE_SUBMODULES);
3172-
else if (!strcmp(arg, "--submodule"))
3172+
else if (!prefixcmp(arg, "--ignore-submodules=")) {
3173+
if (!strcmp(arg + 20, "all"))
3174+
DIFF_OPT_SET(options, IGNORE_SUBMODULES);
3175+
else if (!strcmp(arg + 20, "untracked"))
3176+
DIFF_OPT_SET(options, IGNORE_UNTRACKED_IN_SUBMODULES);
3177+
else if (!strcmp(arg + 20, "dirty"))
3178+
DIFF_OPT_SET(options, IGNORE_DIRTY_SUBMODULES);
3179+
else
3180+
die("bad --ignore-submodules argument: %s", arg + 20);
3181+
} else if (!strcmp(arg, "--submodule"))
31733182
DIFF_OPT_SET(options, SUBMODULE_LOG);
31743183
else if (!prefixcmp(arg, "--submodule=")) {
31753184
if (!strcmp(arg + 12, "log"))

t/t4027-diff-submodule.sh

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,15 @@ test_expect_success 'git diff HEAD with dirty submodule (work tree, refs match)'
103103
git diff HEAD >actual &&
104104
sed -e "1,/^@@/d" actual >actual.body &&
105105
expect_from_to >expect.body $subprev $subprev-dirty &&
106-
test_cmp expect.body actual.body
106+
test_cmp expect.body actual.body &&
107+
git diff --ignore-submodules HEAD >actual2 &&
108+
! test -s actual2 &&
109+
git diff --ignore-submodules=untracked HEAD >actual3 &&
110+
sed -e "1,/^@@/d" actual3 >actual3.body &&
111+
expect_from_to >expect.body $subprev $subprev-dirty &&
112+
test_cmp expect.body actual3.body &&
113+
git diff --ignore-submodules=dirty HEAD >actual4 &&
114+
! test -s actual4
107115
'
108116

109117
test_expect_success 'git diff HEAD with dirty submodule (index, refs match)' '
@@ -129,7 +137,13 @@ test_expect_success 'git diff HEAD with dirty submodule (untracked, refs match)'
129137
git diff HEAD >actual &&
130138
sed -e "1,/^@@/d" actual >actual.body &&
131139
expect_from_to >expect.body $subprev $subprev-dirty &&
132-
test_cmp expect.body actual.body
140+
test_cmp expect.body actual.body &&
141+
git diff --ignore-submodules=all HEAD >actual2 &&
142+
! test -s actual2 &&
143+
git diff --ignore-submodules=untracked HEAD >actual3 &&
144+
! test -s actual3 &&
145+
git diff --ignore-submodules=dirty HEAD >actual4 &&
146+
! test -s actual4
133147
'
134148

135149
test_expect_success 'git diff (empty submodule dir)' '

t/t4041-diff-submodule.sh renamed to t/t4041-diff-submodule-option.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,21 @@ Submodule sm1 contains untracked content
205205
EOF
206206
"
207207

208+
test_expect_success 'submodule contains untracked content (untracked ignored)' "
209+
git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
210+
! test -s actual
211+
"
212+
213+
test_expect_success 'submodule contains untracked content (dirty ignored)' "
214+
git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
215+
! test -s actual
216+
"
217+
218+
test_expect_success 'submodule contains untracked content (all ignored)' "
219+
git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
220+
! test -s actual
221+
"
222+
208223
test_expect_success 'submodule contains untracked and modifed content' "
209224
echo new > sm1/foo6 &&
210225
git diff-index -p --submodule=log HEAD >actual &&
@@ -214,6 +229,26 @@ Submodule sm1 contains modified content
214229
EOF
215230
"
216231

232+
test_expect_success 'submodule contains untracked and modifed content (untracked ignored)' "
233+
echo new > sm1/foo6 &&
234+
git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
235+
diff actual - <<-EOF
236+
Submodule sm1 contains modified content
237+
EOF
238+
"
239+
240+
test_expect_success 'submodule contains untracked and modifed content (dirty ignored)' "
241+
echo new > sm1/foo6 &&
242+
git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
243+
! test -s actual
244+
"
245+
246+
test_expect_success 'submodule contains untracked and modifed content (all ignored)' "
247+
echo new > sm1/foo6 &&
248+
git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
249+
! test -s actual
250+
"
251+
217252
test_expect_success 'submodule contains modifed content' "
218253
rm -f sm1/new-file &&
219254
git diff-index -p --submodule=log HEAD >actual &&
@@ -242,6 +277,27 @@ Submodule sm1 $head6..$head8:
242277
EOF
243278
"
244279

280+
test_expect_success 'modified submodule contains untracked content (untracked ignored)' "
281+
git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
282+
diff actual - <<-EOF
283+
Submodule sm1 $head6..$head8:
284+
> change
285+
EOF
286+
"
287+
288+
test_expect_success 'modified submodule contains untracked content (dirty ignored)' "
289+
git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
290+
diff actual - <<-EOF
291+
Submodule sm1 $head6..$head8:
292+
> change
293+
EOF
294+
"
295+
296+
test_expect_success 'modified submodule contains untracked content (all ignored)' "
297+
git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
298+
! test -s actual
299+
"
300+
245301
test_expect_success 'modified submodule contains untracked and modifed content' "
246302
echo modification >> sm1/foo6 &&
247303
git diff-index -p --submodule=log HEAD >actual &&
@@ -253,6 +309,31 @@ Submodule sm1 $head6..$head8:
253309
EOF
254310
"
255311

312+
test_expect_success 'modified submodule contains untracked and modifed content (untracked ignored)' "
313+
echo modification >> sm1/foo6 &&
314+
git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
315+
diff actual - <<-EOF
316+
Submodule sm1 contains modified content
317+
Submodule sm1 $head6..$head8:
318+
> change
319+
EOF
320+
"
321+
322+
test_expect_success 'modified submodule contains untracked and modifed content (dirty ignored)' "
323+
echo modification >> sm1/foo6 &&
324+
git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
325+
diff actual - <<-EOF
326+
Submodule sm1 $head6..$head8:
327+
> change
328+
EOF
329+
"
330+
331+
test_expect_success 'modified submodule contains untracked and modifed content (all ignored)' "
332+
echo modification >> sm1/foo6 &&
333+
git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
334+
! test -s actual
335+
"
336+
256337
test_expect_success 'modified submodule contains modifed content' "
257338
rm -f sm1/new-file &&
258339
git diff-index -p --submodule=log HEAD >actual &&

0 commit comments

Comments
 (0)