3 # Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
4 # Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests)
7 test_description
='Support for verbose submodule differences in git diff
9 This test tries to verify the sanity of the --submodule option of git diff.
12 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
13 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
15 TEST_PASSES_SANITIZE_LEAK
=true
18 # Test non-UTF-8 encoding in case iconv is available.
19 if test_have_prereq ICONV
21 test_encoding
="ISO8859-1"
22 # String "added" in German (translated with Google Translate), encoded in UTF-8,
23 # used in sample commit log messages in add_file() function below.
24 added
=$
(printf "hinzugef\303\274gt")
36 echo "$name" >"$name" &&
39 # "git commit -m" would break MinGW, as Windows refuse to pass
40 # $test_encoding encoded parameter to git.
41 echo "Add $name ($added $name)" |
iconv -f utf-8
-t $test_encoding |
42 git
-c "i18n.commitEncoding=$test_encoding" commit
-F -
44 git rev-parse
--short --verify HEAD
49 git commit
"$@" -m "Commit $*" >/dev
/null
52 test_create_repo sm1
&&
53 add_file . foo
>/dev
/null
55 head1
=$
(add_file sm1 foo1 foo2
)
56 fullhead1
=$
(cd sm1
; git rev-parse
--verify HEAD
)
58 test_expect_success
'added submodule' '
60 git diff-index -p --submodule=log HEAD >actual &&
61 cat >expected <<-EOF &&
62 Submodule sm1 0000000...$head1 (new submodule)
64 test_cmp expected actual
67 test_expect_success
'added submodule, set diff.submodule' '
68 git config diff.submodule log &&
70 git diff --cached >actual &&
71 cat >expected <<-EOF &&
72 Submodule sm1 0000000...$head1 (new submodule)
74 git config --unset diff.submodule &&
75 test_cmp expected actual
78 test_expect_success
'--submodule=short overrides diff.submodule' '
79 test_config diff.submodule log &&
81 git diff --submodule=short --cached >actual &&
82 cat >expected <<-EOF &&
83 diff --git a/sm1 b/sm1
89 +Subproject commit $fullhead1
91 test_cmp expected actual
94 test_expect_success
'diff.submodule does not affect plumbing' '
95 test_config diff.submodule log &&
96 git diff-index -p HEAD >actual &&
97 cat >expected <<-EOF &&
98 diff --git a/sm1 b/sm1
100 index 0000000..$head1
104 +Subproject commit $fullhead1
106 test_cmp expected actual
110 head2
=$
(add_file sm1 foo3
)
112 test_expect_success
'modified submodule(forward)' '
113 git diff-index -p --submodule=log HEAD >actual &&
114 cat >expected <<-EOF &&
115 Submodule sm1 $head1..$head2:
116 > Add foo3 ($added foo3)
118 test_cmp expected actual
121 test_expect_success
'modified submodule(forward)' '
122 git diff --submodule=log >actual &&
123 cat >expected <<-EOF &&
124 Submodule sm1 $head1..$head2:
125 > Add foo3 ($added foo3)
127 test_cmp expected actual
130 test_expect_success
'modified submodule(forward) --submodule' '
131 git diff --submodule >actual &&
132 cat >expected <<-EOF &&
133 Submodule sm1 $head1..$head2:
134 > Add foo3 ($added foo3)
136 test_cmp expected actual
139 fullhead2
=$
(cd sm1
; git rev-parse
--verify HEAD
)
140 test_expect_success
'modified submodule(forward) --submodule=short' '
141 git diff --submodule=short >actual &&
142 cat >expected <<-EOF &&
143 diff --git a/sm1 b/sm1
144 index $head1..$head2 160000
148 -Subproject commit $fullhead1
149 +Subproject commit $fullhead2
151 test_cmp expected actual
157 git
reset --hard HEAD~
2 >/dev
/null
&&
158 git rev-parse
--short --verify HEAD
161 test_expect_success
'modified submodule(backward)' '
162 git diff-index -p --submodule=log HEAD >actual &&
163 cat >expected <<-EOF &&
164 Submodule sm1 $head2..$head3 (rewind):
165 < Add foo3 ($added foo3)
166 < Add foo2 ($added foo2)
168 test_cmp expected actual
171 head4
=$
(add_file sm1 foo4 foo5
)
172 test_expect_success
'modified submodule(backward and forward)' '
173 git diff-index -p --submodule=log HEAD >actual &&
174 cat >expected <<-EOF &&
175 Submodule sm1 $head2...$head4:
176 > Add foo5 ($added foo5)
177 > Add foo4 ($added foo4)
178 < Add foo3 ($added foo3)
179 < Add foo2 ($added foo2)
181 test_cmp expected actual
187 head5
=$
(git hash-object sm1 | cut
-c1-7) &&
192 test_expect_success
'typechanged submodule(submodule->blob), --cached' '
193 git diff --submodule=log --cached >actual &&
194 cat >expected <<-EOF &&
195 Submodule sm1 $head4...0000000 (submodule deleted)
196 diff --git a/sm1 b/sm1
198 index 0000000..$head5
204 test_cmp expected actual
207 test_expect_success
'typechanged submodule(submodule->blob)' '
208 git diff --submodule=log >actual &&
209 cat >expected <<-EOF &&
210 diff --git a/sm1 b/sm1
211 deleted file mode 100644
212 index $head5..0000000
217 Submodule sm1 0000000...$head4 (new submodule)
219 test_cmp expected actual
223 git checkout-index sm1
224 test_expect_success
'typechanged submodule(submodule->blob)' '
225 git diff-index -p --submodule=log HEAD >actual &&
226 cat >expected <<-EOF &&
227 Submodule sm1 $head4...0000000 (submodule deleted)
228 diff --git a/sm1 b/sm1
230 index 0000000..$head5
236 test_cmp expected actual
240 test_create_repo sm1
&&
241 head6
=$
(add_file sm1 foo6 foo7
)
242 fullhead6
=$
(cd sm1
; git rev-parse
--verify HEAD
)
243 test_expect_success
'nonexistent commit' '
244 git diff-index -p --submodule=log HEAD >actual &&
245 cat >expected <<-EOF &&
246 Submodule sm1 $head4...$head6 (commits not present)
248 test_cmp expected actual
252 test_expect_success
'typechanged submodule(blob->submodule)' '
253 git diff-index -p --submodule=log HEAD >actual &&
254 cat >expected <<-EOF &&
255 diff --git a/sm1 b/sm1
256 deleted file mode 100644
257 index $head5..0000000
262 Submodule sm1 0000000...$head6 (new submodule)
264 test_cmp expected actual
268 test_expect_success
'submodule is up to date' '
269 git diff-index -p --submodule=log HEAD >actual &&
270 test_must_be_empty actual
273 test_expect_success
'submodule contains untracked content' '
274 echo new > sm1/new-file &&
275 git diff-index -p --ignore-submodules=none --submodule=log HEAD >actual &&
276 cat >expected <<-EOF &&
277 Submodule sm1 contains untracked content
279 test_cmp expected actual
282 test_expect_success
'submodule contains untracked content (untracked ignored)' '
283 git diff-index -p --submodule=log HEAD >actual &&
284 test_must_be_empty actual
287 test_expect_success
'submodule contains untracked content (dirty ignored)' '
288 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
289 test_must_be_empty actual
292 test_expect_success
'submodule contains untracked content (all ignored)' '
293 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
294 test_must_be_empty actual
297 test_expect_success
'submodule contains untracked and modified content' '
298 echo new > sm1/foo6 &&
299 git diff-index -p --ignore-submodules=none --submodule=log HEAD >actual &&
300 cat >expected <<-EOF &&
301 Submodule sm1 contains untracked content
302 Submodule sm1 contains modified content
304 test_cmp expected actual
307 test_expect_success
'submodule contains untracked and modified content (untracked ignored)' '
308 echo new > sm1/foo6 &&
309 git diff-index -p --submodule=log HEAD >actual &&
310 cat >expected <<-EOF &&
311 Submodule sm1 contains modified content
313 test_cmp expected actual
316 test_expect_success
'submodule contains untracked and modified content (dirty ignored)' '
317 echo new > sm1/foo6 &&
318 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
319 test_must_be_empty actual
322 test_expect_success
'submodule contains untracked and modified content (all ignored)' '
323 echo new > sm1/foo6 &&
324 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
325 test_must_be_empty actual
328 test_expect_success
'submodule contains modified content' '
329 rm -f sm1/new-file &&
330 git diff-index -p --submodule=log HEAD >actual &&
331 cat >expected <<-EOF &&
332 Submodule sm1 contains modified content
334 test_cmp expected actual
337 (cd sm1
; git commit
-mchange foo6
>/dev
/null
) &&
338 head8
=$
(cd sm1
; git rev-parse
--short --verify HEAD
) &&
339 test_expect_success
'submodule is modified' '
340 git diff-index -p --submodule=log HEAD >actual &&
341 cat >expected <<-EOF &&
342 Submodule sm1 $head6..$head8:
345 test_cmp expected actual
348 test_expect_success
'modified submodule contains untracked content' '
349 echo new > sm1/new-file &&
350 git diff-index -p --ignore-submodules=none --submodule=log HEAD >actual &&
351 cat >expected <<-EOF &&
352 Submodule sm1 contains untracked content
353 Submodule sm1 $head6..$head8:
356 test_cmp expected actual
359 test_expect_success
'modified submodule contains untracked content (untracked ignored)' '
360 git diff-index -p --submodule=log HEAD >actual &&
361 cat >expected <<-EOF &&
362 Submodule sm1 $head6..$head8:
365 test_cmp expected actual
368 test_expect_success
'modified submodule contains untracked content (dirty ignored)' '
369 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
370 cat >expected <<-EOF &&
371 Submodule sm1 $head6..$head8:
374 test_cmp expected actual
377 test_expect_success
'modified submodule contains untracked content (all ignored)' '
378 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
379 test_must_be_empty actual
382 test_expect_success
'modified submodule contains untracked and modified content' '
383 echo modification >> sm1/foo6 &&
384 git diff-index -p --ignore-submodules=none --submodule=log HEAD >actual &&
385 cat >expected <<-EOF &&
386 Submodule sm1 contains untracked content
387 Submodule sm1 contains modified content
388 Submodule sm1 $head6..$head8:
391 test_cmp expected actual
394 test_expect_success
'modified submodule contains untracked and modified content (untracked ignored)' '
395 echo modification >> sm1/foo6 &&
396 git diff-index -p --submodule=log HEAD >actual &&
397 cat >expected <<-EOF &&
398 Submodule sm1 contains modified content
399 Submodule sm1 $head6..$head8:
402 test_cmp expected actual
405 test_expect_success
'modified submodule contains untracked and modified content (dirty ignored)' '
406 echo modification >> sm1/foo6 &&
407 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
408 cat >expected <<-EOF &&
409 Submodule sm1 $head6..$head8:
412 test_cmp expected actual
415 test_expect_success
'modified submodule contains untracked and modified content (all ignored)' '
416 echo modification >> sm1/foo6 &&
417 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
418 test_must_be_empty actual
421 test_expect_success
'modified submodule contains modified content' '
422 rm -f sm1/new-file &&
423 git diff-index -p --submodule=log HEAD >actual &&
424 cat >expected <<-EOF &&
425 Submodule sm1 contains modified content
426 Submodule sm1 $head6..$head8:
429 test_cmp expected actual
433 test_expect_success
'deleted submodule' '
434 git diff-index -p --submodule=log HEAD >actual &&
435 cat >expected <<-EOF &&
436 Submodule sm1 $head6...0000000 (submodule deleted)
438 test_cmp expected actual
441 test_expect_success
'create second submodule' '
442 test_create_repo sm2 &&
443 head7=$(add_file sm2 foo8 foo9) &&
447 test_expect_success
'multiple submodules' '
448 git diff-index -p --submodule=log HEAD >actual &&
449 cat >expected <<-EOF &&
450 Submodule sm1 $head6...0000000 (submodule deleted)
451 Submodule sm2 0000000...$head7 (new submodule)
453 test_cmp expected actual
456 test_expect_success
'path filter' '
457 git diff-index -p --submodule=log HEAD sm2 >actual &&
458 cat >expected <<-EOF &&
459 Submodule sm2 0000000...$head7 (new submodule)
461 test_cmp expected actual
465 test_expect_success
'given commit' '
466 git diff-index -p --submodule=log HEAD^ >actual &&
467 cat >expected <<-EOF &&
468 Submodule sm1 $head6...0000000 (submodule deleted)
469 Submodule sm2 0000000...$head7 (new submodule)
471 test_cmp expected actual
474 test_expect_success
'given commit --submodule' '
475 git diff-index -p --submodule HEAD^ >actual &&
476 cat >expected <<-EOF &&
477 Submodule sm1 $head6...0000000 (submodule deleted)
478 Submodule sm2 0000000...$head7 (new submodule)
480 test_cmp expected actual
483 fullhead7
=$
(cd sm2
; git rev-parse
--verify HEAD
)
485 test_expect_success
'given commit --submodule=short' '
486 git diff-index -p --submodule=short HEAD^ >actual &&
487 cat >expected <<-EOF &&
488 diff --git a/sm1 b/sm1
489 deleted file mode 160000
490 index $head6..0000000
494 -Subproject commit $fullhead6
495 diff --git a/sm2 b/sm2
497 index 0000000..$head7
501 +Subproject commit $fullhead7
503 test_cmp expected actual
506 test_expect_success
'setup .git file for sm2' '
508 REAL="$(pwd)/../.real" &&
510 echo "gitdir: $REAL" >.git)
513 test_expect_success
'diff --submodule with .git file' '
514 git diff --submodule HEAD^ >actual &&
515 cat >expected <<-EOF &&
516 Submodule sm1 $head6...0000000 (submodule deleted)
517 Submodule sm2 0000000...$head7 (new submodule)
519 test_cmp expected actual
522 test_expect_success
'diff --submodule with objects referenced by alternates' '
532 git clone -s ../sub_alt sub &&
535 git commit -m "sub a"
538 sha1_before=$(git rev-parse --short HEAD) &&
542 sha1_after=$(git rev-parse --short HEAD) &&
544 echo "Submodule sub $sha1_before..$sha1_after:" &&
551 git checkout origin/main
553 git diff --submodule > ../actual
555 test_cmp expected actual