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