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
)
37 test_expect_success
'added submodule' "
39 git diff-index -p --submodule=log HEAD >actual &&
40 cat >expected <<-EOF &&
41 Submodule sm1 0000000...$head1 (new submodule)
43 test_cmp expected actual
47 head2
=$
(add_file sm1 foo3
)
49 test_expect_success
'modified submodule(forward)' "
50 git diff-index -p --submodule=log HEAD >actual &&
51 cat >expected <<-EOF &&
52 Submodule sm1 $head1..$head2:
55 test_cmp expected actual
58 test_expect_success
'modified submodule(forward)' "
59 git diff --submodule=log >actual &&
60 cat >expected <<-EOF &&
61 Submodule sm1 $head1..$head2:
64 test_cmp expected actual
67 test_expect_success
'modified submodule(forward) --submodule' "
68 git diff --submodule >actual &&
69 cat >expected <<-EOF &&
70 Submodule sm1 $head1..$head2:
73 test_cmp expected actual
76 fullhead1
=$
(cd sm1
; git rev-list
--max-count=1 $head1)
77 fullhead2
=$
(cd sm1
; git rev-list
--max-count=1 $head2)
78 test_expect_success
'modified submodule(forward) --submodule=short' "
79 git diff --submodule=short >actual &&
80 cat >expected <<-EOF &&
81 diff --git a/sm1 b/sm1
82 index $head1..$head2 160000
86 -Subproject commit $fullhead1
87 +Subproject commit $fullhead2
89 test_cmp expected actual
95 git
reset --hard HEAD~
2 >/dev
/null
&&
96 git rev-parse
--verify HEAD | cut
-c1-7
99 test_expect_success
'modified submodule(backward)' "
100 git diff-index -p --submodule=log HEAD >actual &&
101 cat >expected <<-EOF &&
102 Submodule sm1 $head2..$head3 (rewind):
106 test_cmp expected actual
109 head4
=$
(add_file sm1 foo4 foo5
) &&
110 head4_full
=$
(GIT_DIR
=sm
1/.git git rev-parse
--verify HEAD
)
111 test_expect_success
'modified submodule(backward and forward)' "
112 git diff-index -p --submodule=log HEAD >actual &&
113 cat >expected <<-EOF &&
114 Submodule sm1 $head2...$head4:
120 test_cmp expected actual
126 head5
=$
(git hash-object sm1 | cut
-c1-7) &&
131 test_expect_success
'typechanged submodule(submodule->blob), --cached' "
132 git diff --submodule=log --cached >actual &&
133 cat >expected <<-EOF &&
134 Submodule sm1 41fbea9...0000000 (submodule deleted)
135 diff --git a/sm1 b/sm1
137 index 0000000..9da5fb8
143 test_cmp expected actual
146 test_expect_success
'typechanged submodule(submodule->blob)' "
147 git diff --submodule=log >actual &&
148 cat >expected <<-EOF &&
149 diff --git a/sm1 b/sm1
150 deleted file mode 100644
151 index 9da5fb8..0000000
156 Submodule sm1 0000000...$head4 (new submodule)
158 test_cmp expected actual
162 git checkout-index sm1
163 test_expect_success
'typechanged submodule(submodule->blob)' "
164 git diff-index -p --submodule=log HEAD >actual &&
165 cat >expected <<-EOF &&
166 Submodule sm1 $head4...0000000 (submodule deleted)
167 diff --git a/sm1 b/sm1
169 index 0000000..$head5
175 test_cmp expected actual
179 test_create_repo sm1
&&
180 head6
=$
(add_file sm1 foo6 foo7
)
181 fullhead6
=$
(cd sm1
; git rev-list
--max-count=1 $head6)
182 test_expect_success
'nonexistent commit' "
183 git diff-index -p --submodule=log HEAD >actual &&
184 cat >expected <<-EOF &&
185 Submodule sm1 $head4...$head6 (commits not present)
187 test_cmp expected actual
191 test_expect_success
'typechanged submodule(blob->submodule)' "
192 git diff-index -p --submodule=log HEAD >actual &&
193 cat >expected <<-EOF &&
194 diff --git a/sm1 b/sm1
195 deleted file mode 100644
196 index $head5..0000000
201 Submodule sm1 0000000...$head6 (new submodule)
203 test_cmp expected actual
207 test_expect_success
'submodule is up to date' "
208 git diff-index -p --submodule=log HEAD >actual &&
209 cat >expected <<-EOF &&
211 test_cmp expected actual
214 test_expect_success
'submodule contains untracked content' "
215 echo new > sm1/new-file &&
216 git diff-index -p --submodule=log HEAD >actual &&
217 cat >expected <<-EOF &&
218 Submodule sm1 contains untracked content
220 test_cmp expected actual
223 test_expect_success
'submodule contains untracked content (untracked ignored)' "
224 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
228 test_expect_success
'submodule contains untracked content (dirty ignored)' "
229 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
233 test_expect_success
'submodule contains untracked content (all ignored)' "
234 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
238 test_expect_success
'submodule contains untracked and modifed content' "
239 echo new > sm1/foo6 &&
240 git diff-index -p --submodule=log HEAD >actual &&
241 cat >expected <<-EOF &&
242 Submodule sm1 contains untracked content
243 Submodule sm1 contains modified content
245 test_cmp expected actual
248 test_expect_success
'submodule contains untracked and modifed content (untracked ignored)' "
249 echo new > sm1/foo6 &&
250 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
251 cat >expected <<-EOF &&
252 Submodule sm1 contains modified content
254 test_cmp expected actual
257 test_expect_success
'submodule contains untracked and modifed content (dirty ignored)' "
258 echo new > sm1/foo6 &&
259 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
263 test_expect_success
'submodule contains untracked and modifed content (all ignored)' "
264 echo new > sm1/foo6 &&
265 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
269 test_expect_success
'submodule contains modifed content' "
270 rm -f sm1/new-file &&
271 git diff-index -p --submodule=log HEAD >actual &&
272 cat >expected <<-EOF &&
273 Submodule sm1 contains modified content
275 test_cmp expected actual
278 (cd sm1
; git commit
-mchange foo6
>/dev
/null
) &&
279 head8
=$
(cd sm1
; git rev-parse
--verify HEAD | cut
-c1-7) &&
280 test_expect_success
'submodule is modified' "
281 git diff-index -p --submodule=log HEAD >actual &&
282 cat >expected <<-EOF &&
283 Submodule sm1 $head6..$head8:
286 test_cmp expected actual
289 test_expect_success
'modified submodule contains untracked content' "
290 echo new > sm1/new-file &&
291 git diff-index -p --submodule=log HEAD >actual &&
292 cat >expected <<-EOF &&
293 Submodule sm1 contains untracked content
294 Submodule sm1 $head6..$head8:
297 test_cmp expected actual
300 test_expect_success
'modified submodule contains untracked content (untracked ignored)' "
301 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
302 cat >expected <<-EOF &&
303 Submodule sm1 $head6..$head8:
306 test_cmp expected actual
309 test_expect_success
'modified submodule contains untracked content (dirty ignored)' "
310 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
311 cat >expected <<-EOF &&
312 Submodule sm1 $head6..$head8:
315 test_cmp expected actual
318 test_expect_success
'modified submodule contains untracked content (all ignored)' "
319 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
323 test_expect_success
'modified submodule contains untracked and modifed content' "
324 echo modification >> sm1/foo6 &&
325 git diff-index -p --submodule=log HEAD >actual &&
326 cat >expected <<-EOF &&
327 Submodule sm1 contains untracked content
328 Submodule sm1 contains modified content
329 Submodule sm1 $head6..$head8:
332 test_cmp expected actual
335 test_expect_success
'modified submodule contains untracked and modifed content (untracked ignored)' "
336 echo modification >> sm1/foo6 &&
337 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
338 cat >expected <<-EOF &&
339 Submodule sm1 contains modified content
340 Submodule sm1 $head6..$head8:
343 test_cmp expected actual
346 test_expect_success
'modified submodule contains untracked and modifed content (dirty ignored)' "
347 echo modification >> sm1/foo6 &&
348 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
349 cat >expected <<-EOF &&
350 Submodule sm1 $head6..$head8:
353 test_cmp expected actual
356 test_expect_success
'modified submodule contains untracked and modifed content (all ignored)' "
357 echo modification >> sm1/foo6 &&
358 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
362 test_expect_success
'modified submodule contains modifed content' "
363 rm -f sm1/new-file &&
364 git diff-index -p --submodule=log HEAD >actual &&
365 cat >expected <<-EOF &&
366 Submodule sm1 contains modified content
367 Submodule sm1 $head6..$head8:
370 test_cmp expected actual
374 test_expect_success
'deleted submodule' "
375 git diff-index -p --submodule=log HEAD >actual &&
376 cat >expected <<-EOF &&
377 Submodule sm1 $head6...0000000 (submodule deleted)
379 test_cmp expected actual
382 test_create_repo sm2
&&
383 head7
=$
(add_file sm2 foo8 foo9
) &&
386 test_expect_success
'multiple submodules' "
387 git diff-index -p --submodule=log HEAD >actual &&
388 cat >expected <<-EOF &&
389 Submodule sm1 $head6...0000000 (submodule deleted)
390 Submodule sm2 0000000...$head7 (new submodule)
392 test_cmp expected actual
395 test_expect_success
'path filter' "
396 git diff-index -p --submodule=log HEAD sm2 >actual &&
397 cat >expected <<-EOF &&
398 Submodule sm2 0000000...$head7 (new submodule)
400 test_cmp expected actual
404 test_expect_success
'given commit' "
405 git diff-index -p --submodule=log HEAD^ >actual &&
406 cat >expected <<-EOF &&
407 Submodule sm1 $head6...0000000 (submodule deleted)
408 Submodule sm2 0000000...$head7 (new submodule)
410 test_cmp expected actual
413 test_expect_success
'given commit --submodule' "
414 git diff-index -p --submodule HEAD^ >actual &&
415 cat >expected <<-EOF &&
416 Submodule sm1 $head6...0000000 (submodule deleted)
417 Submodule sm2 0000000...$head7 (new submodule)
419 test_cmp expected actual
422 fullhead7
=$
(cd sm2
; git rev-list
--max-count=1 $head7)
424 test_expect_success
'given commit --submodule=short' "
425 git diff-index -p --submodule=short HEAD^ >actual &&
426 cat >expected <<-EOF &&
427 diff --git a/sm1 b/sm1
428 deleted file mode 160000
429 index $head6..0000000
433 -Subproject commit $fullhead6
434 diff --git a/sm2 b/sm2
436 index 0000000..$head7
440 +Subproject commit $fullhead7
442 test_cmp expected actual
445 test_expect_success
'setup .git file for sm2' '
447 REAL="$(pwd)/../.real" &&
449 echo "gitdir: $REAL" >.git)
452 test_expect_success
'diff --submodule with .git file' '
453 git diff --submodule HEAD^ >actual &&
454 cat >expected <<-EOF &&
455 Submodule sm1 $head6...0000000 (submodule deleted)
456 Submodule sm2 0000000...$head7 (new submodule)
458 test_cmp expected actual