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 # Tested non-UTF-8 encoding
19 test_encoding
="ISO8859-1"
21 # String "added" in German (translated with Google Translate), encoded in UTF-8,
22 # used in sample commit log messages in add_file() function below.
23 added
=$
(printf "hinzugef\303\274gt")
30 echo "$name" >"$name" &&
33 # "git commit -m" would break MinGW, as Windows refuse to pass
34 # $test_encoding encoded parameter to git.
35 echo "Add $name ($added $name)" |
iconv -f utf-8
-t $test_encoding |
36 git
-c "i18n.commitEncoding=$test_encoding" commit
-F -
38 git rev-parse
--short --verify HEAD
43 git commit
"$@" -m "Commit $*" >/dev
/null
46 test_create_repo sm1
&&
47 add_file . foo
>/dev
/null
49 head1
=$
(add_file sm1 foo1 foo2
)
50 fullhead1
=$
(cd sm1
; git rev-parse
--verify HEAD
)
52 test_expect_success
'added submodule' '
54 git diff-index -p --submodule=log HEAD >actual &&
55 cat >expected <<-EOF &&
56 Submodule sm1 0000000...$head1 (new submodule)
58 test_cmp expected actual
61 test_expect_success
'added submodule, set diff.submodule' '
62 git config diff.submodule log &&
64 git diff --cached >actual &&
65 cat >expected <<-EOF &&
66 Submodule sm1 0000000...$head1 (new submodule)
68 git config --unset diff.submodule &&
69 test_cmp expected actual
72 test_expect_success
'--submodule=short overrides diff.submodule' '
73 test_config diff.submodule log &&
75 git diff --submodule=short --cached >actual &&
76 cat >expected <<-EOF &&
77 diff --git a/sm1 b/sm1
83 +Subproject commit $fullhead1
85 test_cmp expected actual
88 test_expect_success
'diff.submodule does not affect plumbing' '
89 test_config diff.submodule log &&
90 git diff-index -p HEAD >actual &&
91 cat >expected <<-EOF &&
92 diff --git a/sm1 b/sm1
98 +Subproject commit $fullhead1
100 test_cmp expected actual
104 head2
=$
(add_file sm1 foo3
)
106 test_expect_success
'modified submodule(forward)' '
107 git diff-index -p --submodule=log HEAD >actual &&
108 cat >expected <<-EOF &&
109 Submodule sm1 $head1..$head2:
110 > Add foo3 ($added foo3)
112 test_cmp expected actual
115 test_expect_success
'modified submodule(forward)' '
116 git diff --submodule=log >actual &&
117 cat >expected <<-EOF &&
118 Submodule sm1 $head1..$head2:
119 > Add foo3 ($added foo3)
121 test_cmp expected actual
124 test_expect_success
'modified submodule(forward) --submodule' '
125 git diff --submodule >actual &&
126 cat >expected <<-EOF &&
127 Submodule sm1 $head1..$head2:
128 > Add foo3 ($added foo3)
130 test_cmp expected actual
133 fullhead2
=$
(cd sm1
; git rev-parse
--verify HEAD
)
134 test_expect_success
'modified submodule(forward) --submodule=short' '
135 git diff --submodule=short >actual &&
136 cat >expected <<-EOF &&
137 diff --git a/sm1 b/sm1
138 index $head1..$head2 160000
142 -Subproject commit $fullhead1
143 +Subproject commit $fullhead2
145 test_cmp expected actual
151 git
reset --hard HEAD~
2 >/dev
/null
&&
152 git rev-parse
--short --verify HEAD
155 test_expect_success
'modified submodule(backward)' '
156 git diff-index -p --submodule=log HEAD >actual &&
157 cat >expected <<-EOF &&
158 Submodule sm1 $head2..$head3 (rewind):
159 < Add foo3 ($added foo3)
160 < Add foo2 ($added foo2)
162 test_cmp expected actual
165 head4
=$
(add_file sm1 foo4 foo5
)
166 test_expect_success
'modified submodule(backward and forward)' '
167 git diff-index -p --submodule=log HEAD >actual &&
168 cat >expected <<-EOF &&
169 Submodule sm1 $head2...$head4:
170 > Add foo5 ($added foo5)
171 > Add foo4 ($added foo4)
172 < Add foo3 ($added foo3)
173 < Add foo2 ($added foo2)
175 test_cmp expected actual
181 head5
=$
(git hash-object sm1 | cut
-c1-7) &&
186 test_expect_success
'typechanged submodule(submodule->blob), --cached' '
187 git diff --submodule=log --cached >actual &&
188 cat >expected <<-EOF &&
189 Submodule sm1 $head4...0000000 (submodule deleted)
190 diff --git a/sm1 b/sm1
192 index 0000000..$head5
198 test_cmp expected actual
201 test_expect_success
'typechanged submodule(submodule->blob)' '
202 git diff --submodule=log >actual &&
203 cat >expected <<-EOF &&
204 diff --git a/sm1 b/sm1
205 deleted file mode 100644
206 index $head5..0000000
211 Submodule sm1 0000000...$head4 (new submodule)
213 test_cmp expected actual
217 git checkout-index sm1
218 test_expect_success
'typechanged submodule(submodule->blob)' '
219 git diff-index -p --submodule=log HEAD >actual &&
220 cat >expected <<-EOF &&
221 Submodule sm1 $head4...0000000 (submodule deleted)
222 diff --git a/sm1 b/sm1
224 index 0000000..$head5
230 test_cmp expected actual
234 test_create_repo sm1
&&
235 head6
=$
(add_file sm1 foo6 foo7
)
236 fullhead6
=$
(cd sm1
; git rev-parse
--verify HEAD
)
237 test_expect_success
'nonexistent commit' '
238 git diff-index -p --submodule=log HEAD >actual &&
239 cat >expected <<-EOF &&
240 Submodule sm1 $head4...$head6 (commits not present)
242 test_cmp expected actual
246 test_expect_success
'typechanged submodule(blob->submodule)' '
247 git diff-index -p --submodule=log HEAD >actual &&
248 cat >expected <<-EOF &&
249 diff --git a/sm1 b/sm1
250 deleted file mode 100644
251 index $head5..0000000
256 Submodule sm1 0000000...$head6 (new submodule)
258 test_cmp expected actual
262 test_expect_success
'submodule is up to date' '
263 git diff-index -p --submodule=log HEAD >actual &&
264 test_must_be_empty actual
267 test_expect_success
'submodule contains untracked content' '
268 echo new > sm1/new-file &&
269 git diff-index -p --ignore-submodules=none --submodule=log HEAD >actual &&
270 cat >expected <<-EOF &&
271 Submodule sm1 contains untracked content
273 test_cmp expected actual
276 test_expect_success
'submodule contains untracked content (untracked ignored)' '
277 git diff-index -p --submodule=log HEAD >actual &&
278 test_must_be_empty actual
281 test_expect_success
'submodule contains untracked content (dirty ignored)' '
282 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
283 test_must_be_empty actual
286 test_expect_success
'submodule contains untracked content (all ignored)' '
287 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
288 test_must_be_empty actual
291 test_expect_success
'submodule contains untracked and modified content' '
292 echo new > sm1/foo6 &&
293 git diff-index -p --ignore-submodules=none --submodule=log HEAD >actual &&
294 cat >expected <<-EOF &&
295 Submodule sm1 contains untracked content
296 Submodule sm1 contains modified content
298 test_cmp expected actual
301 test_expect_success
'submodule contains untracked and modified content (untracked ignored)' '
302 echo new > sm1/foo6 &&
303 git diff-index -p --submodule=log HEAD >actual &&
304 cat >expected <<-EOF &&
305 Submodule sm1 contains modified content
307 test_cmp expected actual
310 test_expect_success
'submodule contains untracked and modified content (dirty ignored)' '
311 echo new > sm1/foo6 &&
312 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
313 test_must_be_empty actual
316 test_expect_success
'submodule contains untracked and modified content (all ignored)' '
317 echo new > sm1/foo6 &&
318 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
319 test_must_be_empty actual
322 test_expect_success
'submodule contains modified content' '
323 rm -f sm1/new-file &&
324 git diff-index -p --submodule=log HEAD >actual &&
325 cat >expected <<-EOF &&
326 Submodule sm1 contains modified content
328 test_cmp expected actual
331 (cd sm1
; git commit
-mchange foo6
>/dev
/null
) &&
332 head8
=$
(cd sm1
; git rev-parse
--short --verify HEAD
) &&
333 test_expect_success
'submodule is modified' '
334 git diff-index -p --submodule=log HEAD >actual &&
335 cat >expected <<-EOF &&
336 Submodule sm1 $head6..$head8:
339 test_cmp expected actual
342 test_expect_success
'modified submodule contains untracked content' '
343 echo new > sm1/new-file &&
344 git diff-index -p --ignore-submodules=none --submodule=log HEAD >actual &&
345 cat >expected <<-EOF &&
346 Submodule sm1 contains untracked content
347 Submodule sm1 $head6..$head8:
350 test_cmp expected actual
353 test_expect_success
'modified submodule contains untracked content (untracked ignored)' '
354 git diff-index -p --submodule=log HEAD >actual &&
355 cat >expected <<-EOF &&
356 Submodule sm1 $head6..$head8:
359 test_cmp expected actual
362 test_expect_success
'modified submodule contains untracked content (dirty ignored)' '
363 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
364 cat >expected <<-EOF &&
365 Submodule sm1 $head6..$head8:
368 test_cmp expected actual
371 test_expect_success
'modified submodule contains untracked content (all ignored)' '
372 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
373 test_must_be_empty actual
376 test_expect_success
'modified submodule contains untracked and modified content' '
377 echo modification >> sm1/foo6 &&
378 git diff-index -p --ignore-submodules=none --submodule=log HEAD >actual &&
379 cat >expected <<-EOF &&
380 Submodule sm1 contains untracked content
381 Submodule sm1 contains modified content
382 Submodule sm1 $head6..$head8:
385 test_cmp expected actual
388 test_expect_success
'modified submodule contains untracked and modified content (untracked ignored)' '
389 echo modification >> sm1/foo6 &&
390 git diff-index -p --submodule=log HEAD >actual &&
391 cat >expected <<-EOF &&
392 Submodule sm1 contains modified content
393 Submodule sm1 $head6..$head8:
396 test_cmp expected actual
399 test_expect_success
'modified submodule contains untracked and modified content (dirty ignored)' '
400 echo modification >> sm1/foo6 &&
401 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
402 cat >expected <<-EOF &&
403 Submodule sm1 $head6..$head8:
406 test_cmp expected actual
409 test_expect_success
'modified submodule contains untracked and modified content (all ignored)' '
410 echo modification >> sm1/foo6 &&
411 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
412 test_must_be_empty actual
415 test_expect_success
'modified submodule contains modified content' '
416 rm -f sm1/new-file &&
417 git diff-index -p --submodule=log HEAD >actual &&
418 cat >expected <<-EOF &&
419 Submodule sm1 contains modified content
420 Submodule sm1 $head6..$head8:
423 test_cmp expected actual
427 test_expect_success
'deleted submodule' '
428 git diff-index -p --submodule=log HEAD >actual &&
429 cat >expected <<-EOF &&
430 Submodule sm1 $head6...0000000 (submodule deleted)
432 test_cmp expected actual
435 test_expect_success
'create second submodule' '
436 test_create_repo sm2 &&
437 head7=$(add_file sm2 foo8 foo9) &&
441 test_expect_success
'multiple submodules' '
442 git diff-index -p --submodule=log HEAD >actual &&
443 cat >expected <<-EOF &&
444 Submodule sm1 $head6...0000000 (submodule deleted)
445 Submodule sm2 0000000...$head7 (new submodule)
447 test_cmp expected actual
450 test_expect_success
'path filter' '
451 git diff-index -p --submodule=log HEAD sm2 >actual &&
452 cat >expected <<-EOF &&
453 Submodule sm2 0000000...$head7 (new submodule)
455 test_cmp expected actual
459 test_expect_success
'given commit' '
460 git diff-index -p --submodule=log HEAD^ >actual &&
461 cat >expected <<-EOF &&
462 Submodule sm1 $head6...0000000 (submodule deleted)
463 Submodule sm2 0000000...$head7 (new submodule)
465 test_cmp expected actual
468 test_expect_success
'given commit --submodule' '
469 git diff-index -p --submodule HEAD^ >actual &&
470 cat >expected <<-EOF &&
471 Submodule sm1 $head6...0000000 (submodule deleted)
472 Submodule sm2 0000000...$head7 (new submodule)
474 test_cmp expected actual
477 fullhead7
=$
(cd sm2
; git rev-parse
--verify HEAD
)
479 test_expect_success
'given commit --submodule=short' '
480 git diff-index -p --submodule=short HEAD^ >actual &&
481 cat >expected <<-EOF &&
482 diff --git a/sm1 b/sm1
483 deleted file mode 160000
484 index $head6..0000000
488 -Subproject commit $fullhead6
489 diff --git a/sm2 b/sm2
491 index 0000000..$head7
495 +Subproject commit $fullhead7
497 test_cmp expected actual
500 test_expect_success
'setup .git file for sm2' '
502 REAL="$(pwd)/../.real" &&
504 echo "gitdir: $REAL" >.git)
507 test_expect_success
'diff --submodule with .git file' '
508 git diff --submodule HEAD^ >actual &&
509 cat >expected <<-EOF &&
510 Submodule sm1 $head6...0000000 (submodule deleted)
511 Submodule sm2 0000000...$head7 (new submodule)
513 test_cmp expected actual
516 test_expect_success
'diff --submodule with objects referenced by alternates' '
526 git clone -s ../sub_alt sub &&
529 git commit -m "sub a"
532 sha1_before=$(git rev-parse --short HEAD) &&
536 sha1_after=$(git rev-parse --short HEAD) &&
538 echo "Submodule sub $sha1_before..$sha1_after:" &&
545 git checkout origin/main
547 git diff --submodule > ../actual
549 test_cmp expected actual