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.
14 # Tested non-UTF-8 encoding
15 test_encoding="ISO8859-1"
17 # String "added" in German (translated with Google Translate), encoded in UTF-8,
18 # used in sample commit log messages in add_file() function below.
19 added=$(printf "hinzugef\303\274gt")
26 echo "$name" >"$name" &&
29 # "git commit -m" would break MinGW, as Windows refuse to pass
30 # $test_encoding encoded parameter to git.
31 echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding |
32 git -c "i18n.commitEncoding=$test_encoding" commit -F -
34 git rev-parse --short --verify HEAD
39 git commit "$@" -m "Commit $*" >/dev/null
42 test_create_repo sm1 &&
43 add_file . foo >/dev/null
45 head1=$(add_file sm1 foo1 foo2)
46 fullhead1=$(cd sm1; git rev-parse --verify HEAD)
48 test_expect_success 'added submodule' '
50 git diff-index -p --submodule=log HEAD >actual &&
51 cat >expected <<-EOF &&
52 Submodule sm1 0000000...$head1 (new submodule)
54 test_cmp expected actual
57 test_expect_success 'added submodule, set diff.submodule' '
58 git config diff.submodule log &&
60 git diff --cached >actual &&
61 cat >expected <<-EOF &&
62 Submodule sm1 0000000...$head1 (new submodule)
64 git config --unset diff.submodule &&
65 test_cmp expected actual
68 test_expect_success '--submodule=short overrides diff.submodule' '
69 test_config diff.submodule log &&
71 git diff --submodule=short --cached >actual &&
72 cat >expected <<-EOF &&
73 diff --git a/sm1 b/sm1
79 +Subproject commit $fullhead1
81 test_cmp expected actual
84 test_expect_success 'diff.submodule does not affect plumbing' '
85 test_config diff.submodule log &&
86 git diff-index -p HEAD >actual &&
87 cat >expected <<-EOF &&
88 diff --git a/sm1 b/sm1
94 +Subproject commit $fullhead1
96 test_cmp expected actual
100 head2=$(add_file sm1 foo3)
102 test_expect_success 'modified submodule(forward)' '
103 git diff-index -p --submodule=log HEAD >actual &&
104 cat >expected <<-EOF &&
105 Submodule sm1 $head1..$head2:
106 > Add foo3 ($added foo3)
108 test_cmp expected actual
111 test_expect_success 'modified submodule(forward)' '
112 git diff --submodule=log >actual &&
113 cat >expected <<-EOF &&
114 Submodule sm1 $head1..$head2:
115 > Add foo3 ($added foo3)
117 test_cmp expected actual
120 test_expect_success 'modified submodule(forward) --submodule' '
121 git diff --submodule >actual &&
122 cat >expected <<-EOF &&
123 Submodule sm1 $head1..$head2:
124 > Add foo3 ($added foo3)
126 test_cmp expected actual
129 fullhead2=$(cd sm1; git rev-parse --verify HEAD)
130 test_expect_success 'modified submodule(forward) --submodule=short' '
131 git diff --submodule=short >actual &&
132 cat >expected <<-EOF &&
133 diff --git a/sm1 b/sm1
134 index $head1..$head2 160000
138 -Subproject commit $fullhead1
139 +Subproject commit $fullhead2
141 test_cmp expected actual
147 git reset --hard HEAD~2 >/dev/null &&
148 git rev-parse --short --verify HEAD
151 test_expect_success 'modified submodule(backward)' '
152 git diff-index -p --submodule=log HEAD >actual &&
153 cat >expected <<-EOF &&
154 Submodule sm1 $head2..$head3 (rewind):
155 < Add foo3 ($added foo3)
156 < Add foo2 ($added foo2)
158 test_cmp expected actual
161 head4=$(add_file sm1 foo4 foo5)
162 test_expect_success 'modified submodule(backward and forward)' '
163 git diff-index -p --submodule=log HEAD >actual &&
164 cat >expected <<-EOF &&
165 Submodule sm1 $head2...$head4:
166 > Add foo5 ($added foo5)
167 > Add foo4 ($added foo4)
168 < Add foo3 ($added foo3)
169 < Add foo2 ($added foo2)
171 test_cmp expected actual
177 head5=$(git hash-object sm1 | cut -c1-7) &&
182 test_expect_success 'typechanged submodule(submodule->blob), --cached' '
183 git diff --submodule=log --cached >actual &&
184 cat >expected <<-EOF &&
185 Submodule sm1 $head4...0000000 (submodule deleted)
186 diff --git a/sm1 b/sm1
188 index 0000000..$head5
194 test_cmp expected actual
197 test_expect_success 'typechanged submodule(submodule->blob)' '
198 git diff --submodule=log >actual &&
199 cat >expected <<-EOF &&
200 diff --git a/sm1 b/sm1
201 deleted file mode 100644
202 index $head5..0000000
207 Submodule sm1 0000000...$head4 (new submodule)
209 test_cmp expected actual
213 git checkout-index sm1
214 test_expect_success 'typechanged submodule(submodule->blob)' '
215 git diff-index -p --submodule=log HEAD >actual &&
216 cat >expected <<-EOF &&
217 Submodule sm1 $head4...0000000 (submodule deleted)
218 diff --git a/sm1 b/sm1
220 index 0000000..$head5
226 test_cmp expected actual
230 test_create_repo sm1 &&
231 head6=$(add_file sm1 foo6 foo7)
232 fullhead6=$(cd sm1; git rev-parse --verify HEAD)
233 test_expect_success 'nonexistent commit' '
234 git diff-index -p --submodule=log HEAD >actual &&
235 cat >expected <<-EOF &&
236 Submodule sm1 $head4...$head6 (commits not present)
238 test_cmp expected actual
242 test_expect_success 'typechanged submodule(blob->submodule)' '
243 git diff-index -p --submodule=log HEAD >actual &&
244 cat >expected <<-EOF &&
245 diff --git a/sm1 b/sm1
246 deleted file mode 100644
247 index $head5..0000000
252 Submodule sm1 0000000...$head6 (new submodule)
254 test_cmp expected actual
258 test_expect_success 'submodule is up to date' '
259 git diff-index -p --submodule=log HEAD >actual &&
260 cat >expected <<-EOF &&
262 test_cmp expected actual
265 test_expect_success 'submodule contains untracked content' '
266 echo new > sm1/new-file &&
267 git diff-index -p --submodule=log HEAD >actual &&
268 cat >expected <<-EOF &&
269 Submodule sm1 contains untracked content
271 test_cmp expected actual
274 test_expect_success 'submodule contains untracked content (untracked ignored)' '
275 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
279 test_expect_success 'submodule contains untracked content (dirty ignored)' '
280 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
284 test_expect_success 'submodule contains untracked content (all ignored)' '
285 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
289 test_expect_success 'submodule contains untracked and modifed content' '
290 echo new > sm1/foo6 &&
291 git diff-index -p --submodule=log HEAD >actual &&
292 cat >expected <<-EOF &&
293 Submodule sm1 contains untracked content
294 Submodule sm1 contains modified content
296 test_cmp expected actual
299 test_expect_success 'submodule contains untracked and modifed content (untracked ignored)' '
300 echo new > sm1/foo6 &&
301 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
302 cat >expected <<-EOF &&
303 Submodule sm1 contains modified content
305 test_cmp expected actual
308 test_expect_success 'submodule contains untracked and modifed content (dirty ignored)' '
309 echo new > sm1/foo6 &&
310 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
314 test_expect_success 'submodule contains untracked and modifed content (all ignored)' '
315 echo new > sm1/foo6 &&
316 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
320 test_expect_success 'submodule contains modifed content' '
321 rm -f sm1/new-file &&
322 git diff-index -p --submodule=log HEAD >actual &&
323 cat >expected <<-EOF &&
324 Submodule sm1 contains modified content
326 test_cmp expected actual
329 (cd sm1; git commit -mchange foo6 >/dev/null) &&
330 head8=$(cd sm1; git rev-parse --short --verify HEAD) &&
331 test_expect_success 'submodule is modified' '
332 git diff-index -p --submodule=log HEAD >actual &&
333 cat >expected <<-EOF &&
334 Submodule sm1 $head6..$head8:
337 test_cmp expected actual
340 test_expect_success 'modified submodule contains untracked content' '
341 echo new > sm1/new-file &&
342 git diff-index -p --submodule=log HEAD >actual &&
343 cat >expected <<-EOF &&
344 Submodule sm1 contains untracked content
345 Submodule sm1 $head6..$head8:
348 test_cmp expected actual
351 test_expect_success 'modified submodule contains untracked content (untracked ignored)' '
352 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
353 cat >expected <<-EOF &&
354 Submodule sm1 $head6..$head8:
357 test_cmp expected actual
360 test_expect_success 'modified submodule contains untracked content (dirty ignored)' '
361 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
362 cat >expected <<-EOF &&
363 Submodule sm1 $head6..$head8:
366 test_cmp expected actual
369 test_expect_success 'modified submodule contains untracked content (all ignored)' '
370 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
374 test_expect_success 'modified submodule contains untracked and modifed content' '
375 echo modification >> sm1/foo6 &&
376 git diff-index -p --submodule=log HEAD >actual &&
377 cat >expected <<-EOF &&
378 Submodule sm1 contains untracked content
379 Submodule sm1 contains modified content
380 Submodule sm1 $head6..$head8:
383 test_cmp expected actual
386 test_expect_success 'modified submodule contains untracked and modifed content (untracked ignored)' '
387 echo modification >> sm1/foo6 &&
388 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
389 cat >expected <<-EOF &&
390 Submodule sm1 contains modified content
391 Submodule sm1 $head6..$head8:
394 test_cmp expected actual
397 test_expect_success 'modified submodule contains untracked and modifed content (dirty ignored)' '
398 echo modification >> sm1/foo6 &&
399 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
400 cat >expected <<-EOF &&
401 Submodule sm1 $head6..$head8:
404 test_cmp expected actual
407 test_expect_success 'modified submodule contains untracked and modifed content (all ignored)' '
408 echo modification >> sm1/foo6 &&
409 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
413 test_expect_success 'modified submodule contains modifed content' '
414 rm -f sm1/new-file &&
415 git diff-index -p --submodule=log HEAD >actual &&
416 cat >expected <<-EOF &&
417 Submodule sm1 contains modified content
418 Submodule sm1 $head6..$head8:
421 test_cmp expected actual
425 test_expect_success 'deleted submodule' '
426 git diff-index -p --submodule=log HEAD >actual &&
427 cat >expected <<-EOF &&
428 Submodule sm1 $head6...0000000 (submodule deleted)
430 test_cmp expected actual
433 test_expect_success 'create second submodule' '
434 test_create_repo sm2 &&
435 head7=$(add_file sm2 foo8 foo9) &&
439 test_expect_success 'multiple submodules' '
440 git diff-index -p --submodule=log HEAD >actual &&
441 cat >expected <<-EOF &&
442 Submodule sm1 $head6...0000000 (submodule deleted)
443 Submodule sm2 0000000...$head7 (new submodule)
445 test_cmp expected actual
448 test_expect_success 'path filter' '
449 git diff-index -p --submodule=log HEAD sm2 >actual &&
450 cat >expected <<-EOF &&
451 Submodule sm2 0000000...$head7 (new submodule)
453 test_cmp expected actual
457 test_expect_success 'given commit' '
458 git diff-index -p --submodule=log HEAD^ >actual &&
459 cat >expected <<-EOF &&
460 Submodule sm1 $head6...0000000 (submodule deleted)
461 Submodule sm2 0000000...$head7 (new submodule)
463 test_cmp expected actual
466 test_expect_success 'given commit --submodule' '
467 git diff-index -p --submodule HEAD^ >actual &&
468 cat >expected <<-EOF &&
469 Submodule sm1 $head6...0000000 (submodule deleted)
470 Submodule sm2 0000000...$head7 (new submodule)
472 test_cmp expected actual
475 fullhead7=$(cd sm2; git rev-parse --verify HEAD)
477 test_expect_success 'given commit --submodule=short' '
478 git diff-index -p --submodule=short HEAD^ >actual &&
479 cat >expected <<-EOF &&
480 diff --git a/sm1 b/sm1
481 deleted file mode 160000
482 index $head6..0000000
486 -Subproject commit $fullhead6
487 diff --git a/sm2 b/sm2
489 index 0000000..$head7
493 +Subproject commit $fullhead7
495 test_cmp expected actual
498 test_expect_success 'setup .git file for sm2' '
500 REAL="$(pwd)/../.real" &&
502 echo "gitdir: $REAL" >.git)
505 test_expect_success 'diff --submodule with .git file' '
506 git diff --submodule HEAD^ >actual &&
507 cat >expected <<-EOF &&
508 Submodule sm1 $head6...0000000 (submodule deleted)
509 Submodule sm2 0000000...$head7 (new submodule)
511 test_cmp expected actual
514 test_expect_success 'diff --submodule with objects referenced by alternates' '
524 git clone -s ../sub_alt sub &&
527 git commit -m "sub a"
530 sha1_before=$(git rev-parse --short HEAD) &&
534 sha1_after=$(git rev-parse --short HEAD) &&
536 echo "Submodule sub $sha1_before..$sha1_after:" &&
543 git checkout origin/master
545 git diff --submodule > ../actual
547 test_cmp expected actual