]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4041-diff-submodule-option.sh
Merge branch 'jk/tag-contains-ab' (early part) into maint
[thirdparty/git.git] / t / t4041-diff-submodule-option.sh
CommitLineData
86140d56
JL
1#!/bin/sh
2#
3# Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin
4#
5
6test_description='Support for verbose submodule differences in git diff
7
8This test tries to verify the sanity of the --submodule option of git diff.
9'
10
11. ./test-lib.sh
12
13add_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"
26}
27commit_file () {
28 test_tick &&
29 git commit "$@" -m "Commit $*" >/dev/null
30}
31
32test_create_repo sm1 &&
33add_file . foo >/dev/null
34
35head1=$(add_file sm1 foo1 foo2)
36
37test_expect_success 'added submodule' "
38 git add sm1 &&
39 git diff-index -p --submodule=log HEAD >actual &&
f8d186bb 40 cat >expected <<-EOF &&
86140d56
JL
41Submodule sm1 0000000...$head1 (new submodule)
42EOF
f8d186bb 43 test_cmp expected actual
86140d56
JL
44"
45
46commit_file sm1 &&
47head2=$(add_file sm1 foo3)
48
49test_expect_success 'modified submodule(forward)' "
50 git diff-index -p --submodule=log HEAD >actual &&
f8d186bb 51 cat >expected <<-EOF &&
86140d56
JL
52Submodule sm1 $head1..$head2:
53 > Add foo3
54EOF
f8d186bb 55 test_cmp expected actual
86140d56
JL
56"
57
58test_expect_success 'modified submodule(forward)' "
59 git diff --submodule=log >actual &&
f8d186bb 60 cat >expected <<-EOF &&
86140d56
JL
61Submodule sm1 $head1..$head2:
62 > Add foo3
63EOF
f8d186bb 64 test_cmp expected actual
86140d56
JL
65"
66
67test_expect_success 'modified submodule(forward) --submodule' "
68 git diff --submodule >actual &&
f8d186bb 69 cat >expected <<-EOF &&
86140d56
JL
70Submodule sm1 $head1..$head2:
71 > Add foo3
72EOF
f8d186bb 73 test_cmp expected actual
86140d56
JL
74"
75
76fullhead1=$(cd sm1; git rev-list --max-count=1 $head1)
77fullhead2=$(cd sm1; git rev-list --max-count=1 $head2)
78test_expect_success 'modified submodule(forward) --submodule=short' "
79 git diff --submodule=short >actual &&
f8d186bb 80 cat >expected <<-EOF &&
86140d56
JL
81diff --git a/sm1 b/sm1
82index $head1..$head2 160000
83--- a/sm1
84+++ b/sm1
85@@ -1 +1 @@
86-Subproject commit $fullhead1
87+Subproject commit $fullhead2
88EOF
f8d186bb 89 test_cmp expected actual
86140d56
JL
90"
91
92commit_file sm1 &&
18a82692
JN
93head3=$(
94 cd sm1 &&
95 git reset --hard HEAD~2 >/dev/null &&
96 git rev-parse --verify HEAD | cut -c1-7
fd4ec4f2 97)
86140d56
JL
98
99test_expect_success 'modified submodule(backward)' "
100 git diff-index -p --submodule=log HEAD >actual &&
f8d186bb 101 cat >expected <<-EOF &&
86140d56
JL
102Submodule sm1 $head2..$head3 (rewind):
103 < Add foo3
104 < Add foo2
105EOF
f8d186bb 106 test_cmp expected actual
86140d56
JL
107"
108
109head4=$(add_file sm1 foo4 foo5) &&
110head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD)
111test_expect_success 'modified submodule(backward and forward)' "
112 git diff-index -p --submodule=log HEAD >actual &&
f8d186bb 113 cat >expected <<-EOF &&
86140d56
JL
114Submodule sm1 $head2...$head4:
115 > Add foo5
116 > Add foo4
117 < Add foo3
118 < Add foo2
119EOF
f8d186bb 120 test_cmp expected actual
86140d56
JL
121"
122
123commit_file sm1 &&
124mv sm1 sm1-bak &&
125echo sm1 >sm1 &&
126head5=$(git hash-object sm1 | cut -c1-7) &&
127git add sm1 &&
128rm -f sm1 &&
129mv sm1-bak sm1
130
131test_expect_success 'typechanged submodule(submodule->blob), --cached' "
132 git diff --submodule=log --cached >actual &&
f8d186bb 133 cat >expected <<-EOF &&
86140d56
JL
134Submodule sm1 41fbea9...0000000 (submodule deleted)
135diff --git a/sm1 b/sm1
136new file mode 100644
137index 0000000..9da5fb8
138--- /dev/null
139+++ b/sm1
140@@ -0,0 +1 @@
141+sm1
142EOF
f8d186bb 143 test_cmp expected actual
86140d56
JL
144"
145
146test_expect_success 'typechanged submodule(submodule->blob)' "
147 git diff --submodule=log >actual &&
f8d186bb 148 cat >expected <<-EOF &&
86140d56
JL
149diff --git a/sm1 b/sm1
150deleted file mode 100644
151index 9da5fb8..0000000
152--- a/sm1
153+++ /dev/null
154@@ -1 +0,0 @@
155-sm1
156Submodule sm1 0000000...$head4 (new submodule)
157EOF
f8d186bb 158 test_cmp expected actual
86140d56
JL
159"
160
161rm -rf sm1 &&
162git checkout-index sm1
163test_expect_success 'typechanged submodule(submodule->blob)' "
164 git diff-index -p --submodule=log HEAD >actual &&
f8d186bb 165 cat >expected <<-EOF &&
86140d56
JL
166Submodule sm1 $head4...0000000 (submodule deleted)
167diff --git a/sm1 b/sm1
168new file mode 100644
169index 0000000..$head5
170--- /dev/null
171+++ b/sm1
172@@ -0,0 +1 @@
173+sm1
174EOF
f8d186bb 175 test_cmp expected actual
86140d56
JL
176"
177
178rm -f sm1 &&
179test_create_repo sm1 &&
180head6=$(add_file sm1 foo6 foo7)
181fullhead6=$(cd sm1; git rev-list --max-count=1 $head6)
182test_expect_success 'nonexistent commit' "
183 git diff-index -p --submodule=log HEAD >actual &&
f8d186bb 184 cat >expected <<-EOF &&
86140d56
JL
185Submodule sm1 $head4...$head6 (commits not present)
186EOF
f8d186bb 187 test_cmp expected actual
86140d56
JL
188"
189
190commit_file
191test_expect_success 'typechanged submodule(blob->submodule)' "
192 git diff-index -p --submodule=log HEAD >actual &&
f8d186bb 193 cat >expected <<-EOF &&
86140d56
JL
194diff --git a/sm1 b/sm1
195deleted file mode 100644
196index $head5..0000000
197--- a/sm1
198+++ /dev/null
199@@ -1 +0,0 @@
200-sm1
201Submodule sm1 0000000...$head6 (new submodule)
202EOF
f8d186bb 203 test_cmp expected actual
86140d56
JL
204"
205
206commit_file sm1 &&
721ceec1
JL
207test_expect_success 'submodule is up to date' "
208 git diff-index -p --submodule=log HEAD >actual &&
f8d186bb 209 cat >expected <<-EOF &&
721ceec1 210EOF
f8d186bb 211 test_cmp expected actual
721ceec1
JL
212"
213
214test_expect_success 'submodule contains untracked content' "
215 echo new > sm1/new-file &&
216 git diff-index -p --submodule=log HEAD >actual &&
f8d186bb 217 cat >expected <<-EOF &&
c7e1a736 218Submodule sm1 contains untracked content
721ceec1 219EOF
f8d186bb 220 test_cmp expected actual
721ceec1
JL
221"
222
dd44d419
JL
223test_expect_success 'submodule contains untracked content (untracked ignored)' "
224 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
6ed7ddaa 225 ! test -s actual
dd44d419
JL
226"
227
228test_expect_success 'submodule contains untracked content (dirty ignored)' "
229 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
6ed7ddaa 230 ! test -s actual
dd44d419
JL
231"
232
233test_expect_success 'submodule contains untracked content (all ignored)' "
234 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
6ed7ddaa 235 ! test -s actual
dd44d419
JL
236"
237
721ceec1
JL
238test_expect_success 'submodule contains untracked and modifed content' "
239 echo new > sm1/foo6 &&
240 git diff-index -p --submodule=log HEAD >actual &&
f8d186bb 241 cat >expected <<-EOF &&
c7e1a736
JL
242Submodule sm1 contains untracked content
243Submodule sm1 contains modified content
721ceec1 244EOF
f8d186bb 245 test_cmp expected actual
721ceec1
JL
246"
247
dd44d419
JL
248test_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 &&
f8d186bb 251 cat >expected <<-EOF &&
dd44d419
JL
252Submodule sm1 contains modified content
253EOF
f8d186bb 254 test_cmp expected actual
dd44d419
JL
255"
256
257test_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 &&
6ed7ddaa 260 ! test -s actual
dd44d419
JL
261"
262
263test_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 &&
6ed7ddaa 266 ! test -s actual
dd44d419
JL
267"
268
721ceec1
JL
269test_expect_success 'submodule contains modifed content' "
270 rm -f sm1/new-file &&
271 git diff-index -p --submodule=log HEAD >actual &&
f8d186bb 272 cat >expected <<-EOF &&
c7e1a736 273Submodule sm1 contains modified content
721ceec1 274EOF
f8d186bb 275 test_cmp expected actual
721ceec1
JL
276"
277
278(cd sm1; git commit -mchange foo6 >/dev/null) &&
279head8=$(cd sm1; git rev-parse --verify HEAD | cut -c1-7) &&
280test_expect_success 'submodule is modified' "
281 git diff-index -p --submodule=log HEAD >actual &&
f8d186bb 282 cat >expected <<-EOF &&
721ceec1
JL
283Submodule sm1 $head6..$head8:
284 > change
285EOF
f8d186bb 286 test_cmp expected actual
721ceec1
JL
287"
288
289test_expect_success 'modified submodule contains untracked content' "
290 echo new > sm1/new-file &&
291 git diff-index -p --submodule=log HEAD >actual &&
f8d186bb 292 cat >expected <<-EOF &&
c7e1a736
JL
293Submodule sm1 contains untracked content
294Submodule sm1 $head6..$head8:
721ceec1
JL
295 > change
296EOF
f8d186bb 297 test_cmp expected actual
721ceec1
JL
298"
299
dd44d419
JL
300test_expect_success 'modified submodule contains untracked content (untracked ignored)' "
301 git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual &&
f8d186bb 302 cat >expected <<-EOF &&
dd44d419
JL
303Submodule sm1 $head6..$head8:
304 > change
305EOF
f8d186bb 306 test_cmp expected actual
dd44d419
JL
307"
308
309test_expect_success 'modified submodule contains untracked content (dirty ignored)' "
310 git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual &&
f8d186bb 311 cat >expected <<-EOF &&
dd44d419
JL
312Submodule sm1 $head6..$head8:
313 > change
314EOF
f8d186bb 315 test_cmp expected actual
dd44d419
JL
316"
317
318test_expect_success 'modified submodule contains untracked content (all ignored)' "
319 git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual &&
6ed7ddaa 320 ! test -s actual
dd44d419
JL
321"
322
721ceec1
JL
323test_expect_success 'modified submodule contains untracked and modifed content' "
324 echo modification >> sm1/foo6 &&
325 git diff-index -p --submodule=log HEAD >actual &&
f8d186bb 326 cat >expected <<-EOF &&
c7e1a736
JL
327Submodule sm1 contains untracked content
328Submodule sm1 contains modified content
329Submodule sm1 $head6..$head8:
721ceec1
JL
330 > change
331EOF
f8d186bb 332 test_cmp expected actual
721ceec1
JL
333"
334
dd44d419
JL
335test_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 &&
f8d186bb 338 cat >expected <<-EOF &&
dd44d419
JL
339Submodule sm1 contains modified content
340Submodule sm1 $head6..$head8:
341 > change
342EOF
f8d186bb 343 test_cmp expected actual
dd44d419
JL
344"
345
346test_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 &&
f8d186bb 349 cat >expected <<-EOF &&
dd44d419
JL
350Submodule sm1 $head6..$head8:
351 > change
352EOF
f8d186bb 353 test_cmp expected actual
dd44d419
JL
354"
355
356test_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 &&
6ed7ddaa 359 ! test -s actual
dd44d419
JL
360"
361
721ceec1
JL
362test_expect_success 'modified submodule contains modifed content' "
363 rm -f sm1/new-file &&
364 git diff-index -p --submodule=log HEAD >actual &&
f8d186bb 365 cat >expected <<-EOF &&
c7e1a736
JL
366Submodule sm1 contains modified content
367Submodule sm1 $head6..$head8:
721ceec1
JL
368 > change
369EOF
f8d186bb 370 test_cmp expected actual
721ceec1
JL
371"
372
86140d56
JL
373rm -rf sm1
374test_expect_success 'deleted submodule' "
375 git diff-index -p --submodule=log HEAD >actual &&
f8d186bb 376 cat >expected <<-EOF &&
86140d56
JL
377Submodule sm1 $head6...0000000 (submodule deleted)
378EOF
f8d186bb 379 test_cmp expected actual
86140d56
JL
380"
381
382test_create_repo sm2 &&
383head7=$(add_file sm2 foo8 foo9) &&
384git add sm2
385
386test_expect_success 'multiple submodules' "
387 git diff-index -p --submodule=log HEAD >actual &&
f8d186bb 388 cat >expected <<-EOF &&
86140d56
JL
389Submodule sm1 $head6...0000000 (submodule deleted)
390Submodule sm2 0000000...$head7 (new submodule)
391EOF
f8d186bb 392 test_cmp expected actual
86140d56
JL
393"
394
395test_expect_success 'path filter' "
396 git diff-index -p --submodule=log HEAD sm2 >actual &&
f8d186bb 397 cat >expected <<-EOF &&
86140d56
JL
398Submodule sm2 0000000...$head7 (new submodule)
399EOF
f8d186bb 400 test_cmp expected actual
86140d56
JL
401"
402
403commit_file sm2
404test_expect_success 'given commit' "
405 git diff-index -p --submodule=log HEAD^ >actual &&
f8d186bb 406 cat >expected <<-EOF &&
86140d56
JL
407Submodule sm1 $head6...0000000 (submodule deleted)
408Submodule sm2 0000000...$head7 (new submodule)
409EOF
f8d186bb 410 test_cmp expected actual
86140d56
JL
411"
412
413test_expect_success 'given commit --submodule' "
414 git diff-index -p --submodule HEAD^ >actual &&
f8d186bb 415 cat >expected <<-EOF &&
86140d56
JL
416Submodule sm1 $head6...0000000 (submodule deleted)
417Submodule sm2 0000000...$head7 (new submodule)
418EOF
f8d186bb 419 test_cmp expected actual
86140d56
JL
420"
421
422fullhead7=$(cd sm2; git rev-list --max-count=1 $head7)
423
424test_expect_success 'given commit --submodule=short' "
425 git diff-index -p --submodule=short HEAD^ >actual &&
f8d186bb 426 cat >expected <<-EOF &&
86140d56
JL
427diff --git a/sm1 b/sm1
428deleted file mode 160000
429index $head6..0000000
430--- a/sm1
431+++ /dev/null
432@@ -1 +0,0 @@
433-Subproject commit $fullhead6
434diff --git a/sm2 b/sm2
435new file mode 160000
436index 0000000..$head7
437--- /dev/null
438+++ b/sm2
439@@ -0,0 +1 @@
440+Subproject commit $fullhead7
441EOF
f8d186bb 442 test_cmp expected actual
86140d56
JL
443"
444
eee49b6c
JL
445test_expect_success 'setup .git file for sm2' '
446 (cd sm2 &&
447 REAL="$(pwd)/../.real" &&
448 mv .git "$REAL"
449 echo "gitdir: $REAL" >.git)
450'
451
452test_expect_success 'diff --submodule with .git file' '
453 git diff --submodule HEAD^ >actual &&
f8d186bb 454 cat >expected <<-EOF &&
eee49b6c
JL
455Submodule sm1 $head6...0000000 (submodule deleted)
456Submodule sm2 0000000...$head7 (new submodule)
457EOF
f8d186bb 458 test_cmp expected actual
eee49b6c
JL
459'
460
86140d56 461test_done