]>
Commit | Line | Data |
---|---|---|
86140d56 JL |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin | |
de6029a2 | 4 | # Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests) |
86140d56 JL |
5 | # |
6 | ||
7 | test_description='Support for verbose submodule differences in git diff | |
8 | ||
9 | This test tries to verify the sanity of the --submodule option of git diff. | |
10 | ' | |
11 | ||
12 | . ./test-lib.sh | |
13 | ||
ee3efaf6 AS |
14 | # Tested non-UTF-8 encoding |
15 | test_encoding="ISO8859-1" | |
16 | ||
de6029a2 AS |
17 | # String "added" in German (translated with Google Translate), encoded in UTF-8, |
18 | # used in sample commit log messages in add_file() function below. | |
19 | added=$(printf "hinzugef\303\274gt") | |
86140d56 | 20 | add_file () { |
2934975f RR |
21 | ( |
22 | cd "$1" && | |
23 | shift && | |
24 | for name | |
25 | do | |
26 | echo "$name" >"$name" && | |
27 | git add "$name" && | |
28 | test_tick && | |
e6ce2be2 PT |
29 | # "git commit -m" would break MinGW, as Windows refuse to pass |
30 | # $test_encoding encoded parameter to git. | |
31 | echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding | | |
32 | git -c "i18n.commitEncoding=$test_encoding" commit -F - | |
2934975f RR |
33 | done >/dev/null && |
34 | git rev-parse --short --verify HEAD | |
35 | ) | |
86140d56 JL |
36 | } |
37 | commit_file () { | |
38 | test_tick && | |
39 | git commit "$@" -m "Commit $*" >/dev/null | |
40 | } | |
41 | ||
42 | test_create_repo sm1 && | |
43 | add_file . foo >/dev/null | |
44 | ||
45 | head1=$(add_file sm1 foo1 foo2) | |
20fa5385 | 46 | fullhead1=$(cd sm1; git rev-parse --verify HEAD) |
86140d56 | 47 | |
a1549f9b | 48 | test_expect_success 'added submodule' ' |
86140d56 JL |
49 | git add sm1 && |
50 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 51 | cat >expected <<-EOF && |
a1549f9b RR |
52 | Submodule sm1 0000000...$head1 (new submodule) |
53 | EOF | |
f8d186bb | 54 | test_cmp expected actual |
a1549f9b | 55 | ' |
86140d56 | 56 | |
a1549f9b | 57 | test_expect_success 'added submodule, set diff.submodule' ' |
c47ef57c RR |
58 | git config diff.submodule log && |
59 | git add sm1 && | |
60 | git diff --cached >actual && | |
61 | cat >expected <<-EOF && | |
a1549f9b RR |
62 | Submodule sm1 0000000...$head1 (new submodule) |
63 | EOF | |
c47ef57c RR |
64 | git config --unset diff.submodule && |
65 | test_cmp expected actual | |
a1549f9b | 66 | ' |
c47ef57c | 67 | |
a1549f9b | 68 | test_expect_success '--submodule=short overrides diff.submodule' ' |
c47ef57c RR |
69 | test_config diff.submodule log && |
70 | git add sm1 && | |
71 | git diff --submodule=short --cached >actual && | |
72 | cat >expected <<-EOF && | |
a1549f9b RR |
73 | diff --git a/sm1 b/sm1 |
74 | new file mode 160000 | |
75 | index 0000000..$head1 | |
76 | --- /dev/null | |
77 | +++ b/sm1 | |
78 | @@ -0,0 +1 @@ | |
79 | +Subproject commit $fullhead1 | |
80 | EOF | |
c47ef57c | 81 | test_cmp expected actual |
a1549f9b | 82 | ' |
c47ef57c | 83 | |
d9c552f1 JK |
84 | test_expect_success 'diff.submodule does not affect plumbing' ' |
85 | test_config diff.submodule log && | |
86 | git diff-index -p HEAD >actual && | |
87 | cat >expected <<-EOF && | |
88 | diff --git a/sm1 b/sm1 | |
89 | new file mode 160000 | |
3b13af9d | 90 | index 0000000..$head1 |
d9c552f1 JK |
91 | --- /dev/null |
92 | +++ b/sm1 | |
93 | @@ -0,0 +1 @@ | |
94 | +Subproject commit $fullhead1 | |
95 | EOF | |
96 | test_cmp expected actual | |
97 | ' | |
98 | ||
86140d56 JL |
99 | commit_file sm1 && |
100 | head2=$(add_file sm1 foo3) | |
101 | ||
ecaee805 | 102 | test_expect_success 'modified submodule(forward)' ' |
86140d56 | 103 | git diff-index -p --submodule=log HEAD >actual && |
f8d186bb | 104 | cat >expected <<-EOF && |
a1549f9b | 105 | Submodule sm1 $head1..$head2: |
de6029a2 | 106 | > Add foo3 ($added foo3) |
a1549f9b | 107 | EOF |
f8d186bb | 108 | test_cmp expected actual |
a1549f9b | 109 | ' |
86140d56 | 110 | |
ecaee805 | 111 | test_expect_success 'modified submodule(forward)' ' |
86140d56 | 112 | git diff --submodule=log >actual && |
f8d186bb | 113 | cat >expected <<-EOF && |
a1549f9b | 114 | Submodule sm1 $head1..$head2: |
de6029a2 | 115 | > Add foo3 ($added foo3) |
a1549f9b | 116 | EOF |
f8d186bb | 117 | test_cmp expected actual |
a1549f9b | 118 | ' |
86140d56 | 119 | |
ecaee805 | 120 | test_expect_success 'modified submodule(forward) --submodule' ' |
86140d56 | 121 | git diff --submodule >actual && |
f8d186bb | 122 | cat >expected <<-EOF && |
a1549f9b | 123 | Submodule sm1 $head1..$head2: |
de6029a2 | 124 | > Add foo3 ($added foo3) |
a1549f9b | 125 | EOF |
f8d186bb | 126 | test_cmp expected actual |
a1549f9b | 127 | ' |
86140d56 | 128 | |
20fa5385 | 129 | fullhead2=$(cd sm1; git rev-parse --verify HEAD) |
a1549f9b | 130 | test_expect_success 'modified submodule(forward) --submodule=short' ' |
86140d56 | 131 | git diff --submodule=short >actual && |
f8d186bb | 132 | cat >expected <<-EOF && |
a1549f9b RR |
133 | diff --git a/sm1 b/sm1 |
134 | index $head1..$head2 160000 | |
135 | --- a/sm1 | |
136 | +++ b/sm1 | |
137 | @@ -1 +1 @@ | |
138 | -Subproject commit $fullhead1 | |
139 | +Subproject commit $fullhead2 | |
140 | EOF | |
f8d186bb | 141 | test_cmp expected actual |
a1549f9b | 142 | ' |
86140d56 JL |
143 | |
144 | commit_file sm1 && | |
18a82692 JN |
145 | head3=$( |
146 | cd sm1 && | |
147 | git reset --hard HEAD~2 >/dev/null && | |
20fa5385 | 148 | git rev-parse --short --verify HEAD |
fd4ec4f2 | 149 | ) |
86140d56 | 150 | |
ecaee805 | 151 | test_expect_success 'modified submodule(backward)' ' |
86140d56 | 152 | git diff-index -p --submodule=log HEAD >actual && |
f8d186bb | 153 | cat >expected <<-EOF && |
a1549f9b | 154 | Submodule sm1 $head2..$head3 (rewind): |
de6029a2 AS |
155 | < Add foo3 ($added foo3) |
156 | < Add foo2 ($added foo2) | |
a1549f9b | 157 | EOF |
f8d186bb | 158 | test_cmp expected actual |
a1549f9b | 159 | ' |
86140d56 | 160 | |
a1549f9b | 161 | head4=$(add_file sm1 foo4 foo5) |
ecaee805 | 162 | test_expect_success 'modified submodule(backward and forward)' ' |
86140d56 | 163 | git diff-index -p --submodule=log HEAD >actual && |
f8d186bb | 164 | cat >expected <<-EOF && |
a1549f9b | 165 | Submodule sm1 $head2...$head4: |
de6029a2 AS |
166 | > Add foo5 ($added foo5) |
167 | > Add foo4 ($added foo4) | |
168 | < Add foo3 ($added foo3) | |
169 | < Add foo2 ($added foo2) | |
a1549f9b | 170 | EOF |
f8d186bb | 171 | test_cmp expected actual |
a1549f9b | 172 | ' |
86140d56 JL |
173 | |
174 | commit_file sm1 && | |
175 | mv sm1 sm1-bak && | |
176 | echo sm1 >sm1 && | |
177 | head5=$(git hash-object sm1 | cut -c1-7) && | |
178 | git add sm1 && | |
179 | rm -f sm1 && | |
180 | mv sm1-bak sm1 | |
181 | ||
a1549f9b | 182 | test_expect_success 'typechanged submodule(submodule->blob), --cached' ' |
86140d56 | 183 | git diff --submodule=log --cached >actual && |
f8d186bb | 184 | cat >expected <<-EOF && |
a1549f9b RR |
185 | Submodule sm1 $head4...0000000 (submodule deleted) |
186 | diff --git a/sm1 b/sm1 | |
187 | new file mode 100644 | |
188 | index 0000000..$head5 | |
189 | --- /dev/null | |
190 | +++ b/sm1 | |
191 | @@ -0,0 +1 @@ | |
192 | +sm1 | |
193 | EOF | |
f8d186bb | 194 | test_cmp expected actual |
a1549f9b | 195 | ' |
86140d56 | 196 | |
a1549f9b | 197 | test_expect_success 'typechanged submodule(submodule->blob)' ' |
86140d56 | 198 | git diff --submodule=log >actual && |
f8d186bb | 199 | cat >expected <<-EOF && |
a1549f9b RR |
200 | diff --git a/sm1 b/sm1 |
201 | deleted file mode 100644 | |
202 | index $head5..0000000 | |
203 | --- a/sm1 | |
204 | +++ /dev/null | |
205 | @@ -1 +0,0 @@ | |
206 | -sm1 | |
207 | Submodule sm1 0000000...$head4 (new submodule) | |
208 | EOF | |
f8d186bb | 209 | test_cmp expected actual |
a1549f9b | 210 | ' |
86140d56 JL |
211 | |
212 | rm -rf sm1 && | |
213 | git checkout-index sm1 | |
a1549f9b | 214 | test_expect_success 'typechanged submodule(submodule->blob)' ' |
86140d56 | 215 | git diff-index -p --submodule=log HEAD >actual && |
f8d186bb | 216 | cat >expected <<-EOF && |
a1549f9b RR |
217 | Submodule sm1 $head4...0000000 (submodule deleted) |
218 | diff --git a/sm1 b/sm1 | |
219 | new file mode 100644 | |
220 | index 0000000..$head5 | |
221 | --- /dev/null | |
222 | +++ b/sm1 | |
223 | @@ -0,0 +1 @@ | |
224 | +sm1 | |
225 | EOF | |
f8d186bb | 226 | test_cmp expected actual |
a1549f9b | 227 | ' |
86140d56 JL |
228 | |
229 | rm -f sm1 && | |
230 | test_create_repo sm1 && | |
231 | head6=$(add_file sm1 foo6 foo7) | |
20fa5385 | 232 | fullhead6=$(cd sm1; git rev-parse --verify HEAD) |
a1549f9b | 233 | test_expect_success 'nonexistent commit' ' |
86140d56 | 234 | git diff-index -p --submodule=log HEAD >actual && |
f8d186bb | 235 | cat >expected <<-EOF && |
a1549f9b RR |
236 | Submodule sm1 $head4...$head6 (commits not present) |
237 | EOF | |
f8d186bb | 238 | test_cmp expected actual |
a1549f9b | 239 | ' |
86140d56 JL |
240 | |
241 | commit_file | |
a1549f9b | 242 | test_expect_success 'typechanged submodule(blob->submodule)' ' |
86140d56 | 243 | git diff-index -p --submodule=log HEAD >actual && |
f8d186bb | 244 | cat >expected <<-EOF && |
a1549f9b RR |
245 | diff --git a/sm1 b/sm1 |
246 | deleted file mode 100644 | |
247 | index $head5..0000000 | |
248 | --- a/sm1 | |
249 | +++ /dev/null | |
250 | @@ -1 +0,0 @@ | |
251 | -sm1 | |
252 | Submodule sm1 0000000...$head6 (new submodule) | |
253 | EOF | |
f8d186bb | 254 | test_cmp expected actual |
a1549f9b | 255 | ' |
86140d56 JL |
256 | |
257 | commit_file sm1 && | |
a1549f9b | 258 | test_expect_success 'submodule is up to date' ' |
721ceec1 | 259 | git diff-index -p --submodule=log HEAD >actual && |
1c5e94f4 | 260 | test_must_be_empty actual |
a1549f9b | 261 | ' |
721ceec1 | 262 | |
a1549f9b | 263 | test_expect_success 'submodule contains untracked content' ' |
721ceec1 JL |
264 | echo new > sm1/new-file && |
265 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 266 | cat >expected <<-EOF && |
a1549f9b RR |
267 | Submodule sm1 contains untracked content |
268 | EOF | |
f8d186bb | 269 | test_cmp expected actual |
a1549f9b | 270 | ' |
721ceec1 | 271 | |
a1549f9b | 272 | test_expect_success 'submodule contains untracked content (untracked ignored)' ' |
dd44d419 | 273 | git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual && |
ec10b018 | 274 | test_must_be_empty actual |
a1549f9b | 275 | ' |
dd44d419 | 276 | |
a1549f9b | 277 | test_expect_success 'submodule contains untracked content (dirty ignored)' ' |
dd44d419 | 278 | git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual && |
ec10b018 | 279 | test_must_be_empty actual |
a1549f9b | 280 | ' |
dd44d419 | 281 | |
a1549f9b | 282 | test_expect_success 'submodule contains untracked content (all ignored)' ' |
dd44d419 | 283 | git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual && |
ec10b018 | 284 | test_must_be_empty actual |
a1549f9b | 285 | ' |
dd44d419 | 286 | |
a1549f9b | 287 | test_expect_success 'submodule contains untracked and modifed content' ' |
721ceec1 JL |
288 | echo new > sm1/foo6 && |
289 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 290 | cat >expected <<-EOF && |
a1549f9b RR |
291 | Submodule sm1 contains untracked content |
292 | Submodule sm1 contains modified content | |
293 | EOF | |
f8d186bb | 294 | test_cmp expected actual |
a1549f9b | 295 | ' |
721ceec1 | 296 | |
a1549f9b | 297 | test_expect_success 'submodule contains untracked and modifed content (untracked ignored)' ' |
dd44d419 JL |
298 | echo new > sm1/foo6 && |
299 | git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual && | |
f8d186bb | 300 | cat >expected <<-EOF && |
a1549f9b RR |
301 | Submodule sm1 contains modified content |
302 | EOF | |
f8d186bb | 303 | test_cmp expected actual |
a1549f9b | 304 | ' |
dd44d419 | 305 | |
a1549f9b | 306 | test_expect_success 'submodule contains untracked and modifed content (dirty ignored)' ' |
dd44d419 JL |
307 | echo new > sm1/foo6 && |
308 | git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual && | |
ec10b018 | 309 | test_must_be_empty actual |
a1549f9b | 310 | ' |
dd44d419 | 311 | |
a1549f9b | 312 | test_expect_success 'submodule contains untracked and modifed content (all ignored)' ' |
dd44d419 JL |
313 | echo new > sm1/foo6 && |
314 | git diff-index -p --ignore-submodules --submodule=log HEAD >actual && | |
ec10b018 | 315 | test_must_be_empty actual |
a1549f9b | 316 | ' |
dd44d419 | 317 | |
a1549f9b | 318 | test_expect_success 'submodule contains modifed content' ' |
721ceec1 JL |
319 | rm -f sm1/new-file && |
320 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 321 | cat >expected <<-EOF && |
a1549f9b RR |
322 | Submodule sm1 contains modified content |
323 | EOF | |
f8d186bb | 324 | test_cmp expected actual |
a1549f9b | 325 | ' |
721ceec1 JL |
326 | |
327 | (cd sm1; git commit -mchange foo6 >/dev/null) && | |
20fa5385 | 328 | head8=$(cd sm1; git rev-parse --short --verify HEAD) && |
a1549f9b | 329 | test_expect_success 'submodule is modified' ' |
721ceec1 | 330 | git diff-index -p --submodule=log HEAD >actual && |
f8d186bb | 331 | cat >expected <<-EOF && |
a1549f9b RR |
332 | Submodule sm1 $head6..$head8: |
333 | > change | |
334 | EOF | |
f8d186bb | 335 | test_cmp expected actual |
a1549f9b | 336 | ' |
721ceec1 | 337 | |
a1549f9b | 338 | test_expect_success 'modified submodule contains untracked content' ' |
721ceec1 JL |
339 | echo new > sm1/new-file && |
340 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 341 | cat >expected <<-EOF && |
a1549f9b RR |
342 | Submodule sm1 contains untracked content |
343 | Submodule sm1 $head6..$head8: | |
344 | > change | |
345 | EOF | |
f8d186bb | 346 | test_cmp expected actual |
a1549f9b | 347 | ' |
721ceec1 | 348 | |
a1549f9b | 349 | test_expect_success 'modified submodule contains untracked content (untracked ignored)' ' |
dd44d419 | 350 | git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual && |
f8d186bb | 351 | cat >expected <<-EOF && |
a1549f9b RR |
352 | Submodule sm1 $head6..$head8: |
353 | > change | |
354 | EOF | |
f8d186bb | 355 | test_cmp expected actual |
a1549f9b | 356 | ' |
dd44d419 | 357 | |
a1549f9b | 358 | test_expect_success 'modified submodule contains untracked content (dirty ignored)' ' |
dd44d419 | 359 | git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual && |
f8d186bb | 360 | cat >expected <<-EOF && |
a1549f9b RR |
361 | Submodule sm1 $head6..$head8: |
362 | > change | |
363 | EOF | |
f8d186bb | 364 | test_cmp expected actual |
a1549f9b | 365 | ' |
dd44d419 | 366 | |
a1549f9b | 367 | test_expect_success 'modified submodule contains untracked content (all ignored)' ' |
dd44d419 | 368 | git diff-index -p --ignore-submodules=all --submodule=log HEAD >actual && |
ec10b018 | 369 | test_must_be_empty actual |
a1549f9b | 370 | ' |
dd44d419 | 371 | |
a1549f9b | 372 | test_expect_success 'modified submodule contains untracked and modifed content' ' |
721ceec1 JL |
373 | echo modification >> sm1/foo6 && |
374 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 375 | cat >expected <<-EOF && |
a1549f9b RR |
376 | Submodule sm1 contains untracked content |
377 | Submodule sm1 contains modified content | |
378 | Submodule sm1 $head6..$head8: | |
379 | > change | |
380 | EOF | |
f8d186bb | 381 | test_cmp expected actual |
a1549f9b | 382 | ' |
721ceec1 | 383 | |
a1549f9b | 384 | test_expect_success 'modified submodule contains untracked and modifed content (untracked ignored)' ' |
dd44d419 JL |
385 | echo modification >> sm1/foo6 && |
386 | git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual && | |
f8d186bb | 387 | cat >expected <<-EOF && |
a1549f9b RR |
388 | Submodule sm1 contains modified content |
389 | Submodule sm1 $head6..$head8: | |
390 | > change | |
391 | EOF | |
f8d186bb | 392 | test_cmp expected actual |
a1549f9b | 393 | ' |
dd44d419 | 394 | |
a1549f9b | 395 | test_expect_success 'modified submodule contains untracked and modifed content (dirty ignored)' ' |
dd44d419 JL |
396 | echo modification >> sm1/foo6 && |
397 | git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual && | |
f8d186bb | 398 | cat >expected <<-EOF && |
a1549f9b RR |
399 | Submodule sm1 $head6..$head8: |
400 | > change | |
401 | EOF | |
f8d186bb | 402 | test_cmp expected actual |
a1549f9b | 403 | ' |
dd44d419 | 404 | |
a1549f9b | 405 | test_expect_success 'modified submodule contains untracked and modifed content (all ignored)' ' |
dd44d419 JL |
406 | echo modification >> sm1/foo6 && |
407 | git diff-index -p --ignore-submodules --submodule=log HEAD >actual && | |
ec10b018 | 408 | test_must_be_empty actual |
a1549f9b | 409 | ' |
dd44d419 | 410 | |
a1549f9b | 411 | test_expect_success 'modified submodule contains modifed content' ' |
721ceec1 JL |
412 | rm -f sm1/new-file && |
413 | git diff-index -p --submodule=log HEAD >actual && | |
f8d186bb | 414 | cat >expected <<-EOF && |
a1549f9b RR |
415 | Submodule sm1 contains modified content |
416 | Submodule sm1 $head6..$head8: | |
417 | > change | |
418 | EOF | |
f8d186bb | 419 | test_cmp expected actual |
a1549f9b | 420 | ' |
721ceec1 | 421 | |
86140d56 | 422 | rm -rf sm1 |
a1549f9b | 423 | test_expect_success 'deleted submodule' ' |
86140d56 | 424 | git diff-index -p --submodule=log HEAD >actual && |
f8d186bb | 425 | cat >expected <<-EOF && |
a1549f9b RR |
426 | Submodule sm1 $head6...0000000 (submodule deleted) |
427 | EOF | |
f8d186bb | 428 | test_cmp expected actual |
a1549f9b | 429 | ' |
86140d56 | 430 | |
17f2f88c JK |
431 | test_expect_success 'create second submodule' ' |
432 | test_create_repo sm2 && | |
433 | head7=$(add_file sm2 foo8 foo9) && | |
434 | git add sm2 | |
435 | ' | |
86140d56 | 436 | |
a1549f9b | 437 | test_expect_success 'multiple submodules' ' |
86140d56 | 438 | git diff-index -p --submodule=log HEAD >actual && |
f8d186bb | 439 | cat >expected <<-EOF && |
a1549f9b RR |
440 | Submodule sm1 $head6...0000000 (submodule deleted) |
441 | Submodule sm2 0000000...$head7 (new submodule) | |
442 | EOF | |
f8d186bb | 443 | test_cmp expected actual |
a1549f9b | 444 | ' |
86140d56 | 445 | |
a1549f9b | 446 | test_expect_success 'path filter' ' |
86140d56 | 447 | git diff-index -p --submodule=log HEAD sm2 >actual && |
f8d186bb | 448 | cat >expected <<-EOF && |
a1549f9b RR |
449 | Submodule sm2 0000000...$head7 (new submodule) |
450 | EOF | |
f8d186bb | 451 | test_cmp expected actual |
a1549f9b | 452 | ' |
86140d56 JL |
453 | |
454 | commit_file sm2 | |
a1549f9b | 455 | test_expect_success 'given commit' ' |
86140d56 | 456 | git diff-index -p --submodule=log HEAD^ >actual && |
f8d186bb | 457 | cat >expected <<-EOF && |
a1549f9b RR |
458 | Submodule sm1 $head6...0000000 (submodule deleted) |
459 | Submodule sm2 0000000...$head7 (new submodule) | |
460 | EOF | |
f8d186bb | 461 | test_cmp expected actual |
a1549f9b | 462 | ' |
86140d56 | 463 | |
a1549f9b | 464 | test_expect_success 'given commit --submodule' ' |
86140d56 | 465 | git diff-index -p --submodule HEAD^ >actual && |
f8d186bb | 466 | cat >expected <<-EOF && |
a1549f9b RR |
467 | Submodule sm1 $head6...0000000 (submodule deleted) |
468 | Submodule sm2 0000000...$head7 (new submodule) | |
469 | EOF | |
f8d186bb | 470 | test_cmp expected actual |
a1549f9b | 471 | ' |
86140d56 | 472 | |
20fa5385 | 473 | fullhead7=$(cd sm2; git rev-parse --verify HEAD) |
86140d56 | 474 | |
a1549f9b | 475 | test_expect_success 'given commit --submodule=short' ' |
86140d56 | 476 | git diff-index -p --submodule=short HEAD^ >actual && |
f8d186bb | 477 | cat >expected <<-EOF && |
a1549f9b RR |
478 | diff --git a/sm1 b/sm1 |
479 | deleted file mode 160000 | |
480 | index $head6..0000000 | |
481 | --- a/sm1 | |
482 | +++ /dev/null | |
483 | @@ -1 +0,0 @@ | |
484 | -Subproject commit $fullhead6 | |
485 | diff --git a/sm2 b/sm2 | |
486 | new file mode 160000 | |
487 | index 0000000..$head7 | |
488 | --- /dev/null | |
489 | +++ b/sm2 | |
490 | @@ -0,0 +1 @@ | |
491 | +Subproject commit $fullhead7 | |
492 | EOF | |
493 | test_cmp expected actual | |
494 | ' | |
86140d56 | 495 | |
eee49b6c JL |
496 | test_expect_success 'setup .git file for sm2' ' |
497 | (cd sm2 && | |
498 | REAL="$(pwd)/../.real" && | |
f957f03b | 499 | mv .git "$REAL" && |
eee49b6c JL |
500 | echo "gitdir: $REAL" >.git) |
501 | ' | |
502 | ||
503 | test_expect_success 'diff --submodule with .git file' ' | |
504 | git diff --submodule HEAD^ >actual && | |
f8d186bb | 505 | cat >expected <<-EOF && |
a1549f9b RR |
506 | Submodule sm1 $head6...0000000 (submodule deleted) |
507 | Submodule sm2 0000000...$head7 (new submodule) | |
508 | EOF | |
f8d186bb | 509 | test_cmp expected actual |
eee49b6c JL |
510 | ' |
511 | ||
5e73633d HV |
512 | test_expect_success 'diff --submodule with objects referenced by alternates' ' |
513 | mkdir sub_alt && | |
514 | (cd sub_alt && | |
515 | git init && | |
516 | echo a >a && | |
517 | git add a && | |
518 | git commit -m a | |
519 | ) && | |
520 | mkdir super && | |
521 | (cd super && | |
522 | git clone -s ../sub_alt sub && | |
523 | git init && | |
524 | git add sub && | |
525 | git commit -m "sub a" | |
526 | ) && | |
527 | (cd sub_alt && | |
f957f03b | 528 | sha1_before=$(git rev-parse --short HEAD) && |
5e73633d HV |
529 | echo b >b && |
530 | git add b && | |
99094a7a JK |
531 | git commit -m b && |
532 | sha1_after=$(git rev-parse --short HEAD) && | |
533 | { | |
534 | echo "Submodule sub $sha1_before..$sha1_after:" && | |
535 | echo " > b" | |
536 | } >../expected | |
5e73633d HV |
537 | ) && |
538 | (cd super && | |
539 | (cd sub && | |
540 | git fetch && | |
541 | git checkout origin/master | |
542 | ) && | |
543 | git diff --submodule > ../actual | |
60687de5 | 544 | ) && |
5e73633d HV |
545 | test_cmp expected actual |
546 | ' | |
547 | ||
86140d56 | 548 | test_done |