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 msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding) &&
30 git -c "i18n.commitEncoding=$test_encoding" commit -m "$msg_added_iso88591"
32 git rev-parse --short --verify HEAD
37 git commit "$@" -m "Commit $*" >/dev/null
40 test_create_repo sm1 &&
41 add_file . foo >/dev/null
43 head1=$(add_file sm1 foo1 foo2)
44 fullhead1=$(cd sm1; git rev-parse --verify HEAD)
46 test_expect_success 'added submodule' '
48 git diff-index -p --submodule=log HEAD >actual &&
49 cat >expected <<-EOF &&
50 Submodule sm1 0000000...$head1 (new submodule)
52 test_cmp expected actual
55 test_expect_success 'added submodule, set diff.submodule' '
56 git config diff.submodule log &&
58 git diff --cached >actual &&
59 cat >expected <<-EOF &&
60 Submodule sm1 0000000...$head1 (new submodule)
62 git config --unset diff.submodule &&
63 test_cmp expected actual
66 test_expect_success '--submodule=short overrides diff.submodule' '
67 test_config diff.submodule log &&
69 git diff --submodule=short --cached >actual &&
70 cat >expected <<-EOF &&
71 diff --git a/sm1 b/sm1
77 +Subproject commit $fullhead1
79 test_cmp expected actual
82 test_expect_success 'diff.submodule does not affect plumbing' '
83 test_config diff.submodule log &&
84 git diff-index -p HEAD >actual &&
85 cat >expected <<-EOF &&
86 diff --git a/sm1 b/sm1
92 +Subproject commit $fullhead1
94 test_cmp expected actual
98 head2=$(add_file sm1 foo3)
100 test_expect_success 'modified submodule(forward)' '
101 git diff-index -p --submodule=log HEAD >actual &&
102 cat >expected <<-EOF &&
103 Submodule sm1 $head1..$head2:
104 > Add foo3 ($added foo3)
106 test_cmp expected actual
109 test_expect_success 'modified submodule(forward)' '
110 git diff --submodule=log >actual &&
111 cat >expected <<-EOF &&
112 Submodule sm1 $head1..$head2:
113 > Add foo3 ($added foo3)
115 test_cmp expected actual
118 test_expect_success 'modified submodule(forward) --submodule' '
119 git diff --submodule >actual &&
120 cat >expected <<-EOF &&
121 Submodule sm1 $head1..$head2:
122 > Add foo3 ($added foo3)
124 test_cmp expected actual
127 fullhead2=$(cd sm1; git rev-parse --verify HEAD)
128 test_expect_success 'modified submodule(forward) --submodule=short' '
129 git diff --submodule=short >actual &&
130 cat >expected <<-EOF &&
131 diff --git a/sm1 b/sm1
132 index $head1..$head2 160000
136 -Subproject commit $fullhead1
137 +Subproject commit $fullhead2
139 test_cmp expected actual
145 git reset --hard HEAD~2 >/dev/null &&
146 git rev-parse --short --verify HEAD
149 test_expect_success 'modified submodule(backward)' '
150 git diff-index -p --submodule=log HEAD >actual &&
151 cat >expected <<-EOF &&
152 Submodule sm1 $head2..$head3 (rewind):
153 < Add foo3 ($added foo3)
154 < Add foo2 ($added foo2)
156 test_cmp expected actual
159 head4=$(add_file sm1 foo4 foo5)
160 test_expect_success 'modified submodule(backward and forward)' '
161 git diff-index -p --submodule=log HEAD >actual &&
162 cat >expected <<-EOF &&
163 Submodule sm1 $head2...$head4:
164 > Add foo5 ($added foo5)
165 > Add foo4 ($added foo4)
166 < Add foo3 ($added foo3)
167 < Add foo2 ($added foo2)
169 test_cmp expected actual
175 head5=$(git hash-object sm1 | cut -c1-7) &&
180 test_expect_success 'typechanged submodule(submodule->blob), --cached' '
181 git diff --submodule=log --cached >actual &&
182 cat >expected <<-EOF &&
183 Submodule sm1 $head4...0000000 (submodule deleted)
184 diff --git a/sm1 b/sm1
186 index 0000000..$head5
192 test_cmp expected actual
195 test_expect_success 'typechanged submodule(submodule->blob)' '
196 git diff --submodule=log >actual &&
197 cat >expected <<-EOF &&
198 diff --git a/sm1 b/sm1
199 deleted file mode 100644
200 index $head5..0000000
205 Submodule sm1 0000000...$head4 (new submodule)
207 test_cmp expected actual
211 git checkout-index sm1
212 test_expect_success 'typechanged submodule(submodule->blob)' '
213 git diff-index -p --submodule=log HEAD >actual &&
214 cat >expected <<-EOF &&
215 Submodule sm1 $head4...0000000 (submodule deleted)
216 diff --git a/sm1 b/sm1
218 index 0000000..$head5
224 test_cmp expected actual
228 test_create_repo sm1 &&
229 head6=$(add_file sm1 foo6 foo7)
230 fullhead6=$(cd sm1; git rev-parse --verify HEAD)
231 test_expect_success 'nonexistent commit' '
232 git diff-index -p --submodule=log HEAD >actual &&
233 cat >expected <<-EOF &&
234 Submodule sm1 $head4...$head6 (commits not present)
236 test_cmp expected actual
240 test_expect_success 'typechanged submodule(blob->submodule)' '
241 git diff-index -p --submodule=log HEAD >actual &&
242 cat >expected <<-EOF &&
243 diff --git a/sm1 b/sm1
244 deleted file mode 100644
245 index $head5..0000000
250 Submodule sm1 0000000...$head6 (new submodule)
252 test_cmp expected actual
256 test_expect_success 'submodule is up to date' '
257 git diff-index -p --submodule=log HEAD >actual &&
258 cat >expected <<-EOF &&
260 test_cmp expected actual
263 test_expect_success 'submodule contains untracked content' '
264 echo new > sm1/new-file &&
265 git diff-index -p --submodule=log HEAD >actual &&
266 cat >expected <<-EOF &&
267 Submodule sm1 contains untracked content
269 test_cmp expected actual
272 test_expect_success 'submodule contains untracked content (untracked ignored)' '
273 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
277 test_expect_success 'submodule contains untracked content (dirty ignored)' '
278 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
282 test_expect_success 'submodule contains untracked content (all ignored)' '
283 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
287 test_expect_success 'submodule contains untracked and modifed content' '
288 echo new > sm1/foo6 &&
289 git diff-index -p --submodule=log HEAD >actual &&
290 cat >expected <<-EOF &&
291 Submodule sm1 contains untracked content
292 Submodule sm1 contains modified content
294 test_cmp expected actual
297 test_expect_success 'submodule contains untracked and modifed content (untracked ignored)' '
298 echo new > sm1/foo6 &&
299 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
300 cat >expected <<-EOF &&
301 Submodule sm1 contains modified content
303 test_cmp expected actual
306 test_expect_success 'submodule contains untracked and modifed content (dirty ignored)' '
307 echo new > sm1/foo6 &&
308 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
312 test_expect_success 'submodule contains untracked and modifed content (all ignored)' '
313 echo new > sm1/foo6 &&
314 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
318 test_expect_success 'submodule contains modifed content' '
319 rm -f sm1/new-file &&
320 git diff-index -p --submodule=log HEAD >actual &&
321 cat >expected <<-EOF &&
322 Submodule sm1 contains modified content
324 test_cmp expected actual
327 (cd sm1; git commit -mchange foo6 >/dev/null) &&
328 head8=$(cd sm1; git rev-parse --short --verify HEAD) &&
329 test_expect_success 'submodule is modified' '
330 git diff-index -p --submodule=log HEAD >actual &&
331 cat >expected <<-EOF &&
332 Submodule sm1 $head6..$head8:
335 test_cmp expected actual
338 test_expect_success 'modified submodule contains untracked content' '
339 echo new > sm1/new-file &&
340 git diff-index -p --submodule=log HEAD >actual &&
341 cat >expected <<-EOF &&
342 Submodule sm1 contains untracked content
343 Submodule sm1 $head6..$head8:
346 test_cmp expected actual
349 test_expect_success 'modified submodule contains untracked content (untracked ignored)' '
350 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
351 cat >expected <<-EOF &&
352 Submodule sm1 $head6..$head8:
355 test_cmp expected actual
358 test_expect_success 'modified submodule contains untracked content (dirty ignored)' '
359 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
360 cat >expected <<-EOF &&
361 Submodule sm1 $head6..$head8:
364 test_cmp expected actual
367 test_expect_success 'modified submodule contains untracked content (all ignored)' '
368 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
372 test_expect_success 'modified submodule contains untracked and modifed content' '
373 echo modification >> sm1/foo6 &&
374 git diff-index -p --submodule=log HEAD >actual &&
375 cat >expected <<-EOF &&
376 Submodule sm1 contains untracked content
377 Submodule sm1 contains modified content
378 Submodule sm1 $head6..$head8:
381 test_cmp expected actual
384 test_expect_success 'modified submodule contains untracked and modifed content (untracked ignored)' '
385 echo modification >> sm1/foo6 &&
386 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
387 cat >expected <<-EOF &&
388 Submodule sm1 contains modified content
389 Submodule sm1 $head6..$head8:
392 test_cmp expected actual
395 test_expect_success 'modified submodule contains untracked and modifed content (dirty ignored)' '
396 echo modification >> sm1/foo6 &&
397 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
398 cat >expected <<-EOF &&
399 Submodule sm1 $head6..$head8:
402 test_cmp expected actual
405 test_expect_success 'modified submodule contains untracked and modifed content (all ignored)' '
406 echo modification >> sm1/foo6 &&
407 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
411 test_expect_success 'modified submodule contains modifed content' '
412 rm -f sm1/new-file &&
413 git diff-index -p --submodule=log HEAD >actual &&
414 cat >expected <<-EOF &&
415 Submodule sm1 contains modified content
416 Submodule sm1 $head6..$head8:
419 test_cmp expected actual
423 test_expect_success 'deleted submodule' '
424 git diff-index -p --submodule=log HEAD >actual &&
425 cat >expected <<-EOF &&
426 Submodule sm1 $head6...0000000 (submodule deleted)
428 test_cmp expected actual
431 test_create_repo sm2 &&
432 head7=$(add_file sm2 foo8 foo9) &&
435 test_expect_success 'multiple submodules' '
436 git diff-index -p --submodule=log HEAD >actual &&
437 cat >expected <<-EOF &&
438 Submodule sm1 $head6...0000000 (submodule deleted)
439 Submodule sm2 0000000...$head7 (new submodule)
441 test_cmp expected actual
444 test_expect_success 'path filter' '
445 git diff-index -p --submodule=log HEAD sm2 >actual &&
446 cat >expected <<-EOF &&
447 Submodule sm2 0000000...$head7 (new submodule)
449 test_cmp expected actual
453 test_expect_success 'given commit' '
454 git diff-index -p --submodule=log HEAD^ >actual &&
455 cat >expected <<-EOF &&
456 Submodule sm1 $head6...0000000 (submodule deleted)
457 Submodule sm2 0000000...$head7 (new submodule)
459 test_cmp expected actual
462 test_expect_success 'given commit --submodule' '
463 git diff-index -p --submodule HEAD^ >actual &&
464 cat >expected <<-EOF &&
465 Submodule sm1 $head6...0000000 (submodule deleted)
466 Submodule sm2 0000000...$head7 (new submodule)
468 test_cmp expected actual
471 fullhead7=$(cd sm2; git rev-parse --verify HEAD)
473 test_expect_success 'given commit --submodule=short' '
474 git diff-index -p --submodule=short HEAD^ >actual &&
475 cat >expected <<-EOF &&
476 diff --git a/sm1 b/sm1
477 deleted file mode 160000
478 index $head6..0000000
482 -Subproject commit $fullhead6
483 diff --git a/sm2 b/sm2
485 index 0000000..$head7
489 +Subproject commit $fullhead7
491 test_cmp expected actual
494 test_expect_success 'setup .git file for sm2' '
496 REAL="$(pwd)/../.real" &&
498 echo "gitdir: $REAL" >.git)
501 test_expect_success 'diff --submodule with .git file' '
502 git diff --submodule HEAD^ >actual &&
503 cat >expected <<-EOF &&
504 Submodule sm1 $head6...0000000 (submodule deleted)
505 Submodule sm2 0000000...$head7 (new submodule)
507 test_cmp expected actual
510 test_expect_success 'diff --submodule with objects referenced by alternates' '
520 git clone -s ../sub_alt sub &&
523 git commit -m "sub a"
526 sha1_before=$(git rev-parse --short HEAD)
530 sha1_after=$(git rev-parse --short HEAD)
531 echo "Submodule sub $sha1_before..$sha1_after:
537 git checkout origin/master
539 git diff --submodule > ../actual
541 test_cmp expected actual