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 # String "added" in German (translated with Google Translate), encoded in UTF-8,
15 # used in sample commit log messages in add_file() function below.
16 added=$(printf "hinzugef\303\274gt")
23 echo "$name" >"$name" &&
26 msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso8859-1) &&
27 git -c 'i18n.commitEncoding=iso8859-1' commit -m "$msg_added_iso88591"
29 git rev-parse --short --verify HEAD
34 git commit "$@" -m "Commit $*" >/dev/null
37 test_create_repo sm1 &&
38 add_file . foo >/dev/null
40 head1=$(add_file sm1 foo1 foo2)
41 fullhead1=$(cd sm1; git rev-parse --verify HEAD)
43 test_expect_success 'added submodule' '
45 git diff-index -p --submodule=log HEAD >actual &&
46 cat >expected <<-EOF &&
47 Submodule sm1 0000000...$head1 (new submodule)
49 test_cmp expected actual
52 test_expect_success 'added submodule, set diff.submodule' '
53 git config diff.submodule log &&
55 git diff --cached >actual &&
56 cat >expected <<-EOF &&
57 Submodule sm1 0000000...$head1 (new submodule)
59 git config --unset diff.submodule &&
60 test_cmp expected actual
63 test_expect_success '--submodule=short overrides diff.submodule' '
64 test_config diff.submodule log &&
66 git diff --submodule=short --cached >actual &&
67 cat >expected <<-EOF &&
68 diff --git a/sm1 b/sm1
74 +Subproject commit $fullhead1
76 test_cmp expected actual
79 test_expect_success 'diff.submodule does not affect plumbing' '
80 test_config diff.submodule log &&
81 git diff-index -p HEAD >actual &&
82 cat >expected <<-EOF &&
83 diff --git a/sm1 b/sm1
89 +Subproject commit $fullhead1
91 test_cmp expected actual
95 head2=$(add_file sm1 foo3)
97 test_expect_success 'modified submodule(forward)' '
98 git diff-index -p --submodule=log HEAD >actual &&
99 cat >expected <<-EOF &&
100 Submodule sm1 $head1..$head2:
101 > Add foo3 ($added foo3)
103 test_cmp expected actual
106 test_expect_success 'modified submodule(forward)' '
107 git diff --submodule=log >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) --submodule' '
116 git diff --submodule >actual &&
117 cat >expected <<-EOF &&
118 Submodule sm1 $head1..$head2:
119 > Add foo3 ($added foo3)
121 test_cmp expected actual
124 fullhead2=$(cd sm1; git rev-parse --verify HEAD)
125 test_expect_success 'modified submodule(forward) --submodule=short' '
126 git diff --submodule=short >actual &&
127 cat >expected <<-EOF &&
128 diff --git a/sm1 b/sm1
129 index $head1..$head2 160000
133 -Subproject commit $fullhead1
134 +Subproject commit $fullhead2
136 test_cmp expected actual
142 git reset --hard HEAD~2 >/dev/null &&
143 git rev-parse --short --verify HEAD
146 test_expect_success 'modified submodule(backward)' '
147 git diff-index -p --submodule=log HEAD >actual &&
148 cat >expected <<-EOF &&
149 Submodule sm1 $head2..$head3 (rewind):
150 < Add foo3 ($added foo3)
151 < Add foo2 ($added foo2)
153 test_cmp expected actual
156 head4=$(add_file sm1 foo4 foo5)
157 test_expect_success 'modified submodule(backward and forward)' '
158 git diff-index -p --submodule=log HEAD >actual &&
159 cat >expected <<-EOF &&
160 Submodule sm1 $head2...$head4:
161 > Add foo5 ($added foo5)
162 > Add foo4 ($added foo4)
163 < Add foo3 ($added foo3)
164 < Add foo2 ($added foo2)
166 test_cmp expected actual
172 head5=$(git hash-object sm1 | cut -c1-7) &&
177 test_expect_success 'typechanged submodule(submodule->blob), --cached' '
178 git diff --submodule=log --cached >actual &&
179 cat >expected <<-EOF &&
180 Submodule sm1 $head4...0000000 (submodule deleted)
181 diff --git a/sm1 b/sm1
183 index 0000000..$head5
189 test_cmp expected actual
192 test_expect_success 'typechanged submodule(submodule->blob)' '
193 git diff --submodule=log >actual &&
194 cat >expected <<-EOF &&
195 diff --git a/sm1 b/sm1
196 deleted file mode 100644
197 index $head5..0000000
202 Submodule sm1 0000000...$head4 (new submodule)
204 test_cmp expected actual
208 git checkout-index sm1
209 test_expect_success 'typechanged submodule(submodule->blob)' '
210 git diff-index -p --submodule=log HEAD >actual &&
211 cat >expected <<-EOF &&
212 Submodule sm1 $head4...0000000 (submodule deleted)
213 diff --git a/sm1 b/sm1
215 index 0000000..$head5
221 test_cmp expected actual
225 test_create_repo sm1 &&
226 head6=$(add_file sm1 foo6 foo7)
227 fullhead6=$(cd sm1; git rev-parse --verify HEAD)
228 test_expect_success 'nonexistent commit' '
229 git diff-index -p --submodule=log HEAD >actual &&
230 cat >expected <<-EOF &&
231 Submodule sm1 $head4...$head6 (commits not present)
233 test_cmp expected actual
237 test_expect_success 'typechanged submodule(blob->submodule)' '
238 git diff-index -p --submodule=log HEAD >actual &&
239 cat >expected <<-EOF &&
240 diff --git a/sm1 b/sm1
241 deleted file mode 100644
242 index $head5..0000000
247 Submodule sm1 0000000...$head6 (new submodule)
249 test_cmp expected actual
253 test_expect_success 'submodule is up to date' '
254 git diff-index -p --submodule=log HEAD >actual &&
255 cat >expected <<-EOF &&
257 test_cmp expected actual
260 test_expect_success 'submodule contains untracked content' '
261 echo new > sm1/new-file &&
262 git diff-index -p --submodule=log HEAD >actual &&
263 cat >expected <<-EOF &&
264 Submodule sm1 contains untracked content
266 test_cmp expected actual
269 test_expect_success 'submodule contains untracked content (untracked ignored)' '
270 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
274 test_expect_success 'submodule contains untracked content (dirty ignored)' '
275 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
279 test_expect_success 'submodule contains untracked content (all ignored)' '
280 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
284 test_expect_success 'submodule contains untracked and modifed content' '
285 echo new > sm1/foo6 &&
286 git diff-index -p --submodule=log HEAD >actual &&
287 cat >expected <<-EOF &&
288 Submodule sm1 contains untracked content
289 Submodule sm1 contains modified content
291 test_cmp expected actual
294 test_expect_success 'submodule contains untracked and modifed content (untracked ignored)' '
295 echo new > sm1/foo6 &&
296 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
297 cat >expected <<-EOF &&
298 Submodule sm1 contains modified content
300 test_cmp expected actual
303 test_expect_success 'submodule contains untracked and modifed content (dirty ignored)' '
304 echo new > sm1/foo6 &&
305 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
309 test_expect_success 'submodule contains untracked and modifed content (all ignored)' '
310 echo new > sm1/foo6 &&
311 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
315 test_expect_success 'submodule contains modifed content' '
316 rm -f sm1/new-file &&
317 git diff-index -p --submodule=log HEAD >actual &&
318 cat >expected <<-EOF &&
319 Submodule sm1 contains modified content
321 test_cmp expected actual
324 (cd sm1; git commit -mchange foo6 >/dev/null) &&
325 head8=$(cd sm1; git rev-parse --short --verify HEAD) &&
326 test_expect_success 'submodule is modified' '
327 git diff-index -p --submodule=log HEAD >actual &&
328 cat >expected <<-EOF &&
329 Submodule sm1 $head6..$head8:
332 test_cmp expected actual
335 test_expect_success 'modified submodule contains untracked content' '
336 echo new > sm1/new-file &&
337 git diff-index -p --submodule=log HEAD >actual &&
338 cat >expected <<-EOF &&
339 Submodule sm1 contains untracked content
340 Submodule sm1 $head6..$head8:
343 test_cmp expected actual
346 test_expect_success 'modified submodule contains untracked content (untracked ignored)' '
347 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
348 cat >expected <<-EOF &&
349 Submodule sm1 $head6..$head8:
352 test_cmp expected actual
355 test_expect_success 'modified submodule contains untracked content (dirty ignored)' '
356 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
357 cat >expected <<-EOF &&
358 Submodule sm1 $head6..$head8:
361 test_cmp expected actual
364 test_expect_success 'modified submodule contains untracked content (all ignored)' '
365 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
369 test_expect_success 'modified submodule contains untracked and modifed content' '
370 echo modification >> sm1/foo6 &&
371 git diff-index -p --submodule=log HEAD >actual &&
372 cat >expected <<-EOF &&
373 Submodule sm1 contains untracked content
374 Submodule sm1 contains modified content
375 Submodule sm1 $head6..$head8:
378 test_cmp expected actual
381 test_expect_success 'modified submodule contains untracked and modifed content (untracked ignored)' '
382 echo modification >> sm1/foo6 &&
383 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
384 cat >expected <<-EOF &&
385 Submodule sm1 contains modified content
386 Submodule sm1 $head6..$head8:
389 test_cmp expected actual
392 test_expect_success 'modified submodule contains untracked and modifed content (dirty ignored)' '
393 echo modification >> sm1/foo6 &&
394 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
395 cat >expected <<-EOF &&
396 Submodule sm1 $head6..$head8:
399 test_cmp expected actual
402 test_expect_success 'modified submodule contains untracked and modifed content (all ignored)' '
403 echo modification >> sm1/foo6 &&
404 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
408 test_expect_success 'modified submodule contains modifed content' '
409 rm -f sm1/new-file &&
410 git diff-index -p --submodule=log HEAD >actual &&
411 cat >expected <<-EOF &&
412 Submodule sm1 contains modified content
413 Submodule sm1 $head6..$head8:
416 test_cmp expected actual
420 test_expect_success 'deleted submodule' '
421 git diff-index -p --submodule=log HEAD >actual &&
422 cat >expected <<-EOF &&
423 Submodule sm1 $head6...0000000 (submodule deleted)
425 test_cmp expected actual
428 test_create_repo sm2 &&
429 head7=$(add_file sm2 foo8 foo9) &&
432 test_expect_success 'multiple submodules' '
433 git diff-index -p --submodule=log HEAD >actual &&
434 cat >expected <<-EOF &&
435 Submodule sm1 $head6...0000000 (submodule deleted)
436 Submodule sm2 0000000...$head7 (new submodule)
438 test_cmp expected actual
441 test_expect_success 'path filter' '
442 git diff-index -p --submodule=log HEAD sm2 >actual &&
443 cat >expected <<-EOF &&
444 Submodule sm2 0000000...$head7 (new submodule)
446 test_cmp expected actual
450 test_expect_success 'given commit' '
451 git diff-index -p --submodule=log HEAD^ >actual &&
452 cat >expected <<-EOF &&
453 Submodule sm1 $head6...0000000 (submodule deleted)
454 Submodule sm2 0000000...$head7 (new submodule)
456 test_cmp expected actual
459 test_expect_success 'given commit --submodule' '
460 git diff-index -p --submodule 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 fullhead7=$(cd sm2; git rev-parse --verify HEAD)
470 test_expect_success 'given commit --submodule=short' '
471 git diff-index -p --submodule=short HEAD^ >actual &&
472 cat >expected <<-EOF &&
473 diff --git a/sm1 b/sm1
474 deleted file mode 160000
475 index $head6..0000000
479 -Subproject commit $fullhead6
480 diff --git a/sm2 b/sm2
482 index 0000000..$head7
486 +Subproject commit $fullhead7
488 test_cmp expected actual
491 test_expect_success 'setup .git file for sm2' '
493 REAL="$(pwd)/../.real" &&
495 echo "gitdir: $REAL" >.git)
498 test_expect_success 'diff --submodule with .git file' '
499 git diff --submodule HEAD^ >actual &&
500 cat >expected <<-EOF &&
501 Submodule sm1 $head6...0000000 (submodule deleted)
502 Submodule sm2 0000000...$head7 (new submodule)
504 test_cmp expected actual
507 test_expect_success 'diff --submodule with objects referenced by alternates' '
517 git clone -s ../sub_alt sub &&
520 git commit -m "sub a"
523 sha1_before=$(git rev-parse --short HEAD)
527 sha1_after=$(git rev-parse --short HEAD)
528 echo "Submodule sub $sha1_before..$sha1_after:
534 git checkout origin/master
536 git diff --submodule > ../actual
538 test_cmp expected actual