3 # Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
6 test_description='Support for verbose submodule differences in git diff
8 This test tries to verify the sanity of the --submodule option of git diff.
19 echo "$name" > "$name" &&
22 git commit -m "Add $name"
24 git rev-parse --verify HEAD | cut -c1-7
29 git commit "$@" -m "Commit $*" >/dev/null
32 test_create_repo sm1 &&
33 add_file . foo >/dev/null
35 head1=$(add_file sm1 foo1 foo2)
36 fullhead1=$(cd sm1; git rev-list --max-count=1 $head1)
38 test_expect_success 'added submodule' "
40 git diff-index -p --submodule=log HEAD >actual &&
41 cat >expected <<-EOF &&
42 Submodule sm1 0000000...$head1 (new submodule)
44 test_cmp expected actual
47 test_expect_success 'added submodule, set diff.submodule' "
48 git config diff.submodule log &&
50 git diff --cached >actual &&
51 cat >expected <<-EOF &&
52 Submodule sm1 0000000...$head1 (new submodule)
54 git config --unset diff.submodule &&
55 test_cmp expected actual
58 test_expect_success '--submodule=short overrides diff.submodule' "
59 test_config diff.submodule log &&
61 git diff --submodule=short --cached >actual &&
62 cat >expected <<-EOF &&
63 diff --git a/sm1 b/sm1
65 index 0000000..a2c4dab
69 +Subproject commit $fullhead1
71 test_cmp expected actual
74 test_expect_success 'diff.submodule does not affect plumbing' '
75 test_config diff.submodule log &&
76 git diff-index -p HEAD >actual &&
77 cat >expected <<-EOF &&
78 diff --git a/sm1 b/sm1
80 index 0000000..a2c4dab
84 +Subproject commit $fullhead1
86 test_cmp expected actual
90 head2=$(add_file sm1 foo3)
92 test_expect_success 'modified submodule(forward)' "
93 git diff-index -p --submodule=log HEAD >actual &&
94 cat >expected <<-EOF &&
95 Submodule sm1 $head1..$head2:
98 test_cmp expected actual
101 test_expect_success 'modified submodule(forward)' "
102 git diff --submodule=log >actual &&
103 cat >expected <<-EOF &&
104 Submodule sm1 $head1..$head2:
107 test_cmp expected actual
110 test_expect_success 'modified submodule(forward) --submodule' "
111 git diff --submodule >actual &&
112 cat >expected <<-EOF &&
113 Submodule sm1 $head1..$head2:
116 test_cmp expected actual
119 fullhead2=$(cd sm1; git rev-list --max-count=1 $head2)
120 test_expect_success 'modified submodule(forward) --submodule=short' "
121 git diff --submodule=short >actual &&
122 cat >expected <<-EOF &&
123 diff --git a/sm1 b/sm1
124 index $head1..$head2 160000
128 -Subproject commit $fullhead1
129 +Subproject commit $fullhead2
131 test_cmp expected actual
137 git reset --hard HEAD~2 >/dev/null &&
138 git rev-parse --verify HEAD | cut -c1-7
141 test_expect_success 'modified submodule(backward)' "
142 git diff-index -p --submodule=log HEAD >actual &&
143 cat >expected <<-EOF &&
144 Submodule sm1 $head2..$head3 (rewind):
148 test_cmp expected actual
151 head4=$(add_file sm1 foo4 foo5) &&
152 head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
153 test_expect_success 'modified submodule(backward and forward)' "
154 git diff-index -p --submodule=log HEAD >actual &&
155 cat >expected <<-EOF &&
156 Submodule sm1 $head2...$head4:
162 test_cmp expected actual
168 head5=$(git hash-object sm1 | cut -c1-7) &&
173 test_expect_success 'typechanged submodule(submodule->blob), --cached' "
174 git diff --submodule=log --cached >actual &&
175 cat >expected <<-EOF &&
176 Submodule sm1 41fbea9...0000000 (submodule deleted)
177 diff --git a/sm1 b/sm1
179 index 0000000..9da5fb8
185 test_cmp expected actual
188 test_expect_success 'typechanged submodule(submodule->blob)' "
189 git diff --submodule=log >actual &&
190 cat >expected <<-EOF &&
191 diff --git a/sm1 b/sm1
192 deleted file mode 100644
193 index 9da5fb8..0000000
198 Submodule sm1 0000000...$head4 (new submodule)
200 test_cmp expected actual
204 git checkout-index sm1
205 test_expect_success 'typechanged submodule(submodule->blob)' "
206 git diff-index -p --submodule=log HEAD >actual &&
207 cat >expected <<-EOF &&
208 Submodule sm1 $head4...0000000 (submodule deleted)
209 diff --git a/sm1 b/sm1
211 index 0000000..$head5
217 test_cmp expected actual
221 test_create_repo sm1 &&
222 head6=$(add_file sm1 foo6 foo7)
223 fullhead6=$(cd sm1; git rev-list --max-count=1 $head6)
224 test_expect_success 'nonexistent commit' "
225 git diff-index -p --submodule=log HEAD >actual &&
226 cat >expected <<-EOF &&
227 Submodule sm1 $head4...$head6 (commits not present)
229 test_cmp expected actual
233 test_expect_success 'typechanged submodule(blob->submodule)' "
234 git diff-index -p --submodule=log HEAD >actual &&
235 cat >expected <<-EOF &&
236 diff --git a/sm1 b/sm1
237 deleted file mode 100644
238 index $head5..0000000
243 Submodule sm1 0000000...$head6 (new submodule)
245 test_cmp expected actual
249 test_expect_success 'submodule is up to date' "
250 git diff-index -p --submodule=log HEAD >actual &&
251 cat >expected <<-EOF &&
253 test_cmp expected actual
256 test_expect_success 'submodule contains untracked content' "
257 echo new > sm1/new-file &&
258 git diff-index -p --submodule=log HEAD >actual &&
259 cat >expected <<-EOF &&
260 Submodule sm1 contains untracked content
262 test_cmp expected actual
265 test_expect_success 'submodule contains untracked content (untracked ignored)' "
266 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
270 test_expect_success 'submodule contains untracked content (dirty ignored)' "
271 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
275 test_expect_success 'submodule contains untracked content (all ignored)' "
276 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
280 test_expect_success 'submodule contains untracked and modifed content' "
281 echo new > sm1/foo6 &&
282 git diff-index -p --submodule=log HEAD >actual &&
283 cat >expected <<-EOF &&
284 Submodule sm1 contains untracked content
285 Submodule sm1 contains modified content
287 test_cmp expected actual
290 test_expect_success 'submodule contains untracked and modifed content (untracked ignored)' "
291 echo new > sm1/foo6 &&
292 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
293 cat >expected <<-EOF &&
294 Submodule sm1 contains modified content
296 test_cmp expected actual
299 test_expect_success 'submodule contains untracked and modifed content (dirty ignored)' "
300 echo new > sm1/foo6 &&
301 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
305 test_expect_success 'submodule contains untracked and modifed content (all ignored)' "
306 echo new > sm1/foo6 &&
307 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
311 test_expect_success 'submodule contains modifed content' "
312 rm -f sm1/new-file &&
313 git diff-index -p --submodule=log HEAD >actual &&
314 cat >expected <<-EOF &&
315 Submodule sm1 contains modified content
317 test_cmp expected actual
320 (cd sm1; git commit -mchange foo6 >/dev/null) &&
321 head8=$(cd sm1; git rev-parse --verify HEAD | cut -c1-7) &&
322 test_expect_success 'submodule is modified' "
323 git diff-index -p --submodule=log HEAD >actual &&
324 cat >expected <<-EOF &&
325 Submodule sm1 $head6..$head8:
328 test_cmp expected actual
331 test_expect_success 'modified submodule contains untracked content' "
332 echo new > sm1/new-file &&
333 git diff-index -p --submodule=log HEAD >actual &&
334 cat >expected <<-EOF &&
335 Submodule sm1 contains untracked content
336 Submodule sm1 $head6..$head8:
339 test_cmp expected actual
342 test_expect_success 'modified submodule contains untracked content (untracked ignored)' "
343 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
344 cat >expected <<-EOF &&
345 Submodule sm1 $head6..$head8:
348 test_cmp expected actual
351 test_expect_success 'modified submodule contains untracked content (dirty ignored)' "
352 git diff-index -p --ignore-submodules=dirty --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 (all ignored)' "
361 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
365 test_expect_success 'modified submodule contains untracked and modifed content' "
366 echo modification >> sm1/foo6 &&
367 git diff-index -p --submodule=log HEAD >actual &&
368 cat >expected <<-EOF &&
369 Submodule sm1 contains untracked content
370 Submodule sm1 contains modified content
371 Submodule sm1 $head6..$head8:
374 test_cmp expected actual
377 test_expect_success 'modified submodule contains untracked and modifed content (untracked ignored)' "
378 echo modification >> sm1/foo6 &&
379 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
380 cat >expected <<-EOF &&
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 modifed content (dirty ignored)' "
389 echo modification >> sm1/foo6 &&
390 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
391 cat >expected <<-EOF &&
392 Submodule sm1 $head6..$head8:
395 test_cmp expected actual
398 test_expect_success 'modified submodule contains untracked and modifed content (all ignored)' "
399 echo modification >> sm1/foo6 &&
400 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
404 test_expect_success 'modified submodule contains modifed content' "
405 rm -f sm1/new-file &&
406 git diff-index -p --submodule=log HEAD >actual &&
407 cat >expected <<-EOF &&
408 Submodule sm1 contains modified content
409 Submodule sm1 $head6..$head8:
412 test_cmp expected actual
416 test_expect_success 'deleted submodule' "
417 git diff-index -p --submodule=log HEAD >actual &&
418 cat >expected <<-EOF &&
419 Submodule sm1 $head6...0000000 (submodule deleted)
421 test_cmp expected actual
424 test_create_repo sm2 &&
425 head7=$(add_file sm2 foo8 foo9) &&
428 test_expect_success 'multiple submodules' "
429 git diff-index -p --submodule=log HEAD >actual &&
430 cat >expected <<-EOF &&
431 Submodule sm1 $head6...0000000 (submodule deleted)
432 Submodule sm2 0000000...$head7 (new submodule)
434 test_cmp expected actual
437 test_expect_success 'path filter' "
438 git diff-index -p --submodule=log HEAD sm2 >actual &&
439 cat >expected <<-EOF &&
440 Submodule sm2 0000000...$head7 (new submodule)
442 test_cmp expected actual
446 test_expect_success 'given commit' "
447 git diff-index -p --submodule=log HEAD^ >actual &&
448 cat >expected <<-EOF &&
449 Submodule sm1 $head6...0000000 (submodule deleted)
450 Submodule sm2 0000000...$head7 (new submodule)
452 test_cmp expected actual
455 test_expect_success 'given commit --submodule' "
456 git diff-index -p --submodule HEAD^ >actual &&
457 cat >expected <<-EOF &&
458 Submodule sm1 $head6...0000000 (submodule deleted)
459 Submodule sm2 0000000...$head7 (new submodule)
461 test_cmp expected actual
464 fullhead7=$(cd sm2; git rev-list --max-count=1 $head7)
466 test_expect_success 'given commit --submodule=short' "
467 git diff-index -p --submodule=short HEAD^ >actual &&
468 cat >expected <<-EOF &&
469 diff --git a/sm1 b/sm1
470 deleted file mode 160000
471 index $head6..0000000
475 -Subproject commit $fullhead6
476 diff --git a/sm2 b/sm2
478 index 0000000..$head7
482 +Subproject commit $fullhead7
484 test_cmp expected actual
487 test_expect_success 'setup .git file for sm2' '
489 REAL="$(pwd)/../.real" &&
491 echo "gitdir: $REAL" >.git)
494 test_expect_success 'diff --submodule with .git file' '
495 git diff --submodule HEAD^ >actual &&
496 cat >expected <<-EOF &&
497 Submodule sm1 $head6...0000000 (submodule deleted)
498 Submodule sm2 0000000...$head7 (new submodule)
500 test_cmp expected actual
503 test_expect_success 'diff --submodule with objects referenced by alternates' '
513 git clone -s ../sub_alt sub &&
516 git commit -m "sub a"
519 sha1_before=$(git rev-parse --short HEAD)
523 sha1_after=$(git rev-parse --short HEAD)
524 echo "Submodule sub $sha1_before..$sha1_after:
530 git checkout origin/master
532 git diff --submodule > ../actual
534 test_cmp expected actual