fast-import: filemodify after M 040000 <tree> "" crashes
[git/git.git] / t / t9300-fast-import.sh
CommitLineData
50aee995
SP
1#!/bin/sh
2#
3# Copyright (c) 2007 Shawn Pearce
4#
5
eaa2a6fc 6test_description='test git fast-import utility'
50aee995 7. ./test-lib.sh
bfdbee98 8. "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
50aee995 9
8232dc42
SP
10file2_data='file2
11second line of EOF'
12
13file3_data='EOF
14in 3rd file
15 END'
16
17file4_data=abcd
18file4_len=4
19
b715cfbb
SP
20file5_data='an inline file.
21 we should see it later.'
22
23file6_data='#!/bin/sh
24echo "$@"'
25
50aee995
SP
26###
27### series A
28###
29
30test_tick
31cat >input <<INPUT_END
32blob
33mark :2
34data <<EOF
8232dc42 35$file2_data
50aee995
SP
36EOF
37
38blob
39mark :3
40data <<END
8232dc42 41$file3_data
50aee995
SP
42END
43
44blob
45mark :4
8232dc42
SP
46data $file4_len
47$file4_data
50aee995
SP
48commit refs/heads/master
49mark :5
50committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
51data <<COMMIT
52initial
53COMMIT
54
55M 644 :2 file2
56M 644 :3 file3
57M 755 :4 file4
58
88fbf67b
JH
59tag series-A
60from :5
61data <<EOF
62An annotated tag without a tagger
63EOF
64
50aee995
SP
65INPUT_END
66test_expect_success \
67 'A: create pack from stdin' \
eaa2a6fc 68 'git fast-import --export-marks=marks.out <input &&
5be60078 69 git whatchanged master'
50aee995
SP
70test_expect_success \
71 'A: verify pack' \
5be60078 72 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
50aee995
SP
73
74cat >expect <<EOF
75author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
76committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
77
78initial
79EOF
80test_expect_success \
81 'A: verify commit' \
5be60078 82 'git cat-file commit master | sed 1d >actual &&
3af82863 83 test_cmp expect actual'
50aee995
SP
84
85cat >expect <<EOF
86100644 blob file2
87100644 blob file3
88100755 blob file4
89EOF
90test_expect_success \
91 'A: verify tree' \
5be60078 92 'git cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
3af82863 93 test_cmp expect actual'
50aee995 94
8232dc42 95echo "$file2_data" >expect
50aee995
SP
96test_expect_success \
97 'A: verify file2' \
3af82863 98 'git cat-file blob master:file2 >actual && test_cmp expect actual'
50aee995 99
8232dc42 100echo "$file3_data" >expect
50aee995
SP
101test_expect_success \
102 'A: verify file3' \
3af82863 103 'git cat-file blob master:file3 >actual && test_cmp expect actual'
50aee995 104
8232dc42 105printf "$file4_data" >expect
50aee995
SP
106test_expect_success \
107 'A: verify file4' \
3af82863 108 'git cat-file blob master:file4 >actual && test_cmp expect actual'
50aee995 109
88fbf67b
JH
110cat >expect <<EOF
111object $(git rev-parse refs/heads/master)
112type commit
113tag series-A
114
115An annotated tag without a tagger
116EOF
117test_expect_success 'A: verify tag/series-A' '
118 git cat-file tag tags/series-A >actual &&
119 test_cmp expect actual
120'
121
50aee995 122cat >expect <<EOF
5be60078
JH
123:2 `git rev-parse --verify master:file2`
124:3 `git rev-parse --verify master:file3`
125:4 `git rev-parse --verify master:file4`
126:5 `git rev-parse --verify master^0`
50aee995
SP
127EOF
128test_expect_success \
129 'A: verify marks output' \
3af82863 130 'test_cmp expect marks.out'
50aee995 131
e8438420
SP
132test_expect_success \
133 'A: verify marks import' \
eaa2a6fc 134 'git fast-import \
e8438420
SP
135 --import-marks=marks.out \
136 --export-marks=marks.new \
137 </dev/null &&
3af82863 138 test_cmp expect marks.new'
e8438420 139
aac65ed1
SP
140test_tick
141cat >input <<INPUT_END
142commit refs/heads/verify--import-marks
143committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
144data <<COMMIT
145recreate from :5
146COMMIT
147
148from :5
149M 755 :2 copy-of-file2
150
151INPUT_END
152test_expect_success \
153 'A: verify marks import does not crash' \
eaa2a6fc 154 'git fast-import --import-marks=marks.out <input &&
5be60078 155 git whatchanged verify--import-marks'
aac65ed1
SP
156test_expect_success \
157 'A: verify pack' \
5be60078 158 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
aac65ed1
SP
159cat >expect <<EOF
160:000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2
161EOF
5be60078 162git diff-tree -M -r master verify--import-marks >actual
aac65ed1
SP
163test_expect_success \
164 'A: verify diff' \
165 'compare_diff_raw expect actual &&
5be60078
JH
166 test `git rev-parse --verify master:file2` \
167 = `git rev-parse --verify verify--import-marks:copy-of-file2`'
aac65ed1 168
7e7db5e4
RH
169test_tick
170mt=$(git hash-object --stdin < /dev/null)
171: >input.blob
172: >marks.exp
173: >tree.exp
174
175cat >input.commit <<EOF
176commit refs/heads/verify--dump-marks
177committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
178data <<COMMIT
179test the sparse array dumping routines with exponentially growing marks
180COMMIT
181EOF
182
183i=0
184l=4
185m=6
186n=7
187while test "$i" -lt 27; do
188 cat >>input.blob <<EOF
189blob
190mark :$l
191data 0
192blob
193mark :$m
194data 0
195blob
196mark :$n
197data 0
198EOF
199 echo "M 100644 :$l l$i" >>input.commit
200 echo "M 100644 :$m m$i" >>input.commit
201 echo "M 100644 :$n n$i" >>input.commit
202
203 echo ":$l $mt" >>marks.exp
204 echo ":$m $mt" >>marks.exp
205 echo ":$n $mt" >>marks.exp
206
207 printf "100644 blob $mt\tl$i\n" >>tree.exp
208 printf "100644 blob $mt\tm$i\n" >>tree.exp
209 printf "100644 blob $mt\tn$i\n" >>tree.exp
210
211 l=$(($l + $l))
212 m=$(($m + $m))
213 n=$(($l + $n))
214
215 i=$((1 + $i))
216done
217
218sort tree.exp > tree.exp_s
219
220test_expect_success 'A: export marks with large values' '
221 cat input.blob input.commit | git fast-import --export-marks=marks.large &&
222 git ls-tree refs/heads/verify--dump-marks >tree.out &&
223 test_cmp tree.exp_s tree.out &&
224 test_cmp marks.exp marks.large'
225
50aee995
SP
226###
227### series B
228###
229
230test_tick
231cat >input <<INPUT_END
232commit refs/heads/branch
233mark :1
234committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
235data <<COMMIT
236corrupt
237COMMIT
238
239from refs/heads/master
240M 755 0000000000000000000000000000000000000001 zero1
241
242INPUT_END
41ac414e 243test_expect_success 'B: fail on invalid blob sha1' '
eaa2a6fc 244 test_must_fail git fast-import <input
41ac414e 245'
50aee995
SP
246rm -f .git/objects/pack_* .git/objects/index_*
247
ea08a6fd
SP
248cat >input <<INPUT_END
249commit .badbranchname
250committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
251data <<COMMIT
252corrupt
253COMMIT
254
255from refs/heads/master
256
257INPUT_END
41ac414e 258test_expect_success 'B: fail on invalid branch name ".badbranchname"' '
eaa2a6fc 259 test_must_fail git fast-import <input
41ac414e 260'
ea08a6fd
SP
261rm -f .git/objects/pack_* .git/objects/index_*
262
263cat >input <<INPUT_END
264commit bad[branch]name
265committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
266data <<COMMIT
267corrupt
268COMMIT
269
270from refs/heads/master
271
272INPUT_END
41ac414e 273test_expect_success 'B: fail on invalid branch name "bad[branch]name"' '
eaa2a6fc 274 test_must_fail git fast-import <input
41ac414e 275'
ea08a6fd
SP
276rm -f .git/objects/pack_* .git/objects/index_*
277
278cat >input <<INPUT_END
279commit TEMP_TAG
280committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
281data <<COMMIT
282tag base
283COMMIT
284
285from refs/heads/master
286
287INPUT_END
288test_expect_success \
289 'B: accept branch name "TEMP_TAG"' \
eaa2a6fc 290 'git fast-import <input &&
ea08a6fd
SP
291 test -f .git/TEMP_TAG &&
292 test `git rev-parse master` = `git rev-parse TEMP_TAG^`'
293rm -f .git/TEMP_TAG
294
50aee995
SP
295###
296### series C
297###
298
eaa2a6fc 299newf=`echo hi newf | git hash-object -w --stdin`
5be60078 300oldf=`git rev-parse --verify master:file2`
50aee995
SP
301test_tick
302cat >input <<INPUT_END
303commit refs/heads/branch
304committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
305data <<COMMIT
306second
307COMMIT
308
309from refs/heads/master
310M 644 $oldf file2/oldf
311M 755 $newf file2/newf
312D file3
313
314INPUT_END
315test_expect_success \
316 'C: incremental import create pack from stdin' \
eaa2a6fc 317 'git fast-import <input &&
5be60078 318 git whatchanged branch'
50aee995
SP
319test_expect_success \
320 'C: verify pack' \
5be60078 321 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
50aee995
SP
322test_expect_success \
323 'C: validate reuse existing blob' \
5be60078
JH
324 'test $newf = `git rev-parse --verify branch:file2/newf`
325 test $oldf = `git rev-parse --verify branch:file2/oldf`'
50aee995
SP
326
327cat >expect <<EOF
5be60078 328parent `git rev-parse --verify master^0`
50aee995
SP
329author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
330committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
331
332second
333EOF
334test_expect_success \
335 'C: verify commit' \
5be60078 336 'git cat-file commit branch | sed 1d >actual &&
3af82863 337 test_cmp expect actual'
50aee995
SP
338
339cat >expect <<EOF
340:000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
341:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
342:100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
343EOF
5be60078 344git diff-tree -M -r master branch >actual
50aee995
SP
345test_expect_success \
346 'C: validate rename result' \
347 'compare_diff_raw expect actual'
348
b715cfbb
SP
349###
350### series D
351###
352
353test_tick
354cat >input <<INPUT_END
355commit refs/heads/branch
356committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
357data <<COMMIT
358third
359COMMIT
360
361from refs/heads/branch^0
362M 644 inline newdir/interesting
363data <<EOF
364$file5_data
365EOF
366
367M 755 inline newdir/exec.sh
368data <<EOF
369$file6_data
370EOF
371
372INPUT_END
373test_expect_success \
374 'D: inline data in commit' \
eaa2a6fc 375 'git fast-import <input &&
5be60078 376 git whatchanged branch'
b715cfbb
SP
377test_expect_success \
378 'D: verify pack' \
5be60078 379 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
b715cfbb
SP
380
381cat >expect <<EOF
382:000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A newdir/exec.sh
383:000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A newdir/interesting
384EOF
5be60078 385git diff-tree -M -r branch^ branch >actual
b715cfbb
SP
386test_expect_success \
387 'D: validate new files added' \
388 'compare_diff_raw expect actual'
389
390echo "$file5_data" >expect
391test_expect_success \
392 'D: verify file5' \
5be60078 393 'git cat-file blob branch:newdir/interesting >actual &&
3af82863 394 test_cmp expect actual'
b715cfbb
SP
395
396echo "$file6_data" >expect
397test_expect_success \
398 'D: verify file6' \
5be60078 399 'git cat-file blob branch:newdir/exec.sh >actual &&
3af82863 400 test_cmp expect actual'
b715cfbb 401
63e0c8b3
SP
402###
403### series E
404###
405
406cat >input <<INPUT_END
407commit refs/heads/branch
408author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
409committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
410data <<COMMIT
411RFC 2822 type date
412COMMIT
413
414from refs/heads/branch^0
415
416INPUT_END
41ac414e 417test_expect_success 'E: rfc2822 date, --date-format=raw' '
eaa2a6fc 418 test_must_fail git fast-import --date-format=raw <input
41ac414e 419'
63e0c8b3
SP
420test_expect_success \
421 'E: rfc2822 date, --date-format=rfc2822' \
eaa2a6fc 422 'git fast-import --date-format=rfc2822 <input'
63e0c8b3
SP
423test_expect_success \
424 'E: verify pack' \
5be60078 425 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
63e0c8b3
SP
426
427cat >expect <<EOF
428author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
429committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
430
431RFC 2822 type date
432EOF
433test_expect_success \
434 'E: verify commit' \
5be60078 435 'git cat-file commit branch | sed 1,2d >actual &&
3af82863 436 test_cmp expect actual'
63e0c8b3 437
7073e69e
SP
438###
439### series F
440###
441
5be60078 442old_branch=`git rev-parse --verify branch^0`
7073e69e
SP
443test_tick
444cat >input <<INPUT_END
445commit refs/heads/branch
446committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
447data <<COMMIT
448losing things already?
449COMMIT
450
451from refs/heads/branch~1
452
453reset refs/heads/other
454from refs/heads/branch
455
456INPUT_END
457test_expect_success \
458 'F: non-fast-forward update skips' \
eaa2a6fc 459 'if git fast-import <input
7073e69e
SP
460 then
461 echo BAD gfi did not fail
462 return 1
463 else
5be60078 464 if test $old_branch = `git rev-parse --verify branch^0`
7073e69e
SP
465 then
466 : branch unaffected and failure returned
467 return 0
468 else
469 echo BAD gfi changed branch $old_branch
470 return 1
471 fi
472 fi
473 '
474test_expect_success \
475 'F: verify pack' \
5be60078 476 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
7073e69e
SP
477
478cat >expect <<EOF
5be60078
JH
479tree `git rev-parse branch~1^{tree}`
480parent `git rev-parse branch~1`
7073e69e
SP
481author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
482committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
483
484losing things already?
485EOF
486test_expect_success \
487 'F: verify other commit' \
5be60078 488 'git cat-file commit other >actual &&
3af82863 489 test_cmp expect actual'
7073e69e
SP
490
491###
492### series G
493###
494
5be60078 495old_branch=`git rev-parse --verify branch^0`
7073e69e
SP
496test_tick
497cat >input <<INPUT_END
498commit refs/heads/branch
499committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
500data <<COMMIT
501losing things already?
502COMMIT
503
504from refs/heads/branch~1
505
506INPUT_END
507test_expect_success \
508 'G: non-fast-forward update forced' \
eaa2a6fc 509 'git fast-import --force <input'
7073e69e
SP
510test_expect_success \
511 'G: verify pack' \
5be60078 512 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
7073e69e
SP
513test_expect_success \
514 'G: branch changed, but logged' \
5be60078
JH
515 'test $old_branch != `git rev-parse --verify branch^0` &&
516 test $old_branch = `git rev-parse --verify branch@{1}`'
7073e69e 517
825769a8
SP
518###
519### series H
520###
521
522test_tick
523cat >input <<INPUT_END
524commit refs/heads/H
525committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
526data <<COMMIT
527third
528COMMIT
529
530from refs/heads/branch^0
531M 644 inline i-will-die
532data <<EOF
533this file will never exist.
534EOF
535
536deleteall
537M 644 inline h/e/l/lo
538data <<EOF
539$file5_data
540EOF
541
542INPUT_END
543test_expect_success \
544 'H: deletall, add 1' \
eaa2a6fc 545 'git fast-import <input &&
5be60078 546 git whatchanged H'
825769a8
SP
547test_expect_success \
548 'H: verify pack' \
5be60078 549 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
825769a8
SP
550
551cat >expect <<EOF
552:100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf
553:100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf
554:100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4
555:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo
556:100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh
557EOF
5be60078 558git diff-tree -M -r H^ H >actual
825769a8
SP
559test_expect_success \
560 'H: validate old files removed, new files added' \
561 'compare_diff_raw expect actual'
562
563echo "$file5_data" >expect
564test_expect_success \
565 'H: verify file' \
5be60078 566 'git cat-file blob H:h/e/l/lo >actual &&
3af82863 567 test_cmp expect actual'
825769a8 568
bdf1c06d
SP
569###
570### series I
571###
572
573cat >input <<INPUT_END
574commit refs/heads/export-boundary
575committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
576data <<COMMIT
577we have a border. its only 40 characters wide.
578COMMIT
579
580from refs/heads/branch
581
582INPUT_END
583test_expect_success \
584 'I: export-pack-edges' \
eaa2a6fc 585 'git fast-import --export-pack-edges=edges.list <input'
bdf1c06d
SP
586
587cat >expect <<EOF
5be60078 588.git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
bdf1c06d
SP
589EOF
590test_expect_success \
591 'I: verify edge list' \
592 'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
3af82863 593 test_cmp expect actual'
bdf1c06d 594
ea5e370a
SP
595###
596### series J
597###
598
599cat >input <<INPUT_END
600commit refs/heads/J
601committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
602data <<COMMIT
603create J
604COMMIT
605
606from refs/heads/branch
607
608reset refs/heads/J
609
610commit refs/heads/J
611committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
612data <<COMMIT
613initialize J
614COMMIT
615
616INPUT_END
617test_expect_success \
618 'J: reset existing branch creates empty commit' \
eaa2a6fc 619 'git fast-import <input'
ea5e370a
SP
620test_expect_success \
621 'J: branch has 1 commit, empty tree' \
5be60078 622 'test 1 = `git rev-list J | wc -l` &&
ea5e370a
SP
623 test 0 = `git ls-tree J | wc -l`'
624
625###
626### series K
627###
628
629cat >input <<INPUT_END
630commit refs/heads/K
631committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
632data <<COMMIT
633create K
634COMMIT
635
636from refs/heads/branch
637
638commit refs/heads/K
639committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
640data <<COMMIT
641redo K
642COMMIT
643
644from refs/heads/branch^1
645
646INPUT_END
647test_expect_success \
648 'K: reinit branch with from' \
eaa2a6fc 649 'git fast-import <input'
ea5e370a
SP
650test_expect_success \
651 'K: verify K^1 = branch^1' \
5be60078
JH
652 'test `git rev-parse --verify branch^1` \
653 = `git rev-parse --verify K^1`'
ea5e370a 654
e7411303
JK
655###
656### series L
657###
658
659cat >input <<INPUT_END
660blob
661mark :1
662data <<EOF
663some data
664EOF
665
666blob
667mark :2
668data <<EOF
669other data
670EOF
671
672commit refs/heads/L
673committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
674data <<COMMIT
675create L
676COMMIT
677
678M 644 :1 b.
679M 644 :1 b/other
680M 644 :1 ba
681
682commit refs/heads/L
683committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
684data <<COMMIT
685update L
686COMMIT
687
688M 644 :2 b.
689M 644 :2 b/other
690M 644 :2 ba
691INPUT_END
692
693cat >expect <<EXPECT_END
694:100644 100644 4268632... 55d3a52... M b.
695:040000 040000 0ae5cac... 443c768... M b
696:100644 100644 4268632... 55d3a52... M ba
697EXPECT_END
698
699test_expect_success \
700 'L: verify internal tree sorting' \
eaa2a6fc 701 'git fast-import <input &&
82cb8afa 702 git diff-tree --abbrev --raw L^ L >output &&
3af82863 703 test_cmp expect output'
e7411303 704
f39a946a
SP
705###
706### series M
707###
708
709test_tick
710cat >input <<INPUT_END
711commit refs/heads/M1
712committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
713data <<COMMIT
714file rename
715COMMIT
716
717from refs/heads/branch^0
718R file2/newf file2/n.e.w.f
719
720INPUT_END
721
722cat >expect <<EOF
723:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f
724EOF
725test_expect_success \
726 'M: rename file in same subdirectory' \
eaa2a6fc 727 'git fast-import <input &&
f39a946a
SP
728 git diff-tree -M -r M1^ M1 >actual &&
729 compare_diff_raw expect actual'
730
731cat >input <<INPUT_END
732commit refs/heads/M2
733committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
734data <<COMMIT
735file rename
736COMMIT
737
738from refs/heads/branch^0
739R file2/newf i/am/new/to/you
740
741INPUT_END
742
743cat >expect <<EOF
744:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you
745EOF
746test_expect_success \
747 'M: rename file to new subdirectory' \
eaa2a6fc 748 'git fast-import <input &&
f39a946a
SP
749 git diff-tree -M -r M2^ M2 >actual &&
750 compare_diff_raw expect actual'
751
752cat >input <<INPUT_END
753commit refs/heads/M3
754committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
755data <<COMMIT
756file rename
757COMMIT
758
759from refs/heads/M2^0
760R i other/sub
761
762INPUT_END
763
764cat >expect <<EOF
765:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you
766EOF
767test_expect_success \
768 'M: rename subdirectory to new subdirectory' \
eaa2a6fc 769 'git fast-import <input &&
f39a946a
SP
770 git diff-tree -M -r M3^ M3 >actual &&
771 compare_diff_raw expect actual'
772
b6f3481b
SP
773###
774### series N
775###
776
777test_tick
778cat >input <<INPUT_END
779commit refs/heads/N1
780committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
781data <<COMMIT
782file copy
783COMMIT
784
785from refs/heads/branch^0
786C file2/newf file2/n.e.w.f
787
788INPUT_END
789
790cat >expect <<EOF
791:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f
792EOF
793test_expect_success \
794 'N: copy file in same subdirectory' \
eaa2a6fc 795 'git fast-import <input &&
b6f3481b
SP
796 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
797 compare_diff_raw expect actual'
798
799cat >input <<INPUT_END
800commit refs/heads/N2
801committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
802data <<COMMIT
803clean directory copy
804COMMIT
805
806from refs/heads/branch^0
807C file2 file3
808
809commit refs/heads/N2
810committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
811data <<COMMIT
812modify directory copy
813COMMIT
814
815M 644 inline file3/file5
816data <<EOF
817$file5_data
818EOF
819
820INPUT_END
821
822cat >expect <<EOF
823:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
824:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
825:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
826EOF
827test_expect_success \
828 'N: copy then modify subdirectory' \
eaa2a6fc 829 'git fast-import <input &&
b6f3481b
SP
830 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
831 compare_diff_raw expect actual'
832
833cat >input <<INPUT_END
834commit refs/heads/N3
835committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
836data <<COMMIT
837dirty directory copy
838COMMIT
839
840from refs/heads/branch^0
841M 644 inline file2/file5
842data <<EOF
843$file5_data
844EOF
845
846C file2 file3
847D file2/file5
848
849INPUT_END
850
851test_expect_success \
852 'N: copy dirty subdirectory' \
eaa2a6fc
NS
853 'git fast-import <input &&
854 test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`'
b6f3481b 855
334fba65
JN
856test_expect_success \
857 'N: copy directory by id' \
858 'cat >expect <<-\EOF &&
859 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
860 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
861 EOF
862 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
863 cat >input <<-INPUT_END &&
864 commit refs/heads/N4
865 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
866 data <<COMMIT
867 copy by tree hash
868 COMMIT
869
870 from refs/heads/branch^0
871 M 040000 $subdir file3
872 INPUT_END
873 git fast-import <input &&
874 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
875 compare_diff_raw expect actual'
876
2794ad52
DB
877test_expect_success \
878 'N: copy root directory by tree hash' \
879 'cat >expect <<-\EOF &&
880 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file3/newf
881 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file3/oldf
882 EOF
883 root=$(git rev-parse refs/heads/branch^0^{tree}) &&
884 cat >input <<-INPUT_END &&
885 commit refs/heads/N6
886 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
887 data <<COMMIT
888 copy root directory by tree hash
889 COMMIT
890
891 from refs/heads/branch^0
892 M 040000 $root ""
893 INPUT_END
894 git fast-import <input &&
895 git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
896 compare_diff_raw expect actual'
897
334fba65
JN
898test_expect_success \
899 'N: modify copied tree' \
900 'cat >expect <<-\EOF &&
901 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
902 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
903 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
904 EOF
905 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
906 cat >input <<-INPUT_END &&
907 commit refs/heads/N5
908 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
909 data <<COMMIT
910 copy by tree hash
911 COMMIT
912
913 from refs/heads/branch^0
914 M 040000 $subdir file3
915
916 commit refs/heads/N5
917 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
918 data <<COMMIT
919 modify directory copy
920 COMMIT
921
922 M 644 inline file3/file5
923 data <<EOF
924 $file5_data
925 EOF
926 INPUT_END
927 git fast-import <input &&
928 git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
929 compare_diff_raw expect actual'
930
5edde510
JN
931test_expect_success \
932 'N: copy to root by id and modify' \
933 'echo "hello, world" >expect.foo &&
934 echo hello >expect.bar &&
935 git fast-import <<-SETUP_END &&
936 commit refs/heads/N7
937 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
938 data <<COMMIT
939 hello, tree
940 COMMIT
941
942 deleteall
943 M 644 inline foo/bar
944 data <<EOF
945 hello
946 EOF
947 SETUP_END
948
949 tree=$(git rev-parse --verify N7:) &&
950 git fast-import <<-INPUT_END &&
951 commit refs/heads/N8
952 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
953 data <<COMMIT
954 copy to root by id and modify
955 COMMIT
956
957 M 040000 $tree ""
958 M 644 inline foo/foo
959 data <<EOF
960 hello, world
961 EOF
962 INPUT_END
963 git show N8:foo/foo >actual.foo &&
964 git show N8:foo/bar >actual.bar &&
965 test_cmp expect.foo actual.foo &&
966 test_cmp expect.bar actual.bar'
967
401d53fa
SP
968###
969### series O
970###
971
972cat >input <<INPUT_END
973#we will
974commit refs/heads/O1
975# -- ignore all of this text
976committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
977# $GIT_COMMITTER_NAME has inserted here for his benefit.
978data <<COMMIT
979dirty directory copy
980COMMIT
981
982# don't forget the import blank line!
983#
984# yes, we started from our usual base of branch^0.
985# i like branch^0.
986from refs/heads/branch^0
987# and we need to reuse file2/file5 from N3 above.
988M 644 inline file2/file5
989# otherwise the tree will be different
990data <<EOF
991$file5_data
992EOF
993
994# don't forget to copy file2 to file3
995C file2 file3
996#
997# or to delete file5 from file2.
998D file2/file5
999# are we done yet?
1000
1001INPUT_END
1002
1003test_expect_success \
1004 'O: comments are all skipped' \
eaa2a6fc
NS
1005 'git fast-import <input &&
1006 test `git rev-parse N3` = `git rev-parse O1`'
401d53fa 1007
2c570cde
SP
1008cat >input <<INPUT_END
1009commit refs/heads/O2
1010committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1011data <<COMMIT
1012dirty directory copy
1013COMMIT
1014from refs/heads/branch^0
1015M 644 inline file2/file5
1016data <<EOF
1017$file5_data
1018EOF
1019C file2 file3
1020D file2/file5
1021
1022INPUT_END
1023
1024test_expect_success \
1025 'O: blank lines not necessary after data commands' \
eaa2a6fc
NS
1026 'git fast-import <input &&
1027 test `git rev-parse N3` = `git rev-parse O2`'
2c570cde 1028
1fdb649c
SP
1029test_expect_success \
1030 'O: repack before next test' \
1031 'git repack -a -d'
1032
1033cat >input <<INPUT_END
1034commit refs/heads/O3
1035committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1036data <<COMMIT
1037zstring
1038COMMIT
1039commit refs/heads/O3
1040committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1041data <<COMMIT
1042zof
1043COMMIT
1044checkpoint
1045commit refs/heads/O3
1046mark :5
1047committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1048data <<COMMIT
1049zempty
1050COMMIT
1051checkpoint
1052commit refs/heads/O3
1053committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1054data <<COMMIT
1055zcommits
1056COMMIT
1057reset refs/tags/O3-2nd
1058from :5
655e8515
AS
1059reset refs/tags/O3-3rd
1060from :5
1fdb649c
SP
1061INPUT_END
1062
1063cat >expect <<INPUT_END
1064string
1065of
1066empty
1067commits
1068INPUT_END
1069test_expect_success \
1070 'O: blank lines not necessary after other commands' \
eaa2a6fc 1071 'git fast-import <input &&
1fdb649c
SP
1072 test 8 = `find .git/objects/pack -type f | wc -l` &&
1073 test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
1074 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
3af82863 1075 test_cmp expect actual'
1fdb649c 1076
ac053c02
SP
1077cat >input <<INPUT_END
1078commit refs/heads/O4
1079committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1080data <<COMMIT
1081zstring
1082COMMIT
1083commit refs/heads/O4
1084committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1085data <<COMMIT
1086zof
1087COMMIT
1088progress Two commits down, 2 to go!
1089commit refs/heads/O4
1090committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1091data <<COMMIT
1092zempty
1093COMMIT
1094progress Three commits down, 1 to go!
1095commit refs/heads/O4
1096committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1097data <<COMMIT
1098zcommits
1099COMMIT
1100progress I'm done!
1101INPUT_END
1102test_expect_success \
1103 'O: progress outputs as requested by input' \
eaa2a6fc 1104 'git fast-import <input >actual &&
ac053c02 1105 grep "progress " <input >expect &&
3af82863 1106 test_cmp expect actual'
ac053c02 1107
03db4525
AG
1108###
1109### series P (gitlinks)
1110###
1111
1112cat >input <<INPUT_END
1113blob
1114mark :1
1115data 10
1116test file
1117
1118reset refs/heads/sub
1119commit refs/heads/sub
1120mark :2
1121committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1122data 12
1123sub_initial
1124M 100644 :1 file
1125
1126blob
1127mark :3
1128data <<DATAEND
1129[submodule "sub"]
1130 path = sub
1131 url = "`pwd`/sub"
1132DATAEND
1133
1134commit refs/heads/subuse1
1135mark :4
1136committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1137data 8
1138initial
1139from refs/heads/master
1140M 100644 :3 .gitmodules
1141M 160000 :2 sub
1142
1143blob
1144mark :5
1145data 20
1146test file
1147more data
1148
1149commit refs/heads/sub
1150mark :6
1151committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1152data 11
1153sub_second
1154from :2
1155M 100644 :5 file
1156
1157commit refs/heads/subuse1
1158mark :7
1159committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1160data 7
1161second
1162from :4
1163M 160000 :6 sub
1164
1165INPUT_END
1166
1167test_expect_success \
1168 'P: supermodule & submodule mix' \
eaa2a6fc 1169 'git fast-import <input &&
03db4525 1170 git checkout subuse1 &&
fd4ec4f2 1171 rm -rf sub && mkdir sub && (cd sub &&
03db4525 1172 git init &&
8ee5d731 1173 git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
fd4ec4f2 1174 git checkout master) &&
03db4525
AG
1175 git submodule init &&
1176 git submodule update'
1177
eaa2a6fc
NS
1178SUBLAST=$(git rev-parse --verify sub)
1179SUBPREV=$(git rev-parse --verify sub^)
03db4525
AG
1180
1181cat >input <<INPUT_END
1182blob
1183mark :1
1184data <<DATAEND
1185[submodule "sub"]
1186 path = sub
1187 url = "`pwd`/sub"
1188DATAEND
1189
1190commit refs/heads/subuse2
1191mark :2
1192committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1193data 8
1194initial
1195from refs/heads/master
1196M 100644 :1 .gitmodules
1197M 160000 $SUBPREV sub
1198
1199commit refs/heads/subuse2
1200mark :3
1201committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1202data 7
1203second
1204from :2
1205M 160000 $SUBLAST sub
1206
1207INPUT_END
1208
1209test_expect_success \
1210 'P: verbatim SHA gitlinks' \
1211 'git branch -D sub &&
1212 git gc && git prune &&
eaa2a6fc
NS
1213 git fast-import <input &&
1214 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)'
03db4525
AG
1215
1216test_tick
1217cat >input <<INPUT_END
1218commit refs/heads/subuse3
1219mark :1
1220committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1221data <<COMMIT
1222corrupt
1223COMMIT
1224
1225from refs/heads/subuse2
1226M 160000 inline sub
1227data <<DATA
1228$SUBPREV
1229DATA
1230
1231INPUT_END
1232
1233test_expect_success 'P: fail on inline gitlink' '
eaa2a6fc 1234 test_must_fail git fast-import <input'
03db4525
AG
1235
1236test_tick
1237cat >input <<INPUT_END
1238blob
1239mark :1
1240data <<DATA
1241$SUBPREV
1242DATA
1243
1244commit refs/heads/subuse3
1245mark :2
1246committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1247data <<COMMIT
1248corrupt
1249COMMIT
1250
1251from refs/heads/subuse2
1252M 160000 :1 sub
1253
1254INPUT_END
1255
1256test_expect_success 'P: fail on blob mark in gitlink' '
eaa2a6fc 1257 test_must_fail git fast-import <input'
03db4525 1258
a8dd2e7d
JH
1259###
1260### series Q (notes)
1261###
1262
2a113aee
JH
1263note1_data="The first note for the first commit"
1264note2_data="The first note for the second commit"
1265note3_data="The first note for the third commit"
1266note1b_data="The second note for the first commit"
1267note1c_data="The third note for the first commit"
1268note2b_data="The second note for the second commit"
a8dd2e7d
JH
1269
1270test_tick
1271cat >input <<INPUT_END
1272blob
1273mark :2
1274data <<EOF
1275$file2_data
1276EOF
1277
1278commit refs/heads/notes-test
1279mark :3
1280committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1281data <<COMMIT
1282first (:3)
1283COMMIT
1284
1285M 644 :2 file2
1286
1287blob
1288mark :4
1289data $file4_len
1290$file4_data
1291commit refs/heads/notes-test
1292mark :5
1293committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1294data <<COMMIT
1295second (:5)
1296COMMIT
1297
1298M 644 :4 file4
1299
1300commit refs/heads/notes-test
1301mark :6
1302committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1303data <<COMMIT
1304third (:6)
1305COMMIT
1306
1307M 644 inline file5
1308data <<EOF
1309$file5_data
1310EOF
1311
1312M 755 inline file6
1313data <<EOF
1314$file6_data
1315EOF
1316
1317blob
1318mark :7
1319data <<EOF
1320$note1_data
1321EOF
1322
1323blob
1324mark :8
1325data <<EOF
1326$note2_data
1327EOF
1328
1329commit refs/notes/foobar
1330mark :9
1331committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1332data <<COMMIT
1333notes (:9)
1334COMMIT
1335
1336N :7 :3
1337N :8 :5
1338N inline :6
1339data <<EOF
1340$note3_data
1341EOF
1342
2a113aee
JH
1343commit refs/notes/foobar
1344mark :10
1345committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1346data <<COMMIT
1347notes (:10)
1348COMMIT
1349
1350N inline :3
1351data <<EOF
1352$note1b_data
1353EOF
1354
1355commit refs/notes/foobar2
1356mark :11
1357committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1358data <<COMMIT
1359notes (:11)
1360COMMIT
1361
1362N inline :3
1363data <<EOF
1364$note1c_data
1365EOF
1366
1367commit refs/notes/foobar
1368mark :12
1369committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1370data <<COMMIT
1371notes (:12)
1372COMMIT
1373
1374deleteall
1375N inline :5
1376data <<EOF
1377$note2b_data
1378EOF
1379
a8dd2e7d 1380INPUT_END
2a113aee 1381
a8dd2e7d
JH
1382test_expect_success \
1383 'Q: commit notes' \
1384 'git fast-import <input &&
1385 git whatchanged notes-test'
1386test_expect_success \
1387 'Q: verify pack' \
1388 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
1389
1390commit1=$(git rev-parse notes-test~2)
1391commit2=$(git rev-parse notes-test^)
1392commit3=$(git rev-parse notes-test)
1393
1394cat >expect <<EOF
1395author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1396committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1397
1398first (:3)
1399EOF
1400test_expect_success \
1401 'Q: verify first commit' \
1402 'git cat-file commit notes-test~2 | sed 1d >actual &&
1403 test_cmp expect actual'
1404
1405cat >expect <<EOF
1406parent $commit1
1407author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1408committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1409
1410second (:5)
1411EOF
1412test_expect_success \
1413 'Q: verify second commit' \
1414 'git cat-file commit notes-test^ | sed 1d >actual &&
1415 test_cmp expect actual'
1416
1417cat >expect <<EOF
1418parent $commit2
1419author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1420committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1421
1422third (:6)
1423EOF
1424test_expect_success \
1425 'Q: verify third commit' \
1426 'git cat-file commit notes-test | sed 1d >actual &&
1427 test_cmp expect actual'
1428
1429cat >expect <<EOF
1430author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1431committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1432
1433notes (:9)
1434EOF
1435test_expect_success \
2a113aee
JH
1436 'Q: verify first notes commit' \
1437 'git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
a8dd2e7d
JH
1438 test_cmp expect actual'
1439
1440cat >expect.unsorted <<EOF
1441100644 blob $commit1
1442100644 blob $commit2
1443100644 blob $commit3
1444EOF
1445cat expect.unsorted | sort >expect
1446test_expect_success \
2a113aee
JH
1447 'Q: verify first notes tree' \
1448 'git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
a8dd2e7d
JH
1449 test_cmp expect actual'
1450
1451echo "$note1_data" >expect
1452test_expect_success \
2a113aee
JH
1453 'Q: verify first note for first commit' \
1454 'git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual'
a8dd2e7d
JH
1455
1456echo "$note2_data" >expect
1457test_expect_success \
2a113aee
JH
1458 'Q: verify first note for second commit' \
1459 'git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual'
1460
1461echo "$note3_data" >expect
1462test_expect_success \
1463 'Q: verify first note for third commit' \
1464 'git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual'
1465
1466cat >expect <<EOF
1467parent `git rev-parse --verify refs/notes/foobar~2`
1468author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1469committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1470
1471notes (:10)
1472EOF
1473test_expect_success \
1474 'Q: verify second notes commit' \
1475 'git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
1476 test_cmp expect actual'
1477
1478cat >expect.unsorted <<EOF
1479100644 blob $commit1
1480100644 blob $commit2
1481100644 blob $commit3
1482EOF
1483cat expect.unsorted | sort >expect
1484test_expect_success \
1485 'Q: verify second notes tree' \
1486 'git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1487 test_cmp expect actual'
1488
1489echo "$note1b_data" >expect
1490test_expect_success \
1491 'Q: verify second note for first commit' \
1492 'git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual'
1493
1494echo "$note2_data" >expect
1495test_expect_success \
1496 'Q: verify first note for second commit' \
1497 'git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual'
a8dd2e7d
JH
1498
1499echo "$note3_data" >expect
1500test_expect_success \
2a113aee
JH
1501 'Q: verify first note for third commit' \
1502 'git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual'
1503
1504cat >expect <<EOF
1505author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1506committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1507
1508notes (:11)
1509EOF
1510test_expect_success \
1511 'Q: verify third notes commit' \
1512 'git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
1513 test_cmp expect actual'
1514
1515cat >expect.unsorted <<EOF
1516100644 blob $commit1
1517EOF
1518cat expect.unsorted | sort >expect
1519test_expect_success \
1520 'Q: verify third notes tree' \
1521 'git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1522 test_cmp expect actual'
1523
1524echo "$note1c_data" >expect
1525test_expect_success \
1526 'Q: verify third note for first commit' \
1527 'git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual'
1528
1529cat >expect <<EOF
1530parent `git rev-parse --verify refs/notes/foobar^`
1531author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1532committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1533
1534notes (:12)
1535EOF
1536test_expect_success \
1537 'Q: verify fourth notes commit' \
1538 'git cat-file commit refs/notes/foobar | sed 1d >actual &&
1539 test_cmp expect actual'
1540
1541cat >expect.unsorted <<EOF
1542100644 blob $commit2
1543EOF
1544cat expect.unsorted | sort >expect
1545test_expect_success \
1546 'Q: verify fourth notes tree' \
1547 'git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1548 test_cmp expect actual'
1549
1550echo "$note2b_data" >expect
1551test_expect_success \
1552 'Q: verify second note for second commit' \
1553 'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual'
a8dd2e7d 1554
f963bd5d 1555###
2792f26c 1556### series R (feature and option)
f963bd5d
SR
1557###
1558
1559cat >input <<EOF
1560feature no-such-feature-exists
1561EOF
1562
1563test_expect_success 'R: abort on unsupported feature' '
1564 test_must_fail git fast-import <input
1565'
1566
1567cat >input <<EOF
1568feature date-format=now
1569EOF
1570
1571test_expect_success 'R: supported feature is accepted' '
1572 git fast-import <input
1573'
1574
1575cat >input << EOF
1576blob
1577data 3
1578hi
1579feature date-format=now
1580EOF
1581
1582test_expect_success 'R: abort on receiving feature after data command' '
1583 test_must_fail git fast-import <input
1584'
1585
081751c8
SR
1586cat >input << EOF
1587feature import-marks=git.marks
1588feature import-marks=git2.marks
1589EOF
1590
1591test_expect_success 'R: only one import-marks feature allowed per stream' '
1592 test_must_fail git fast-import <input
1593'
1594
f963bd5d
SR
1595cat >input << EOF
1596feature export-marks=git.marks
1597blob
1598mark :1
1599data 3
1600hi
1601
1602EOF
1603
1604test_expect_success \
1605 'R: export-marks feature results in a marks file being created' \
1606 'cat input | git fast-import &&
1607 grep :1 git.marks'
1608
1609test_expect_success \
1610 'R: export-marks options can be overriden by commandline options' \
1611 'cat input | git fast-import --export-marks=other.marks &&
1612 grep :1 other.marks'
1613
1614cat >input << EOF
1615feature import-marks=marks.out
1616feature export-marks=marks.new
1617EOF
1618
1619test_expect_success \
1620 'R: import to output marks works without any content' \
1621 'cat input | git fast-import &&
1622 test_cmp marks.out marks.new'
1623
1624cat >input <<EOF
1625feature import-marks=nonexistant.marks
1626feature export-marks=marks.new
1627EOF
1628
1629test_expect_success \
1630 'R: import marks prefers commandline marks file over the stream' \
1631 'cat input | git fast-import --import-marks=marks.out &&
1632 test_cmp marks.out marks.new'
1633
081751c8
SR
1634
1635cat >input <<EOF
1636feature import-marks=nonexistant.marks
1637feature export-marks=combined.marks
1638EOF
1639
1640test_expect_success 'R: multiple --import-marks= should be honoured' '
1641 head -n2 marks.out > one.marks &&
1642 tail -n +3 marks.out > two.marks &&
1643 git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
1644 test_cmp marks.out combined.marks
1645'
1646
bc3c79ae
SR
1647cat >input <<EOF
1648feature relative-marks
1649feature import-marks=relative.in
1650feature export-marks=relative.out
1651EOF
1652
1653test_expect_success 'R: feature relative-marks should be honoured' '
1654 mkdir -p .git/info/fast-import/ &&
1655 cp marks.new .git/info/fast-import/relative.in &&
1656 git fast-import <input &&
1657 test_cmp marks.new .git/info/fast-import/relative.out
1658'
1659
1660cat >input <<EOF
1661feature relative-marks
1662feature import-marks=relative.in
1663feature no-relative-marks
1664feature export-marks=non-relative.out
1665EOF
1666
1667test_expect_success 'R: feature no-relative-marks should be honoured' '
1668 git fast-import <input &&
1669 test_cmp marks.new non-relative.out
1670'
1671
2792f26c
SR
1672cat >input << EOF
1673option git quiet
1674blob
1675data 3
1676hi
1677
1678EOF
1679
1680touch empty
1681
1682test_expect_success 'R: quiet option results in no stats being output' '
1683 cat input | git fast-import 2> output &&
1684 test_cmp empty output
1685'
1686
1687cat >input <<EOF
1688option git non-existing-option
1689EOF
1690
1691test_expect_success 'R: die on unknown option' '
1692 test_must_fail git fast-import <input
1693'
1694
1695test_expect_success 'R: unknown commandline options are rejected' '\
1696 test_must_fail git fast-import --non-existing-option < /dev/null
1697'
1698
1699cat >input <<EOF
1700option non-existing-vcs non-existing-option
1701EOF
1702
1703test_expect_success 'R: ignore non-git options' '
1704 git fast-import <input
1705'
1706
5eef828b
SP
1707##
1708## R: very large blobs
1709##
1710blobsize=$((2*1024*1024 + 53))
1711test-genrandom bar $blobsize >expect
1712cat >input <<INPUT_END
1713commit refs/heads/big-file
1714committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1715data <<COMMIT
1716R - big file
1717COMMIT
1718
1719M 644 inline big1
1720data $blobsize
1721INPUT_END
1722cat expect >>input
1723cat >>input <<INPUT_END
1724M 644 inline big2
1725data $blobsize
1726INPUT_END
1727cat expect >>input
1728echo >>input
1729
1730test_expect_success \
1731 'R: blob bigger than threshold' \
1732 'test_create_repo R &&
1733 git --git-dir=R/.git fast-import --big-file-threshold=1 <input'
1734test_expect_success \
1735 'R: verify created pack' \
1736 ': >verify &&
1737 for p in R/.git/objects/pack/*.pack;
1738 do
1739 git verify-pack -v $p >>verify || exit;
1740 done'
1741test_expect_success \
1742 'R: verify written objects' \
1743 'git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
1744 test_cmp expect actual &&
1745 a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
1746 b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
1747 test $a = $b'
1748test_expect_success \
1749 'R: blob appears only once' \
1750 'n=$(grep $a verify | wc -l) &&
1751 test 1 = $n'
1752
50aee995 1753test_done