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