Merge branch 'maint'
[git/kirr.git] / t / t4041-diff-submodule-option.sh
blobbf9a7526bd38a17e0e991739db8c4a1f8541b2f6
1 #!/bin/sh
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.
11 . ./test-lib.sh
13 add_file () {
14 sm=$1
15 shift
16 owd=$(pwd)
17 cd "$sm"
18 for name; do
19 echo "$name" > "$name" &&
20 git add "$name" &&
21 test_tick &&
22 git commit -m "Add $name"
23 done >/dev/null
24 git rev-parse --verify HEAD | cut -c1-7
25 cd "$owd"
27 commit_file () {
28 test_tick &&
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' "
38 git add sm1 &&
39 git diff-index -p --submodule=log HEAD >actual &&
40 cat >expected <<-EOF &&
41 Submodule sm1 0000000...$head1 (new submodule)
42 EOF
43 test_cmp expected actual
46 commit_file sm1 &&
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:
53 > Add foo3
54 EOF
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:
62 > Add foo3
63 EOF
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:
71 > Add foo3
72 EOF
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
83 --- a/sm1
84 +++ b/sm1
85 @@ -1 +1 @@
86 -Subproject commit $fullhead1
87 +Subproject commit $fullhead2
88 EOF
89 test_cmp expected actual
92 commit_file sm1 &&
93 head3=$(
94 cd sm1 &&
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):
103 < Add foo3
104 < Add foo2
106 test_cmp expected actual
109 head4=$(add_file sm1 foo4 foo5) &&
110 head4_full=$(GIT_DIR=sm1/.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:
115 > Add foo5
116 > Add foo4
117 < Add foo3
118 < Add foo2
120 test_cmp expected actual
123 commit_file sm1 &&
124 mv sm1 sm1-bak &&
125 echo sm1 >sm1 &&
126 head5=$(git hash-object sm1 | cut -c1-7) &&
127 git add sm1 &&
128 rm -f sm1 &&
129 mv sm1-bak sm1
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
136 new file mode 100644
137 index 0000000..9da5fb8
138 --- /dev/null
139 +++ b/sm1
140 @@ -0,0 +1 @@
141 +sm1
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
152 --- a/sm1
153 +++ /dev/null
154 @@ -1 +0,0 @@
155 -sm1
156 Submodule sm1 0000000...$head4 (new submodule)
158 test_cmp expected actual
161 rm -rf sm1 &&
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
168 new file mode 100644
169 index 0000000..$head5
170 --- /dev/null
171 +++ b/sm1
172 @@ -0,0 +1 @@
173 +sm1
175 test_cmp expected actual
178 rm -f sm1 &&
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
190 commit_file
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
197 --- a/sm1
198 +++ /dev/null
199 @@ -1 +0,0 @@
200 -sm1
201 Submodule sm1 0000000...$head6 (new submodule)
203 test_cmp expected actual
206 commit_file sm1 &&
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 &&
225 ! test -s actual
228 test_expect_success 'submodule contains untracked content (dirty ignored)' "
229 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
230 ! test -s actual
233 test_expect_success 'submodule contains untracked content (all ignored)' "
234 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
235 ! test -s 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 &&
260 ! test -s 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 &&
266 ! test -s 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:
284 > change
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:
295 > change
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:
304 > change
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:
313 > change
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 &&
320 ! test -s 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:
330 > change
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:
341 > change
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:
351 > change
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 &&
359 ! test -s 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:
368 > change
370 test_cmp expected actual
373 rm -rf sm1
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) &&
384 git add sm2
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
403 commit_file sm2
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
430 --- a/sm1
431 +++ /dev/null
432 @@ -1 +0,0 @@
433 -Subproject commit $fullhead6
434 diff --git a/sm2 b/sm2
435 new file mode 160000
436 index 0000000..$head7
437 --- /dev/null
438 +++ b/sm2
439 @@ -0,0 +1 @@
440 +Subproject commit $fullhead7
442 test_cmp expected actual
445 test_expect_success 'setup .git file for sm2' '
446 (cd sm2 &&
447 REAL="$(pwd)/../.real" &&
448 mv .git "$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
461 test_done