docs: give more hints about how "add -e" works
[git/kirr.git] / t / t4041-diff-submodule-option.sh
blob995bdfafecedf6b629acdb3300732a4bb691f23c
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 diff actual - <<-EOF
41 Submodule sm1 0000000...$head1 (new submodule)
42 EOF
45 commit_file sm1 &&
46 head2=$(add_file sm1 foo3)
48 test_expect_success 'modified submodule(forward)' "
49 git diff-index -p --submodule=log HEAD >actual &&
50 diff actual - <<-EOF
51 Submodule sm1 $head1..$head2:
52 > Add foo3
53 EOF
56 test_expect_success 'modified submodule(forward)' "
57 git diff --submodule=log >actual &&
58 diff actual - <<-EOF
59 Submodule sm1 $head1..$head2:
60 > Add foo3
61 EOF
64 test_expect_success 'modified submodule(forward) --submodule' "
65 git diff --submodule >actual &&
66 diff actual - <<-EOF
67 Submodule sm1 $head1..$head2:
68 > Add foo3
69 EOF
72 fullhead1=$(cd sm1; git rev-list --max-count=1 $head1)
73 fullhead2=$(cd sm1; git rev-list --max-count=1 $head2)
74 test_expect_success 'modified submodule(forward) --submodule=short' "
75 git diff --submodule=short >actual &&
76 diff actual - <<-EOF
77 diff --git a/sm1 b/sm1
78 index $head1..$head2 160000
79 --- a/sm1
80 +++ b/sm1
81 @@ -1 +1 @@
82 -Subproject commit $fullhead1
83 +Subproject commit $fullhead2
84 EOF
87 commit_file sm1 &&
88 head3=$(
89 cd sm1 &&
90 git reset --hard HEAD~2 >/dev/null &&
91 git rev-parse --verify HEAD | cut -c1-7
94 test_expect_success 'modified submodule(backward)' "
95 git diff-index -p --submodule=log HEAD >actual &&
96 diff actual - <<-EOF
97 Submodule sm1 $head2..$head3 (rewind):
98 < Add foo3
99 < Add foo2
103 head4=$(add_file sm1 foo4 foo5) &&
104 head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
105 test_expect_success 'modified submodule(backward and forward)' "
106 git diff-index -p --submodule=log HEAD >actual &&
107 diff actual - <<-EOF
108 Submodule sm1 $head2...$head4:
109 > Add foo5
110 > Add foo4
111 < Add foo3
112 < Add foo2
116 commit_file sm1 &&
117 mv sm1 sm1-bak &&
118 echo sm1 >sm1 &&
119 head5=$(git hash-object sm1 | cut -c1-7) &&
120 git add sm1 &&
121 rm -f sm1 &&
122 mv sm1-bak sm1
124 test_expect_success 'typechanged submodule(submodule->blob), --cached' "
125 git diff --submodule=log --cached >actual &&
126 diff actual - <<-EOF
127 Submodule sm1 41fbea9...0000000 (submodule deleted)
128 diff --git a/sm1 b/sm1
129 new file mode 100644
130 index 0000000..9da5fb8
131 --- /dev/null
132 +++ b/sm1
133 @@ -0,0 +1 @@
134 +sm1
138 test_expect_success 'typechanged submodule(submodule->blob)' "
139 git diff --submodule=log >actual &&
140 diff actual - <<-EOF
141 diff --git a/sm1 b/sm1
142 deleted file mode 100644
143 index 9da5fb8..0000000
144 --- a/sm1
145 +++ /dev/null
146 @@ -1 +0,0 @@
147 -sm1
148 Submodule sm1 0000000...$head4 (new submodule)
152 rm -rf sm1 &&
153 git checkout-index sm1
154 test_expect_success 'typechanged submodule(submodule->blob)' "
155 git diff-index -p --submodule=log HEAD >actual &&
156 diff actual - <<-EOF
157 Submodule sm1 $head4...0000000 (submodule deleted)
158 diff --git a/sm1 b/sm1
159 new file mode 100644
160 index 0000000..$head5
161 --- /dev/null
162 +++ b/sm1
163 @@ -0,0 +1 @@
164 +sm1
168 rm -f sm1 &&
169 test_create_repo sm1 &&
170 head6=$(add_file sm1 foo6 foo7)
171 fullhead6=$(cd sm1; git rev-list --max-count=1 $head6)
172 test_expect_success 'nonexistent commit' "
173 git diff-index -p --submodule=log HEAD >actual &&
174 diff actual - <<-EOF
175 Submodule sm1 $head4...$head6 (commits not present)
179 commit_file
180 test_expect_success 'typechanged submodule(blob->submodule)' "
181 git diff-index -p --submodule=log HEAD >actual &&
182 diff actual - <<-EOF
183 diff --git a/sm1 b/sm1
184 deleted file mode 100644
185 index $head5..0000000
186 --- a/sm1
187 +++ /dev/null
188 @@ -1 +0,0 @@
189 -sm1
190 Submodule sm1 0000000...$head6 (new submodule)
194 commit_file sm1 &&
195 test_expect_success 'submodule is up to date' "
196 git diff-index -p --submodule=log HEAD >actual &&
197 diff actual - <<-EOF
201 test_expect_success 'submodule contains untracked content' "
202 echo new > sm1/new-file &&
203 git diff-index -p --submodule=log HEAD >actual &&
204 diff actual - <<-EOF
205 Submodule sm1 contains untracked content
209 test_expect_success 'submodule contains untracked content (untracked ignored)' "
210 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
211 ! test -s actual
214 test_expect_success 'submodule contains untracked content (dirty ignored)' "
215 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
216 ! test -s actual
219 test_expect_success 'submodule contains untracked content (all ignored)' "
220 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
221 ! test -s actual
224 test_expect_success 'submodule contains untracked and modifed content' "
225 echo new > sm1/foo6 &&
226 git diff-index -p --submodule=log HEAD >actual &&
227 diff actual - <<-EOF
228 Submodule sm1 contains untracked content
229 Submodule sm1 contains modified content
233 test_expect_success 'submodule contains untracked and modifed content (untracked ignored)' "
234 echo new > sm1/foo6 &&
235 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
236 diff actual - <<-EOF
237 Submodule sm1 contains modified content
241 test_expect_success 'submodule contains untracked and modifed content (dirty ignored)' "
242 echo new > sm1/foo6 &&
243 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
244 ! test -s actual
247 test_expect_success 'submodule contains untracked and modifed content (all ignored)' "
248 echo new > sm1/foo6 &&
249 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
250 ! test -s actual
253 test_expect_success 'submodule contains modifed content' "
254 rm -f sm1/new-file &&
255 git diff-index -p --submodule=log HEAD >actual &&
256 diff actual - <<-EOF
257 Submodule sm1 contains modified content
261 (cd sm1; git commit -mchange foo6 >/dev/null) &&
262 head8=$(cd sm1; git rev-parse --verify HEAD | cut -c1-7) &&
263 test_expect_success 'submodule is modified' "
264 git diff-index -p --submodule=log HEAD >actual &&
265 diff actual - <<-EOF
266 Submodule sm1 $head6..$head8:
267 > change
271 test_expect_success 'modified submodule contains untracked content' "
272 echo new > sm1/new-file &&
273 git diff-index -p --submodule=log HEAD >actual &&
274 diff actual - <<-EOF
275 Submodule sm1 contains untracked content
276 Submodule sm1 $head6..$head8:
277 > change
281 test_expect_success 'modified submodule contains untracked content (untracked ignored)' "
282 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
283 diff actual - <<-EOF
284 Submodule sm1 $head6..$head8:
285 > change
289 test_expect_success 'modified submodule contains untracked content (dirty ignored)' "
290 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
291 diff actual - <<-EOF
292 Submodule sm1 $head6..$head8:
293 > change
297 test_expect_success 'modified submodule contains untracked content (all ignored)' "
298 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
299 ! test -s actual
302 test_expect_success 'modified submodule contains untracked and modifed content' "
303 echo modification >> sm1/foo6 &&
304 git diff-index -p --submodule=log HEAD >actual &&
305 diff actual - <<-EOF
306 Submodule sm1 contains untracked content
307 Submodule sm1 contains modified content
308 Submodule sm1 $head6..$head8:
309 > change
313 test_expect_success 'modified submodule contains untracked and modifed content (untracked ignored)' "
314 echo modification >> sm1/foo6 &&
315 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
316 diff actual - <<-EOF
317 Submodule sm1 contains modified content
318 Submodule sm1 $head6..$head8:
319 > change
323 test_expect_success 'modified submodule contains untracked and modifed content (dirty ignored)' "
324 echo modification >> sm1/foo6 &&
325 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
326 diff actual - <<-EOF
327 Submodule sm1 $head6..$head8:
328 > change
332 test_expect_success 'modified submodule contains untracked and modifed content (all ignored)' "
333 echo modification >> sm1/foo6 &&
334 git diff-index -p --ignore-submodules --submodule=log HEAD >actual &&
335 ! test -s actual
338 test_expect_success 'modified submodule contains modifed content' "
339 rm -f sm1/new-file &&
340 git diff-index -p --submodule=log HEAD >actual &&
341 diff actual - <<-EOF
342 Submodule sm1 contains modified content
343 Submodule sm1 $head6..$head8:
344 > change
348 rm -rf sm1
349 test_expect_success 'deleted submodule' "
350 git diff-index -p --submodule=log HEAD >actual &&
351 diff actual - <<-EOF
352 Submodule sm1 $head6...0000000 (submodule deleted)
356 test_create_repo sm2 &&
357 head7=$(add_file sm2 foo8 foo9) &&
358 git add sm2
360 test_expect_success 'multiple submodules' "
361 git diff-index -p --submodule=log HEAD >actual &&
362 diff actual - <<-EOF
363 Submodule sm1 $head6...0000000 (submodule deleted)
364 Submodule sm2 0000000...$head7 (new submodule)
368 test_expect_success 'path filter' "
369 git diff-index -p --submodule=log HEAD sm2 >actual &&
370 diff actual - <<-EOF
371 Submodule sm2 0000000...$head7 (new submodule)
375 commit_file sm2
376 test_expect_success 'given commit' "
377 git diff-index -p --submodule=log HEAD^ >actual &&
378 diff actual - <<-EOF
379 Submodule sm1 $head6...0000000 (submodule deleted)
380 Submodule sm2 0000000...$head7 (new submodule)
384 test_expect_success 'given commit --submodule' "
385 git diff-index -p --submodule HEAD^ >actual &&
386 diff actual - <<-EOF
387 Submodule sm1 $head6...0000000 (submodule deleted)
388 Submodule sm2 0000000...$head7 (new submodule)
392 fullhead7=$(cd sm2; git rev-list --max-count=1 $head7)
394 test_expect_success 'given commit --submodule=short' "
395 git diff-index -p --submodule=short HEAD^ >actual &&
396 diff actual - <<-EOF
397 diff --git a/sm1 b/sm1
398 deleted file mode 160000
399 index $head6..0000000
400 --- a/sm1
401 +++ /dev/null
402 @@ -1 +0,0 @@
403 -Subproject commit $fullhead6
404 diff --git a/sm2 b/sm2
405 new file mode 160000
406 index 0000000..$head7
407 --- /dev/null
408 +++ b/sm2
409 @@ -0,0 +1 @@
410 +Subproject commit $fullhead7
414 test_expect_success 'setup .git file for sm2' '
415 (cd sm2 &&
416 REAL="$(pwd)/../.real" &&
417 mv .git "$REAL"
418 echo "gitdir: $REAL" >.git)
421 test_expect_success 'diff --submodule with .git file' '
422 git diff --submodule HEAD^ >actual &&
423 diff actual - <<-EOF
424 Submodule sm1 $head6...0000000 (submodule deleted)
425 Submodule sm2 0000000...$head7 (new submodule)
429 test_done