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
17 # Tested non-UTF-8 encoding
18 test_encoding="ISO8859-1"
20 # String "added" in German (translated with Google Translate), encoded in UTF-8,
21 # used in sample commit log messages in add_file() function below.
22 added=$(printf "hinzugef\303\274gt")
29 echo "$name" >"$name" &&
32 # "git commit -m" would break MinGW, as Windows refuse to pass
33 # $test_encoding encoded parameter to git.
34 echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding |
35 git -c "i18n.commitEncoding=$test_encoding" commit -F -
37 git rev-parse --short --verify HEAD
42 git commit "$@" -m "Commit $*" >/dev/null
45 test_create_repo sm1 &&
46 add_file . foo >/dev/null
48 head1=$(add_file sm1 foo1 foo2)
49 fullhead1=$(cd sm1; git rev-parse --verify HEAD)
51 test_expect_success 'added submodule' '
53 git diff-index -p --submodule=log HEAD >actual &&
54 cat >expected <<-EOF &&
55 Submodule sm1 0000000...$head1 (new submodule)
57 test_cmp expected actual
60 test_expect_success 'added submodule, set diff.submodule' '
61 git config diff.submodule log &&
63 git diff --cached >actual &&
64 cat >expected <<-EOF &&
65 Submodule sm1 0000000...$head1 (new submodule)
67 git config --unset diff.submodule &&
68 test_cmp expected actual
71 test_expect_success '--submodule=short overrides diff.submodule' '
72 test_config diff.submodule log &&
74 git diff --submodule=short --cached >actual &&
75 cat >expected <<-EOF &&
76 diff --git a/sm1 b/sm1
82 +Subproject commit $fullhead1
84 test_cmp expected actual
87 test_expect_success 'diff.submodule does not affect plumbing' '
88 test_config diff.submodule log &&
89 git diff-index -p HEAD >actual &&
90 cat >expected <<-EOF &&
91 diff --git a/sm1 b/sm1
97 +Subproject commit $fullhead1
99 test_cmp expected actual
103 head2=$(add_file sm1 foo3)
105 test_expect_success 'modified submodule(forward)' '
106 git diff-index -p --submodule=log HEAD >actual &&
107 cat >expected <<-EOF &&
108 Submodule sm1 $head1..$head2:
109 > Add foo3 ($added foo3)
111 test_cmp expected actual
114 test_expect_success 'modified submodule(forward)' '
115 git diff --submodule=log >actual &&
116 cat >expected <<-EOF &&
117 Submodule sm1 $head1..$head2:
118 > Add foo3 ($added foo3)
120 test_cmp expected actual
123 test_expect_success 'modified submodule(forward) --submodule' '
124 git diff --submodule >actual &&
125 cat >expected <<-EOF &&
126 Submodule sm1 $head1..$head2:
127 > Add foo3 ($added foo3)
129 test_cmp expected actual
132 fullhead2=$(cd sm1; git rev-parse --verify HEAD)
133 test_expect_success 'modified submodule(forward) --submodule=short' '
134 git diff --submodule=short >actual &&
135 cat >expected <<-EOF &&
136 diff --git a/sm1 b/sm1
137 index $head1..$head2 160000
141 -Subproject commit $fullhead1
142 +Subproject commit $fullhead2
144 test_cmp expected actual
150 git reset --hard HEAD~2 >/dev/null &&
151 git rev-parse --short --verify HEAD
154 test_expect_success 'modified submodule(backward)' '
155 git diff-index -p --submodule=log HEAD >actual &&
156 cat >expected <<-EOF &&
157 Submodule sm1 $head2..$head3 (rewind):
158 < Add foo3 ($added foo3)
159 < Add foo2 ($added foo2)
161 test_cmp expected actual
164 head4=$(add_file sm1 foo4 foo5)
165 test_expect_success 'modified submodule(backward and forward)' '
166 git diff-index -p --submodule=log HEAD >actual &&
167 cat >expected <<-EOF &&
168 Submodule sm1 $head2...$head4:
169 > Add foo5 ($added foo5)
170 > Add foo4 ($added foo4)
171 < Add foo3 ($added foo3)
172 < Add foo2 ($added foo2)
174 test_cmp expected actual
180 head5=$(git hash-object sm1 | cut -c1-7) &&
185 test_expect_success 'typechanged submodule(submodule->blob), --cached' '
186 git diff --submodule=log --cached >actual &&
187 cat >expected <<-EOF &&
188 Submodule sm1 $head4...0000000 (submodule deleted)
189 diff --git a/sm1 b/sm1
191 index 0000000..$head5
197 test_cmp expected actual
200 test_expect_success 'typechanged submodule(submodule->blob)' '
201 git diff --submodule=log >actual &&
202 cat >expected <<-EOF &&
203 diff --git a/sm1 b/sm1
204 deleted file mode 100644
205 index $head5..0000000
210 Submodule sm1 0000000...$head4 (new submodule)
212 test_cmp expected actual
216 git checkout-index sm1
217 test_expect_success 'typechanged submodule(submodule->blob)' '
218 git diff-index -p --submodule=log HEAD >actual &&
219 cat >expected <<-EOF &&
220 Submodule sm1 $head4...0000000 (submodule deleted)
221 diff --git a/sm1 b/sm1
223 index 0000000..$head5
229 test_cmp expected actual
233 test_create_repo sm1 &&
234 head6=$(add_file sm1 foo6 foo7)
235 fullhead6=$(cd sm1; git rev-parse --verify HEAD)
236 test_expect_success 'nonexistent commit' '
237 git diff-index -p --submodule=log HEAD >actual &&
238 cat >expected <<-EOF &&
239 Submodule sm1 $head4...$head6 (commits not present)
241 test_cmp expected actual
245 test_expect_success 'typechanged submodule(blob->submodule)' '
246 git diff-index -p --submodule=log HEAD >actual &&
247 cat >expected <<-EOF &&
248 diff --git a/sm1 b/sm1
249 deleted file mode 100644
250 index $head5..0000000
255 Submodule sm1 0000000...$head6 (new submodule)
257 test_cmp expected actual
261 test_expect_success 'submodule is up to date' '
262 git diff-index -p --submodule=log HEAD >actual &&
263 test_must_be_empty actual
266 test_expect_success 'submodule contains untracked content' '
267 echo new > sm1/new-file &&
268 git diff-index -p --ignore-submodules=none --submodule=log HEAD >actual &&
269 cat >expected <<-EOF &&
270 Submodule sm1 contains untracked content
272 test_cmp expected actual
275 test_expect_success 'submodule contains untracked content (untracked ignored)' '
276 git diff-index -p --submodule=log HEAD >actual &&
277 test_must_be_empty actual
280 test_expect_success 'submodule contains untracked content (dirty ignored)' '
281 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
282 test_must_be_empty actual
285 test_expect_success 'submodule contains untracked content (all ignored)' '
286 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
287 test_must_be_empty actual
290 test_expect_success 'submodule contains untracked and modified content' '
291 echo new > sm1/foo6 &&
292 git diff-index -p --ignore-submodules=none --submodule=log HEAD >actual &&
293 cat >expected <<-EOF &&
294 Submodule sm1 contains untracked content
295 Submodule sm1 contains modified content
297 test_cmp expected actual
300 test_expect_success 'submodule contains untracked and modified content (untracked ignored)' '
301 echo new > sm1/foo6 &&
302 git diff-index -p --submodule=log HEAD >actual &&
303 cat >expected <<-EOF &&
304 Submodule sm1 contains modified content
306 test_cmp expected actual
309 test_expect_success 'submodule contains untracked and modified content (dirty ignored)' '
310 echo new > sm1/foo6 &&
311 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
312 test_must_be_empty actual
315 test_expect_success 'submodule contains untracked and modified content (all ignored)' '
316 echo new > sm1/foo6 &&
317 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
318 test_must_be_empty actual
321 test_expect_success 'submodule contains modified content' '
322 rm -f sm1/new-file &&
323 git diff-index -p --submodule=log HEAD >actual &&
324 cat >expected <<-EOF &&
325 Submodule sm1 contains modified content
327 test_cmp expected actual
330 (cd sm1; git commit -mchange foo6 >/dev/null) &&
331 head8=$(cd sm1; git rev-parse --short --verify HEAD) &&
332 test_expect_success 'submodule is modified' '
333 git diff-index -p --submodule=log HEAD >actual &&
334 cat >expected <<-EOF &&
335 Submodule sm1 $head6..$head8:
338 test_cmp expected actual
341 test_expect_success 'modified submodule contains untracked content' '
342 echo new > sm1/new-file &&
343 git diff-index -p --ignore-submodules=none --submodule=log HEAD >actual &&
344 cat >expected <<-EOF &&
345 Submodule sm1 contains untracked content
346 Submodule sm1 $head6..$head8:
349 test_cmp expected actual
352 test_expect_success 'modified submodule contains untracked content (untracked ignored)' '
353 git diff-index -p --submodule=log HEAD >actual &&
354 cat >expected <<-EOF &&
355 Submodule sm1 $head6..$head8:
358 test_cmp expected actual
361 test_expect_success 'modified submodule contains untracked content (dirty ignored)' '
362 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
363 cat >expected <<-EOF &&
364 Submodule sm1 $head6..$head8:
367 test_cmp expected actual
370 test_expect_success 'modified submodule contains untracked content (all ignored)' '
371 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
372 test_must_be_empty actual
375 test_expect_success 'modified submodule contains untracked and modified content' '
376 echo modification >> sm1/foo6 &&
377 git diff-index -p --ignore-submodules=none --submodule=log HEAD >actual &&
378 cat >expected <<-EOF &&
379 Submodule sm1 contains untracked content
380 Submodule sm1 contains modified content
381 Submodule sm1 $head6..$head8:
384 test_cmp expected actual
387 test_expect_success 'modified submodule contains untracked and modified content (untracked ignored)' '
388 echo modification >> sm1/foo6 &&
389 git diff-index -p --submodule=log HEAD >actual &&
390 cat >expected <<-EOF &&
391 Submodule sm1 contains modified content
392 Submodule sm1 $head6..$head8:
395 test_cmp expected actual
398 test_expect_success 'modified submodule contains untracked and modified content (dirty ignored)' '
399 echo modification >> sm1/foo6 &&
400 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
401 cat >expected <<-EOF &&
402 Submodule sm1 $head6..$head8:
405 test_cmp expected actual
408 test_expect_success 'modified submodule contains untracked and modified content (all ignored)' '
409 echo modification >> sm1/foo6 &&
410 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
411 test_must_be_empty actual
414 test_expect_success 'modified submodule contains modified content' '
415 rm -f sm1/new-file &&
416 git diff-index -p --submodule=log HEAD >actual &&
417 cat >expected <<-EOF &&
418 Submodule sm1 contains modified content
419 Submodule sm1 $head6..$head8:
422 test_cmp expected actual
426 test_expect_success 'deleted submodule' '
427 git diff-index -p --submodule=log HEAD >actual &&
428 cat >expected <<-EOF &&
429 Submodule sm1 $head6...0000000 (submodule deleted)
431 test_cmp expected actual
434 test_expect_success 'create second submodule' '
435 test_create_repo sm2 &&
436 head7=$(add_file sm2 foo8 foo9) &&
440 test_expect_success 'multiple submodules' '
441 git diff-index -p --submodule=log HEAD >actual &&
442 cat >expected <<-EOF &&
443 Submodule sm1 $head6...0000000 (submodule deleted)
444 Submodule sm2 0000000...$head7 (new submodule)
446 test_cmp expected actual
449 test_expect_success 'path filter' '
450 git diff-index -p --submodule=log HEAD sm2 >actual &&
451 cat >expected <<-EOF &&
452 Submodule sm2 0000000...$head7 (new submodule)
454 test_cmp expected actual
458 test_expect_success 'given commit' '
459 git diff-index -p --submodule=log HEAD^ >actual &&
460 cat >expected <<-EOF &&
461 Submodule sm1 $head6...0000000 (submodule deleted)
462 Submodule sm2 0000000...$head7 (new submodule)
464 test_cmp expected actual
467 test_expect_success 'given commit --submodule' '
468 git diff-index -p --submodule HEAD^ >actual &&
469 cat >expected <<-EOF &&
470 Submodule sm1 $head6...0000000 (submodule deleted)
471 Submodule sm2 0000000...$head7 (new submodule)
473 test_cmp expected actual
476 fullhead7=$(cd sm2; git rev-parse --verify HEAD)
478 test_expect_success 'given commit --submodule=short' '
479 git diff-index -p --submodule=short HEAD^ >actual &&
480 cat >expected <<-EOF &&
481 diff --git a/sm1 b/sm1
482 deleted file mode 160000
483 index $head6..0000000
487 -Subproject commit $fullhead6
488 diff --git a/sm2 b/sm2
490 index 0000000..$head7
494 +Subproject commit $fullhead7
496 test_cmp expected actual
499 test_expect_success 'setup .git file for sm2' '
501 REAL="$(pwd)/../.real" &&
503 echo "gitdir: $REAL" >.git)
506 test_expect_success 'diff --submodule with .git file' '
507 git diff --submodule HEAD^ >actual &&
508 cat >expected <<-EOF &&
509 Submodule sm1 $head6...0000000 (submodule deleted)
510 Submodule sm2 0000000...$head7 (new submodule)
512 test_cmp expected actual
515 test_expect_success 'diff --submodule with objects referenced by alternates' '
525 git clone -s ../sub_alt sub &&
528 git commit -m "sub a"
531 sha1_before=$(git rev-parse --short HEAD) &&
535 sha1_after=$(git rev-parse --short HEAD) &&
537 echo "Submodule sub $sha1_before..$sha1_after:" &&
544 git checkout origin/main
546 git diff --submodule > ../actual
548 test_cmp expected actual