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