modernize t9300: single-quote placement and indentation
[git.git] / t / t9300-fast-import.sh
blob566f7bdd30436006615aa882d67531c29e41f3b2
1 #!/bin/sh
3 # Copyright (c) 2007 Shawn Pearce
6 test_description='test git fast-import utility'
7 . ./test-lib.sh
8 . "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
10 # Print $1 bytes from stdin to stdout.
12 # This could be written as "head -c $1", but IRIX "head" does not
13 # support the -c option.
14 head_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;
24 ' - "$1"
27 verify_packs () {
28 for p in .git/objects/pack/*.pack
30 git verify-pack "$@" "$p" || return
31 done
34 file2_data='file2
35 second line of EOF'
37 file3_data='EOF
38 in 3rd file
39 END'
41 file4_data=abcd
42 file4_len=4
44 file5_data='an inline file.
45 we should see it later.'
47 file6_data='#!/bin/sh
48 echo "$@"'
50 >empty
52 ###
53 ### series A
54 ###
56 test_tick
58 test_expect_success 'empty stream succeeds' '
59 git fast-import </dev/null
62 cat >input <<INPUT_END
63 blob
64 mark :2
65 data <<EOF
66 $file2_data
67 EOF
69 blob
70 mark :3
71 data <<END
72 $file3_data
73 END
75 blob
76 mark :4
77 data $file4_len
78 $file4_data
79 commit refs/heads/master
80 mark :5
81 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
82 data <<COMMIT
83 initial
84 COMMIT
86 M 644 :2 file2
87 M 644 :3 file3
88 M 755 :4 file4
90 tag series-A
91 from :5
92 data <<EOF
93 An annotated tag without a tagger
94 EOF
96 tag series-A-blob
97 from :3
98 data <<EOF
99 An annotated tag that annotates a blob.
102 INPUT_END
103 test_expect_success 'A: create pack from stdin' '
104 git fast-import --export-marks=marks.out <input &&
105 git whatchanged master
108 test_expect_success 'A: verify pack' '
109 verify_packs
112 cat >expect <<EOF
113 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
114 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
116 initial
118 test_expect_success 'A: verify commit' '
119 git cat-file commit master | sed 1d >actual &&
120 test_cmp expect actual
123 cat >expect <<EOF
124 100644 blob file2
125 100644 blob file3
126 100755 blob file4
128 test_expect_success 'A: verify tree' '
129 git cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
130 test_cmp expect actual
133 echo "$file2_data" >expect
134 test_expect_success 'A: verify file2' '
135 git cat-file blob master:file2 >actual && test_cmp expect actual
138 echo "$file3_data" >expect
139 test_expect_success 'A: verify file3' '
140 git cat-file blob master:file3 >actual && test_cmp expect actual
143 printf "$file4_data" >expect
144 test_expect_success 'A: verify file4' '
145 git cat-file blob master:file4 >actual && test_cmp expect actual
148 cat >expect <<EOF
149 object $(git rev-parse refs/heads/master)
150 type commit
151 tag series-A
153 An annotated tag without a tagger
155 test_expect_success 'A: verify tag/series-A' '
156 git cat-file tag tags/series-A >actual &&
157 test_cmp expect actual
160 cat >expect <<EOF
161 object $(git rev-parse refs/heads/master:file3)
162 type blob
163 tag series-A-blob
165 An annotated tag that annotates a blob.
167 test_expect_success 'A: verify tag/series-A-blob' '
168 git cat-file tag tags/series-A-blob >actual &&
169 test_cmp expect actual
172 cat >expect <<EOF
173 :2 `git rev-parse --verify master:file2`
174 :3 `git rev-parse --verify master:file3`
175 :4 `git rev-parse --verify master:file4`
176 :5 `git rev-parse --verify master^0`
178 test_expect_success 'A: verify marks output' '
179 test_cmp expect marks.out
182 test_expect_success 'A: verify marks import' '
183 git fast-import \
184 --import-marks=marks.out \
185 --export-marks=marks.new \
186 </dev/null &&
187 test_cmp expect marks.new
190 test_tick
191 new_blob=$(echo testing | git hash-object --stdin)
192 cat >input <<INPUT_END
193 tag series-A-blob-2
194 from $(git rev-parse refs/heads/master:file3)
195 data <<EOF
196 Tag blob by sha1.
199 blob
200 mark :6
201 data <<EOF
202 testing
205 commit refs/heads/new_blob
206 committer <> 0 +0000
207 data 0
208 M 644 :6 new_blob
209 #pretend we got sha1 from fast-import
210 ls "new_blob"
212 tag series-A-blob-3
213 from $new_blob
214 data <<EOF
215 Tag new_blob.
217 INPUT_END
219 cat >expect <<EOF
220 object $(git rev-parse refs/heads/master:file3)
221 type blob
222 tag series-A-blob-2
224 Tag blob by sha1.
225 object $new_blob
226 type blob
227 tag series-A-blob-3
229 Tag new_blob.
232 test_expect_success 'A: tag blob by sha1' '
233 git fast-import <input &&
234 git cat-file tag tags/series-A-blob-2 >actual &&
235 git cat-file tag tags/series-A-blob-3 >>actual &&
236 test_cmp expect actual
239 test_tick
240 cat >input <<INPUT_END
241 commit refs/heads/verify--import-marks
242 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
243 data <<COMMIT
244 recreate from :5
245 COMMIT
247 from :5
248 M 755 :2 copy-of-file2
250 INPUT_END
251 test_expect_success 'A: verify marks import does not crash' '
252 git fast-import --import-marks=marks.out <input &&
253 git whatchanged verify--import-marks
256 test_expect_success 'A: verify pack' '
257 verify_packs
260 cat >expect <<EOF
261 :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2
263 git diff-tree -M -r master verify--import-marks >actual
264 test_expect_success 'A: verify diff' '
265 compare_diff_raw expect actual &&
266 test `git rev-parse --verify master:file2` \
267 = `git rev-parse --verify verify--import-marks:copy-of-file2`
270 test_tick
271 mt=$(git hash-object --stdin < /dev/null)
272 : >input.blob
273 : >marks.exp
274 : >tree.exp
276 cat >input.commit <<EOF
277 commit refs/heads/verify--dump-marks
278 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
279 data <<COMMIT
280 test the sparse array dumping routines with exponentially growing marks
281 COMMIT
288 while test "$i" -lt 27; do
289 cat >>input.blob <<EOF
290 blob
291 mark :$l
292 data 0
293 blob
294 mark :$m
295 data 0
296 blob
297 mark :$n
298 data 0
300 echo "M 100644 :$l l$i" >>input.commit
301 echo "M 100644 :$m m$i" >>input.commit
302 echo "M 100644 :$n n$i" >>input.commit
304 echo ":$l $mt" >>marks.exp
305 echo ":$m $mt" >>marks.exp
306 echo ":$n $mt" >>marks.exp
308 printf "100644 blob $mt\tl$i\n" >>tree.exp
309 printf "100644 blob $mt\tm$i\n" >>tree.exp
310 printf "100644 blob $mt\tn$i\n" >>tree.exp
312 l=$(($l + $l))
313 m=$(($m + $m))
314 n=$(($l + $n))
316 i=$((1 + $i))
317 done
319 sort tree.exp > tree.exp_s
321 test_expect_success 'A: export marks with large values' '
322 cat input.blob input.commit | git fast-import --export-marks=marks.large &&
323 git ls-tree refs/heads/verify--dump-marks >tree.out &&
324 test_cmp tree.exp_s tree.out &&
325 test_cmp marks.exp marks.large
329 ### series B
332 test_tick
333 cat >input <<INPUT_END
334 commit refs/heads/branch
335 mark :1
336 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
337 data <<COMMIT
338 corrupt
339 COMMIT
341 from refs/heads/master
342 M 755 0000000000000000000000000000000000000001 zero1
344 INPUT_END
345 test_expect_success 'B: fail on invalid blob sha1' '
346 test_must_fail git fast-import <input
348 rm -f .git/objects/pack_* .git/objects/index_*
350 cat >input <<INPUT_END
351 commit TEMP_TAG
352 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
353 data <<COMMIT
354 tag base
355 COMMIT
357 from refs/heads/master
359 INPUT_END
360 test_expect_success 'B: accept branch name "TEMP_TAG"' '
361 git fast-import <input &&
362 test -f .git/TEMP_TAG &&
363 test `git rev-parse master` = `git rev-parse TEMP_TAG^`
365 rm -f .git/TEMP_TAG
367 git gc 2>/dev/null >/dev/null
368 git prune 2>/dev/null >/dev/null
370 cat >input <<INPUT_END
371 commit refs/heads/empty-committer-1
372 committer <> $GIT_COMMITTER_DATE
373 data <<COMMIT
374 empty commit
375 COMMIT
376 INPUT_END
377 test_expect_success 'B: accept empty committer' '
378 git fast-import <input &&
379 out=$(git fsck) &&
380 echo "$out" &&
381 test -z "$out"
383 git update-ref -d refs/heads/empty-committer-1 || true
385 git gc 2>/dev/null >/dev/null
386 git prune 2>/dev/null >/dev/null
388 cat >input <<INPUT_END
389 commit refs/heads/empty-committer-2
390 committer <a@b.com> $GIT_COMMITTER_DATE
391 data <<COMMIT
392 empty commit
393 COMMIT
394 INPUT_END
395 test_expect_success 'B: accept and fixup committer with no name' '
396 git fast-import <input &&
397 out=$(git fsck) &&
398 echo "$out" &&
399 test -z "$out"
401 git update-ref -d refs/heads/empty-committer-2 || true
403 git gc 2>/dev/null >/dev/null
404 git prune 2>/dev/null >/dev/null
406 cat >input <<INPUT_END
407 commit refs/heads/invalid-committer
408 committer Name email> $GIT_COMMITTER_DATE
409 data <<COMMIT
410 empty commit
411 COMMIT
412 INPUT_END
413 test_expect_success 'B: fail on invalid committer (1)' '
414 test_must_fail git fast-import <input
416 git update-ref -d refs/heads/invalid-committer || true
418 cat >input <<INPUT_END
419 commit refs/heads/invalid-committer
420 committer Name <e<mail> $GIT_COMMITTER_DATE
421 data <<COMMIT
422 empty commit
423 COMMIT
424 INPUT_END
425 test_expect_success 'B: fail on invalid committer (2)' '
426 test_must_fail git fast-import <input
428 git update-ref -d refs/heads/invalid-committer || true
430 cat >input <<INPUT_END
431 commit refs/heads/invalid-committer
432 committer Name <email>> $GIT_COMMITTER_DATE
433 data <<COMMIT
434 empty commit
435 COMMIT
436 INPUT_END
437 test_expect_success 'B: fail on invalid committer (3)' '
438 test_must_fail git fast-import <input
440 git update-ref -d refs/heads/invalid-committer || true
442 cat >input <<INPUT_END
443 commit refs/heads/invalid-committer
444 committer Name <email $GIT_COMMITTER_DATE
445 data <<COMMIT
446 empty commit
447 COMMIT
448 INPUT_END
449 test_expect_success 'B: fail on invalid committer (4)' '
450 test_must_fail git fast-import <input
452 git update-ref -d refs/heads/invalid-committer || true
454 cat >input <<INPUT_END
455 commit refs/heads/invalid-committer
456 committer Name<email> $GIT_COMMITTER_DATE
457 data <<COMMIT
458 empty commit
459 COMMIT
460 INPUT_END
461 test_expect_success 'B: fail on invalid committer (5)' '
462 test_must_fail git fast-import <input
464 git update-ref -d refs/heads/invalid-committer || true
467 ### series C
470 newf=`echo hi newf | git hash-object -w --stdin`
471 oldf=`git rev-parse --verify master:file2`
472 test_tick
473 cat >input <<INPUT_END
474 commit refs/heads/branch
475 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
476 data <<COMMIT
477 second
478 COMMIT
480 from refs/heads/master
481 M 644 $oldf file2/oldf
482 M 755 $newf file2/newf
483 D file3
485 INPUT_END
486 test_expect_success 'C: incremental import create pack from stdin' '
487 git fast-import <input &&
488 git whatchanged branch
491 test_expect_success 'C: verify pack' '
492 verify_packs
495 test_expect_success 'C: validate reuse existing blob' '
496 test $newf = `git rev-parse --verify branch:file2/newf` &&
497 test $oldf = `git rev-parse --verify branch:file2/oldf`
500 cat >expect <<EOF
501 parent `git rev-parse --verify master^0`
502 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
503 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
505 second
507 test_expect_success 'C: verify commit' '
508 git cat-file commit branch | sed 1d >actual &&
509 test_cmp expect actual
512 cat >expect <<EOF
513 :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
514 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
515 :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
517 git diff-tree -M -r master branch >actual
518 test_expect_success 'C: validate rename result' '
519 compare_diff_raw expect actual
523 ### series D
526 test_tick
527 cat >input <<INPUT_END
528 commit refs/heads/branch
529 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
530 data <<COMMIT
531 third
532 COMMIT
534 from refs/heads/branch^0
535 M 644 inline newdir/interesting
536 data <<EOF
537 $file5_data
540 M 755 inline newdir/exec.sh
541 data <<EOF
542 $file6_data
545 INPUT_END
546 test_expect_success 'D: inline data in commit' '
547 git fast-import <input &&
548 git whatchanged branch
551 test_expect_success 'D: verify pack' '
552 verify_packs
555 cat >expect <<EOF
556 :000000 100755 0000000000000000000000000000000000000000 e74b7d465e52746be2b4bae983670711e6e66657 A newdir/exec.sh
557 :000000 100644 0000000000000000000000000000000000000000 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 A newdir/interesting
559 git diff-tree -M -r branch^ branch >actual
560 test_expect_success 'D: validate new files added' '
561 compare_diff_raw expect actual
564 echo "$file5_data" >expect
565 test_expect_success 'D: verify file5' '
566 git cat-file blob branch:newdir/interesting >actual &&
567 test_cmp expect actual
570 echo "$file6_data" >expect
571 test_expect_success 'D: verify file6' '
572 git cat-file blob branch:newdir/exec.sh >actual &&
573 test_cmp expect actual
577 ### series E
580 cat >input <<INPUT_END
581 commit refs/heads/branch
582 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
583 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
584 data <<COMMIT
585 RFC 2822 type date
586 COMMIT
588 from refs/heads/branch^0
590 INPUT_END
591 test_expect_success 'E: rfc2822 date, --date-format=raw' '
592 test_must_fail git fast-import --date-format=raw <input
594 test_expect_success 'E: rfc2822 date, --date-format=rfc2822' '
595 git fast-import --date-format=rfc2822 <input
598 test_expect_success 'E: verify pack' '
599 verify_packs
602 cat >expect <<EOF
603 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
604 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
606 RFC 2822 type date
608 test_expect_success 'E: verify commit' '
609 git cat-file commit branch | sed 1,2d >actual &&
610 test_cmp expect actual
614 ### series F
617 old_branch=`git rev-parse --verify branch^0`
618 test_tick
619 cat >input <<INPUT_END
620 commit refs/heads/branch
621 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
622 data <<COMMIT
623 losing things already?
624 COMMIT
626 from refs/heads/branch~1
628 reset refs/heads/other
629 from refs/heads/branch
631 INPUT_END
632 test_expect_success 'F: non-fast-forward update skips' '
633 if git fast-import <input
634 then
635 echo BAD gfi did not fail
636 return 1
637 else
638 if test $old_branch = `git rev-parse --verify branch^0`
639 then
640 : branch unaffected and failure returned
641 return 0
642 else
643 echo BAD gfi changed branch $old_branch
644 return 1
649 test_expect_success 'F: verify pack' '
650 verify_packs
653 cat >expect <<EOF
654 tree `git rev-parse branch~1^{tree}`
655 parent `git rev-parse branch~1`
656 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
657 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
659 losing things already?
661 test_expect_success 'F: verify other commit' '
662 git cat-file commit other >actual &&
663 test_cmp expect actual
667 ### series G
670 old_branch=`git rev-parse --verify branch^0`
671 test_tick
672 cat >input <<INPUT_END
673 commit refs/heads/branch
674 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
675 data <<COMMIT
676 losing things already?
677 COMMIT
679 from refs/heads/branch~1
681 INPUT_END
682 test_expect_success 'G: non-fast-forward update forced' '
683 git fast-import --force <input
686 test_expect_success 'G: verify pack' '
687 verify_packs
690 test_expect_success 'G: branch changed, but logged' '
691 test $old_branch != `git rev-parse --verify branch^0` &&
692 test $old_branch = `git rev-parse --verify branch@{1}`
696 ### series H
699 test_tick
700 cat >input <<INPUT_END
701 commit refs/heads/H
702 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
703 data <<COMMIT
704 third
705 COMMIT
707 from refs/heads/branch^0
708 M 644 inline i-will-die
709 data <<EOF
710 this file will never exist.
713 deleteall
714 M 644 inline h/e/l/lo
715 data <<EOF
716 $file5_data
719 INPUT_END
720 test_expect_success 'H: deletall, add 1' '
721 git fast-import <input &&
722 git whatchanged H
725 test_expect_success 'H: verify pack' '
726 verify_packs
729 cat >expect <<EOF
730 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf
731 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf
732 :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4
733 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo
734 :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh
736 git diff-tree -M -r H^ H >actual
737 test_expect_success 'H: validate old files removed, new files added' '
738 compare_diff_raw expect actual
741 echo "$file5_data" >expect
742 test_expect_success 'H: verify file' '
743 git cat-file blob H:h/e/l/lo >actual &&
744 test_cmp expect actual
748 ### series I
751 cat >input <<INPUT_END
752 commit refs/heads/export-boundary
753 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
754 data <<COMMIT
755 we have a border. its only 40 characters wide.
756 COMMIT
758 from refs/heads/branch
760 INPUT_END
761 test_expect_success 'I: export-pack-edges' '
762 git fast-import --export-pack-edges=edges.list <input
765 cat >expect <<EOF
766 .git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
768 test_expect_success 'I: verify edge list' '
769 sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
770 test_cmp expect actual
774 ### series J
777 cat >input <<INPUT_END
778 commit refs/heads/J
779 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
780 data <<COMMIT
781 create J
782 COMMIT
784 from refs/heads/branch
786 reset refs/heads/J
788 commit refs/heads/J
789 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
790 data <<COMMIT
791 initialize J
792 COMMIT
794 INPUT_END
795 test_expect_success 'J: reset existing branch creates empty commit' '
796 git fast-import <input
798 test_expect_success 'J: branch has 1 commit, empty tree' '
799 test 1 = `git rev-list J | wc -l` &&
800 test 0 = `git ls-tree J | wc -l`
803 cat >input <<INPUT_END
804 reset refs/heads/J2
806 tag wrong_tag
807 from refs/heads/J2
808 data <<EOF
809 Tag branch that was reset.
811 INPUT_END
812 test_expect_success 'J: tag must fail on empty branch' '
813 test_must_fail git fast-import <input
816 ### series K
819 cat >input <<INPUT_END
820 commit refs/heads/K
821 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
822 data <<COMMIT
823 create K
824 COMMIT
826 from refs/heads/branch
828 commit refs/heads/K
829 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
830 data <<COMMIT
831 redo K
832 COMMIT
834 from refs/heads/branch^1
836 INPUT_END
837 test_expect_success 'K: reinit branch with from' '
838 git fast-import <input
840 test_expect_success 'K: verify K^1 = branch^1' '
841 test `git rev-parse --verify branch^1` \
842 = `git rev-parse --verify K^1`
846 ### series L
849 cat >input <<INPUT_END
850 blob
851 mark :1
852 data <<EOF
853 some data
856 blob
857 mark :2
858 data <<EOF
859 other data
862 commit refs/heads/L
863 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
864 data <<COMMIT
865 create L
866 COMMIT
868 M 644 :1 b.
869 M 644 :1 b/other
870 M 644 :1 ba
872 commit refs/heads/L
873 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
874 data <<COMMIT
875 update L
876 COMMIT
878 M 644 :2 b.
879 M 644 :2 b/other
880 M 644 :2 ba
881 INPUT_END
883 cat >expect <<EXPECT_END
884 :100644 100644 4268632... 55d3a52... M b.
885 :040000 040000 0ae5cac... 443c768... M b
886 :100644 100644 4268632... 55d3a52... M ba
887 EXPECT_END
889 test_expect_success 'L: verify internal tree sorting' '
890 git fast-import <input &&
891 git diff-tree --abbrev --raw L^ L >output &&
892 test_cmp expect output
895 cat >input <<INPUT_END
896 blob
897 mark :1
898 data <<EOF
899 the data
902 commit refs/heads/L2
903 committer C O Mitter <committer@example.com> 1112912473 -0700
904 data <<COMMIT
905 init L2
906 COMMIT
907 M 644 :1 a/b/c
908 M 644 :1 a/b/d
909 M 644 :1 a/e/f
911 commit refs/heads/L2
912 committer C O Mitter <committer@example.com> 1112912473 -0700
913 data <<COMMIT
914 update L2
915 COMMIT
916 C a g
917 C a/e g/b
918 M 644 :1 g/b/h
919 INPUT_END
921 cat <<EOF >expect
922 g/b/f
923 g/b/h
926 test_expect_success 'L: nested tree copy does not corrupt deltas' '
927 git fast-import <input &&
928 git ls-tree L2 g/b/ >tmp &&
929 cat tmp | cut -f 2 >actual &&
930 test_cmp expect actual &&
931 git fsck `git rev-parse L2`
934 git update-ref -d refs/heads/L2
937 ### series M
940 test_tick
941 cat >input <<INPUT_END
942 commit refs/heads/M1
943 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
944 data <<COMMIT
945 file rename
946 COMMIT
948 from refs/heads/branch^0
949 R file2/newf file2/n.e.w.f
951 INPUT_END
953 cat >expect <<EOF
954 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f
956 test_expect_success 'M: rename file in same subdirectory' '
957 git fast-import <input &&
958 git diff-tree -M -r M1^ M1 >actual &&
959 compare_diff_raw expect actual
962 cat >input <<INPUT_END
963 commit refs/heads/M2
964 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
965 data <<COMMIT
966 file rename
967 COMMIT
969 from refs/heads/branch^0
970 R file2/newf i/am/new/to/you
972 INPUT_END
974 cat >expect <<EOF
975 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you
977 test_expect_success 'M: rename file to new subdirectory' '
978 git fast-import <input &&
979 git diff-tree -M -r M2^ M2 >actual &&
980 compare_diff_raw expect actual
983 cat >input <<INPUT_END
984 commit refs/heads/M3
985 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
986 data <<COMMIT
987 file rename
988 COMMIT
990 from refs/heads/M2^0
991 R i other/sub
993 INPUT_END
995 cat >expect <<EOF
996 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you
998 test_expect_success 'M: rename subdirectory to new subdirectory' '
999 git fast-import <input &&
1000 git diff-tree -M -r M3^ M3 >actual &&
1001 compare_diff_raw expect actual
1004 cat >input <<INPUT_END
1005 commit refs/heads/M4
1006 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1007 data <<COMMIT
1008 rename root
1009 COMMIT
1011 from refs/heads/M2^0
1012 R "" sub
1014 INPUT_END
1016 cat >expect <<EOF
1017 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2/oldf sub/file2/oldf
1018 :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 R100 file4 sub/file4
1019 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you sub/i/am/new/to/you
1020 :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 R100 newdir/exec.sh sub/newdir/exec.sh
1021 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting sub/newdir/interesting
1023 test_expect_success 'M: rename root to subdirectory' '
1024 git fast-import <input &&
1025 git diff-tree -M -r M4^ M4 >actual &&
1026 cat actual &&
1027 compare_diff_raw expect actual
1031 ### series N
1034 test_tick
1035 cat >input <<INPUT_END
1036 commit refs/heads/N1
1037 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1038 data <<COMMIT
1039 file copy
1040 COMMIT
1042 from refs/heads/branch^0
1043 C file2/newf file2/n.e.w.f
1045 INPUT_END
1047 cat >expect <<EOF
1048 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f
1050 test_expect_success 'N: copy file in same subdirectory' '
1051 git fast-import <input &&
1052 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1053 compare_diff_raw expect actual
1056 cat >input <<INPUT_END
1057 commit refs/heads/N2
1058 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1059 data <<COMMIT
1060 clean directory copy
1061 COMMIT
1063 from refs/heads/branch^0
1064 C file2 file3
1066 commit refs/heads/N2
1067 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1068 data <<COMMIT
1069 modify directory copy
1070 COMMIT
1072 M 644 inline file3/file5
1073 data <<EOF
1074 $file5_data
1077 INPUT_END
1079 cat >expect <<EOF
1080 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1081 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1082 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1084 test_expect_success 'N: copy then modify subdirectory' '
1085 git fast-import <input &&
1086 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1087 compare_diff_raw expect actual
1090 cat >input <<INPUT_END
1091 commit refs/heads/N3
1092 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1093 data <<COMMIT
1094 dirty directory copy
1095 COMMIT
1097 from refs/heads/branch^0
1098 M 644 inline file2/file5
1099 data <<EOF
1100 $file5_data
1103 C file2 file3
1104 D file2/file5
1106 INPUT_END
1108 test_expect_success 'N: copy dirty subdirectory' '
1109 git fast-import <input &&
1110 test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`
1113 test_expect_success 'N: copy directory by id' '
1114 cat >expect <<-\EOF &&
1115 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1116 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1118 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1119 cat >input <<-INPUT_END &&
1120 commit refs/heads/N4
1121 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1122 data <<COMMIT
1123 copy by tree hash
1124 COMMIT
1126 from refs/heads/branch^0
1127 M 040000 $subdir file3
1128 INPUT_END
1129 git fast-import <input &&
1130 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1131 compare_diff_raw expect actual
1134 test_expect_success PIPE 'N: read and copy directory' '
1135 cat >expect <<-\EOF &&
1136 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1137 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1139 git update-ref -d refs/heads/N4 &&
1140 rm -f backflow &&
1141 mkfifo backflow &&
1143 exec <backflow &&
1144 cat <<-EOF &&
1145 commit refs/heads/N4
1146 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1147 data <<COMMIT
1148 copy by tree hash, part 2
1149 COMMIT
1151 from refs/heads/branch^0
1152 ls "file2"
1154 read mode type tree filename &&
1155 echo "M 040000 $tree file3"
1157 git fast-import --cat-blob-fd=3 3>backflow &&
1158 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1159 compare_diff_raw expect actual
1162 test_expect_success PIPE 'N: empty directory reads as missing' '
1163 cat <<-\EOF >expect &&
1164 OBJNAME
1165 :000000 100644 OBJNAME OBJNAME A unrelated
1167 echo "missing src" >expect.response &&
1168 git update-ref -d refs/heads/read-empty &&
1169 rm -f backflow &&
1170 mkfifo backflow &&
1172 exec <backflow &&
1173 cat <<-EOF &&
1174 commit refs/heads/read-empty
1175 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1176 data <<COMMIT
1177 read "empty" (missing) directory
1178 COMMIT
1180 M 100644 inline src/greeting
1181 data <<BLOB
1182 hello
1183 BLOB
1184 C src/greeting dst1/non-greeting
1185 C src/greeting unrelated
1186 # leave behind "empty" src directory
1187 D src/greeting
1188 ls "src"
1190 read -r line &&
1191 printf "%s\n" "$line" >response &&
1192 cat <<-\EOF
1193 D dst1
1194 D dst2
1197 git fast-import --cat-blob-fd=3 3>backflow &&
1198 test_cmp expect.response response &&
1199 git rev-list read-empty |
1200 git diff-tree -r --root --stdin |
1201 sed "s/$_x40/OBJNAME/g" >actual &&
1202 test_cmp expect actual
1205 test_expect_success 'N: copy root directory by tree hash' '
1206 cat >expect <<-\EOF &&
1207 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file3/newf
1208 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file3/oldf
1210 root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1211 cat >input <<-INPUT_END &&
1212 commit refs/heads/N6
1213 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1214 data <<COMMIT
1215 copy root directory by tree hash
1216 COMMIT
1218 from refs/heads/branch^0
1219 M 040000 $root ""
1220 INPUT_END
1221 git fast-import <input &&
1222 git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1223 compare_diff_raw expect actual
1226 test_expect_success 'N: copy root by path' '
1227 cat >expect <<-\EOF &&
1228 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf oldroot/file2/newf
1229 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf oldroot/file2/oldf
1230 :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 C100 file4 oldroot/file4
1231 :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 C100 newdir/exec.sh oldroot/newdir/exec.sh
1232 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting oldroot/newdir/interesting
1234 cat >input <<-INPUT_END &&
1235 commit refs/heads/N-copy-root-path
1236 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1237 data <<COMMIT
1238 copy root directory by (empty) path
1239 COMMIT
1241 from refs/heads/branch^0
1242 C "" oldroot
1243 INPUT_END
1244 git fast-import <input &&
1245 git diff-tree -C --find-copies-harder -r branch N-copy-root-path >actual &&
1246 compare_diff_raw expect actual
1249 test_expect_success 'N: delete directory by copying' '
1250 cat >expect <<-\EOF &&
1251 OBJID
1252 :100644 000000 OBJID OBJID D foo/bar/qux
1253 OBJID
1254 :000000 100644 OBJID OBJID A foo/bar/baz
1255 :000000 100644 OBJID OBJID A foo/bar/qux
1257 empty_tree=$(git mktree </dev/null) &&
1258 cat >input <<-INPUT_END &&
1259 commit refs/heads/N-delete
1260 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1261 data <<COMMIT
1262 collect data to be deleted
1263 COMMIT
1265 deleteall
1266 M 100644 inline foo/bar/baz
1267 data <<DATA_END
1268 hello
1269 DATA_END
1270 C "foo/bar/baz" "foo/bar/qux"
1271 C "foo/bar/baz" "foo/bar/quux/1"
1272 C "foo/bar/baz" "foo/bar/quuux"
1273 M 040000 $empty_tree foo/bar/quux
1274 M 040000 $empty_tree foo/bar/quuux
1276 commit refs/heads/N-delete
1277 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1278 data <<COMMIT
1279 delete subdirectory
1280 COMMIT
1282 M 040000 $empty_tree foo/bar/qux
1283 INPUT_END
1284 git fast-import <input &&
1285 git rev-list N-delete |
1286 git diff-tree -r --stdin --root --always |
1287 sed -e "s/$_x40/OBJID/g" >actual &&
1288 test_cmp expect actual
1291 test_expect_success 'N: modify copied tree' '
1292 cat >expect <<-\EOF &&
1293 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1294 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1295 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1297 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1298 cat >input <<-INPUT_END &&
1299 commit refs/heads/N5
1300 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1301 data <<COMMIT
1302 copy by tree hash
1303 COMMIT
1305 from refs/heads/branch^0
1306 M 040000 $subdir file3
1308 commit refs/heads/N5
1309 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1310 data <<COMMIT
1311 modify directory copy
1312 COMMIT
1314 M 644 inline file3/file5
1315 data <<EOF
1316 $file5_data
1318 INPUT_END
1319 git fast-import <input &&
1320 git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1321 compare_diff_raw expect actual
1324 test_expect_success 'N: reject foo/ syntax' '
1325 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1326 test_must_fail git fast-import <<-INPUT_END
1327 commit refs/heads/N5B
1328 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1329 data <<COMMIT
1330 copy with invalid syntax
1331 COMMIT
1333 from refs/heads/branch^0
1334 M 040000 $subdir file3/
1335 INPUT_END
1338 test_expect_success 'N: reject foo/ syntax in copy source' '
1339 test_must_fail git fast-import <<-INPUT_END
1340 commit refs/heads/N5C
1341 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1342 data <<COMMIT
1343 copy with invalid syntax
1344 COMMIT
1346 from refs/heads/branch^0
1347 C file2/ file3
1348 INPUT_END
1351 test_expect_success 'N: reject foo/ syntax in rename source' '
1352 test_must_fail git fast-import <<-INPUT_END
1353 commit refs/heads/N5D
1354 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1355 data <<COMMIT
1356 rename with invalid syntax
1357 COMMIT
1359 from refs/heads/branch^0
1360 R file2/ file3
1361 INPUT_END
1364 test_expect_success 'N: reject foo/ syntax in ls argument' '
1365 test_must_fail git fast-import <<-INPUT_END
1366 commit refs/heads/N5E
1367 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1368 data <<COMMIT
1369 copy with invalid syntax
1370 COMMIT
1372 from refs/heads/branch^0
1373 ls "file2/"
1374 INPUT_END
1377 test_expect_success 'N: copy to root by id and modify' '
1378 echo "hello, world" >expect.foo &&
1379 echo hello >expect.bar &&
1380 git fast-import <<-SETUP_END &&
1381 commit refs/heads/N7
1382 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1383 data <<COMMIT
1384 hello, tree
1385 COMMIT
1387 deleteall
1388 M 644 inline foo/bar
1389 data <<EOF
1390 hello
1392 SETUP_END
1394 tree=$(git rev-parse --verify N7:) &&
1395 git fast-import <<-INPUT_END &&
1396 commit refs/heads/N8
1397 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1398 data <<COMMIT
1399 copy to root by id and modify
1400 COMMIT
1402 M 040000 $tree ""
1403 M 644 inline foo/foo
1404 data <<EOF
1405 hello, world
1407 INPUT_END
1408 git show N8:foo/foo >actual.foo &&
1409 git show N8:foo/bar >actual.bar &&
1410 test_cmp expect.foo actual.foo &&
1411 test_cmp expect.bar actual.bar
1414 test_expect_success 'N: extract subtree' '
1415 branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1416 cat >input <<-INPUT_END &&
1417 commit refs/heads/N9
1418 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1419 data <<COMMIT
1420 extract subtree branch:newdir
1421 COMMIT
1423 M 040000 $branch ""
1424 C "newdir" ""
1425 INPUT_END
1426 git fast-import <input &&
1427 git diff --exit-code branch:newdir N9
1430 test_expect_success 'N: modify subtree, extract it, and modify again' '
1431 echo hello >expect.baz &&
1432 echo hello, world >expect.qux &&
1433 git fast-import <<-SETUP_END &&
1434 commit refs/heads/N10
1435 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1436 data <<COMMIT
1437 hello, tree
1438 COMMIT
1440 deleteall
1441 M 644 inline foo/bar/baz
1442 data <<EOF
1443 hello
1445 SETUP_END
1447 tree=$(git rev-parse --verify N10:) &&
1448 git fast-import <<-INPUT_END &&
1449 commit refs/heads/N11
1450 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1451 data <<COMMIT
1452 copy to root by id and modify
1453 COMMIT
1455 M 040000 $tree ""
1456 M 100644 inline foo/bar/qux
1457 data <<EOF
1458 hello, world
1460 R "foo" ""
1461 C "bar/qux" "bar/quux"
1462 INPUT_END
1463 git show N11:bar/baz >actual.baz &&
1464 git show N11:bar/qux >actual.qux &&
1465 git show N11:bar/quux >actual.quux &&
1466 test_cmp expect.baz actual.baz &&
1467 test_cmp expect.qux actual.qux &&
1468 test_cmp expect.qux actual.quux'
1471 ### series O
1474 cat >input <<INPUT_END
1475 #we will
1476 commit refs/heads/O1
1477 # -- ignore all of this text
1478 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1479 # $GIT_COMMITTER_NAME has inserted here for his benefit.
1480 data <<COMMIT
1481 dirty directory copy
1482 COMMIT
1484 # don't forget the import blank line!
1486 # yes, we started from our usual base of branch^0.
1487 # i like branch^0.
1488 from refs/heads/branch^0
1489 # and we need to reuse file2/file5 from N3 above.
1490 M 644 inline file2/file5
1491 # otherwise the tree will be different
1492 data <<EOF
1493 $file5_data
1496 # don't forget to copy file2 to file3
1497 C file2 file3
1499 # or to delete file5 from file2.
1500 D file2/file5
1501 # are we done yet?
1503 INPUT_END
1505 test_expect_success 'O: comments are all skipped' '
1506 git fast-import <input &&
1507 test `git rev-parse N3` = `git rev-parse O1`
1510 cat >input <<INPUT_END
1511 commit refs/heads/O2
1512 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1513 data <<COMMIT
1514 dirty directory copy
1515 COMMIT
1516 from refs/heads/branch^0
1517 M 644 inline file2/file5
1518 data <<EOF
1519 $file5_data
1521 C file2 file3
1522 D file2/file5
1524 INPUT_END
1526 test_expect_success 'O: blank lines not necessary after data commands' '
1527 git fast-import <input &&
1528 test `git rev-parse N3` = `git rev-parse O2`
1531 test_expect_success 'O: repack before next test' '
1532 git repack -a -d
1535 cat >input <<INPUT_END
1536 commit refs/heads/O3
1537 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1538 data <<COMMIT
1539 zstring
1540 COMMIT
1541 commit refs/heads/O3
1542 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1543 data <<COMMIT
1545 COMMIT
1546 checkpoint
1547 commit refs/heads/O3
1548 mark :5
1549 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1550 data <<COMMIT
1551 zempty
1552 COMMIT
1553 checkpoint
1554 commit refs/heads/O3
1555 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1556 data <<COMMIT
1557 zcommits
1558 COMMIT
1559 reset refs/tags/O3-2nd
1560 from :5
1561 reset refs/tags/O3-3rd
1562 from :5
1563 INPUT_END
1565 cat >expect <<INPUT_END
1566 string
1568 empty
1569 commits
1570 INPUT_END
1571 test_expect_success 'O: blank lines not necessary after other commands' '
1572 git fast-import <input &&
1573 test 8 = `find .git/objects/pack -type f | wc -l` &&
1574 test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
1575 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1576 test_cmp expect actual
1579 cat >input <<INPUT_END
1580 commit refs/heads/O4
1581 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1582 data <<COMMIT
1583 zstring
1584 COMMIT
1585 commit refs/heads/O4
1586 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1587 data <<COMMIT
1589 COMMIT
1590 progress Two commits down, 2 to go!
1591 commit refs/heads/O4
1592 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1593 data <<COMMIT
1594 zempty
1595 COMMIT
1596 progress Three commits down, 1 to go!
1597 commit refs/heads/O4
1598 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1599 data <<COMMIT
1600 zcommits
1601 COMMIT
1602 progress I'm done!
1603 INPUT_END
1604 test_expect_success 'O: progress outputs as requested by input' '
1605 git fast-import <input >actual &&
1606 grep "progress " <input >expect &&
1607 test_cmp expect actual
1611 ### series P (gitlinks)
1614 cat >input <<INPUT_END
1615 blob
1616 mark :1
1617 data 10
1618 test file
1620 reset refs/heads/sub
1621 commit refs/heads/sub
1622 mark :2
1623 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1624 data 12
1625 sub_initial
1626 M 100644 :1 file
1628 blob
1629 mark :3
1630 data <<DATAEND
1631 [submodule "sub"]
1632 path = sub
1633 url = "`pwd`/sub"
1634 DATAEND
1636 commit refs/heads/subuse1
1637 mark :4
1638 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1639 data 8
1640 initial
1641 from refs/heads/master
1642 M 100644 :3 .gitmodules
1643 M 160000 :2 sub
1645 blob
1646 mark :5
1647 data 20
1648 test file
1649 more data
1651 commit refs/heads/sub
1652 mark :6
1653 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1654 data 11
1655 sub_second
1656 from :2
1657 M 100644 :5 file
1659 commit refs/heads/subuse1
1660 mark :7
1661 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1662 data 7
1663 second
1664 from :4
1665 M 160000 :6 sub
1667 INPUT_END
1669 test_expect_success 'P: superproject & submodule mix' '
1670 git fast-import <input &&
1671 git checkout subuse1 &&
1672 rm -rf sub && mkdir sub && (cd sub &&
1673 git init &&
1674 git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1675 git checkout master) &&
1676 git submodule init &&
1677 git submodule update
1680 SUBLAST=$(git rev-parse --verify sub)
1681 SUBPREV=$(git rev-parse --verify sub^)
1683 cat >input <<INPUT_END
1684 blob
1685 mark :1
1686 data <<DATAEND
1687 [submodule "sub"]
1688 path = sub
1689 url = "`pwd`/sub"
1690 DATAEND
1692 commit refs/heads/subuse2
1693 mark :2
1694 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1695 data 8
1696 initial
1697 from refs/heads/master
1698 M 100644 :1 .gitmodules
1699 M 160000 $SUBPREV sub
1701 commit refs/heads/subuse2
1702 mark :3
1703 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1704 data 7
1705 second
1706 from :2
1707 M 160000 $SUBLAST sub
1709 INPUT_END
1711 test_expect_success 'P: verbatim SHA gitlinks' '
1712 git branch -D sub &&
1713 git gc && git prune &&
1714 git fast-import <input &&
1715 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)
1718 test_tick
1719 cat >input <<INPUT_END
1720 commit refs/heads/subuse3
1721 mark :1
1722 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1723 data <<COMMIT
1724 corrupt
1725 COMMIT
1727 from refs/heads/subuse2
1728 M 160000 inline sub
1729 data <<DATA
1730 $SUBPREV
1731 DATA
1733 INPUT_END
1735 test_expect_success 'P: fail on inline gitlink' '
1736 test_must_fail git fast-import <input
1739 test_tick
1740 cat >input <<INPUT_END
1741 blob
1742 mark :1
1743 data <<DATA
1744 $SUBPREV
1745 DATA
1747 commit refs/heads/subuse3
1748 mark :2
1749 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1750 data <<COMMIT
1751 corrupt
1752 COMMIT
1754 from refs/heads/subuse2
1755 M 160000 :1 sub
1757 INPUT_END
1759 test_expect_success 'P: fail on blob mark in gitlink' '
1760 test_must_fail git fast-import <input
1764 ### series Q (notes)
1767 note1_data="The first note for the first commit"
1768 note2_data="The first note for the second commit"
1769 note3_data="The first note for the third commit"
1770 note1b_data="The second note for the first commit"
1771 note1c_data="The third note for the first commit"
1772 note2b_data="The second note for the second commit"
1774 test_tick
1775 cat >input <<INPUT_END
1776 blob
1777 mark :2
1778 data <<EOF
1779 $file2_data
1782 commit refs/heads/notes-test
1783 mark :3
1784 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1785 data <<COMMIT
1786 first (:3)
1787 COMMIT
1789 M 644 :2 file2
1791 blob
1792 mark :4
1793 data $file4_len
1794 $file4_data
1795 commit refs/heads/notes-test
1796 mark :5
1797 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1798 data <<COMMIT
1799 second (:5)
1800 COMMIT
1802 M 644 :4 file4
1804 commit refs/heads/notes-test
1805 mark :6
1806 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1807 data <<COMMIT
1808 third (:6)
1809 COMMIT
1811 M 644 inline file5
1812 data <<EOF
1813 $file5_data
1816 M 755 inline file6
1817 data <<EOF
1818 $file6_data
1821 blob
1822 mark :7
1823 data <<EOF
1824 $note1_data
1827 blob
1828 mark :8
1829 data <<EOF
1830 $note2_data
1833 commit refs/notes/foobar
1834 mark :9
1835 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1836 data <<COMMIT
1837 notes (:9)
1838 COMMIT
1840 N :7 :3
1841 N :8 :5
1842 N inline :6
1843 data <<EOF
1844 $note3_data
1847 commit refs/notes/foobar
1848 mark :10
1849 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1850 data <<COMMIT
1851 notes (:10)
1852 COMMIT
1854 N inline :3
1855 data <<EOF
1856 $note1b_data
1859 commit refs/notes/foobar2
1860 mark :11
1861 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1862 data <<COMMIT
1863 notes (:11)
1864 COMMIT
1866 N inline :3
1867 data <<EOF
1868 $note1c_data
1871 commit refs/notes/foobar
1872 mark :12
1873 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1874 data <<COMMIT
1875 notes (:12)
1876 COMMIT
1878 deleteall
1879 N inline :5
1880 data <<EOF
1881 $note2b_data
1884 INPUT_END
1886 test_expect_success 'Q: commit notes' '
1887 git fast-import <input &&
1888 git whatchanged notes-test
1891 test_expect_success 'Q: verify pack' '
1892 verify_packs
1895 commit1=$(git rev-parse notes-test~2)
1896 commit2=$(git rev-parse notes-test^)
1897 commit3=$(git rev-parse notes-test)
1899 cat >expect <<EOF
1900 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1901 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1903 first (:3)
1905 test_expect_success 'Q: verify first commit' '
1906 git cat-file commit notes-test~2 | sed 1d >actual &&
1907 test_cmp expect actual
1910 cat >expect <<EOF
1911 parent $commit1
1912 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1913 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1915 second (:5)
1917 test_expect_success 'Q: verify second commit' '
1918 git cat-file commit notes-test^ | sed 1d >actual &&
1919 test_cmp expect actual
1922 cat >expect <<EOF
1923 parent $commit2
1924 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1925 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1927 third (:6)
1929 test_expect_success 'Q: verify third commit' '
1930 git cat-file commit notes-test | sed 1d >actual &&
1931 test_cmp expect actual
1934 cat >expect <<EOF
1935 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1936 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1938 notes (:9)
1940 test_expect_success 'Q: verify first notes commit' '
1941 git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1942 test_cmp expect actual
1945 cat >expect.unsorted <<EOF
1946 100644 blob $commit1
1947 100644 blob $commit2
1948 100644 blob $commit3
1950 cat expect.unsorted | sort >expect
1951 test_expect_success 'Q: verify first notes tree' '
1952 git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1953 test_cmp expect actual
1956 echo "$note1_data" >expect
1957 test_expect_success 'Q: verify first note for first commit' '
1958 git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual
1961 echo "$note2_data" >expect
1962 test_expect_success 'Q: verify first note for second commit' '
1963 git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual
1966 echo "$note3_data" >expect
1967 test_expect_success 'Q: verify first note for third commit' '
1968 git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual
1971 cat >expect <<EOF
1972 parent `git rev-parse --verify refs/notes/foobar~2`
1973 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1974 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1976 notes (:10)
1978 test_expect_success 'Q: verify second notes commit' '
1979 git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
1980 test_cmp expect actual
1983 cat >expect.unsorted <<EOF
1984 100644 blob $commit1
1985 100644 blob $commit2
1986 100644 blob $commit3
1988 cat expect.unsorted | sort >expect
1989 test_expect_success 'Q: verify second notes tree' '
1990 git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1991 test_cmp expect actual
1994 echo "$note1b_data" >expect
1995 test_expect_success 'Q: verify second note for first commit' '
1996 git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual
1999 echo "$note2_data" >expect
2000 test_expect_success 'Q: verify first note for second commit' '
2001 git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual
2004 echo "$note3_data" >expect
2005 test_expect_success 'Q: verify first note for third commit' '
2006 git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual
2009 cat >expect <<EOF
2010 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2011 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2013 notes (:11)
2015 test_expect_success 'Q: verify third notes commit' '
2016 git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
2017 test_cmp expect actual
2020 cat >expect.unsorted <<EOF
2021 100644 blob $commit1
2023 cat expect.unsorted | sort >expect
2024 test_expect_success 'Q: verify third notes tree' '
2025 git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2026 test_cmp expect actual
2029 echo "$note1c_data" >expect
2030 test_expect_success 'Q: verify third note for first commit' '
2031 git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual
2034 cat >expect <<EOF
2035 parent `git rev-parse --verify refs/notes/foobar^`
2036 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2037 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2039 notes (:12)
2041 test_expect_success 'Q: verify fourth notes commit' '
2042 git cat-file commit refs/notes/foobar | sed 1d >actual &&
2043 test_cmp expect actual
2046 cat >expect.unsorted <<EOF
2047 100644 blob $commit2
2049 cat expect.unsorted | sort >expect
2050 test_expect_success 'Q: verify fourth notes tree' '
2051 git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2052 test_cmp expect actual
2055 echo "$note2b_data" >expect
2056 test_expect_success 'Q: verify second note for second commit' '
2057 git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual
2060 cat >input <<EOF
2061 reset refs/heads/Q0
2063 commit refs/heads/note-Q0
2064 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2065 data <<COMMIT
2066 Note for an empty branch.
2067 COMMIT
2069 N inline refs/heads/Q0
2070 data <<NOTE
2071 some note
2072 NOTE
2074 test_expect_success 'Q: deny note on empty branch' '
2075 test_must_fail git fast-import <input
2078 ### series R (feature and option)
2081 cat >input <<EOF
2082 feature no-such-feature-exists
2085 test_expect_success 'R: abort on unsupported feature' '
2086 test_must_fail git fast-import <input
2089 cat >input <<EOF
2090 feature date-format=now
2093 test_expect_success 'R: supported feature is accepted' '
2094 git fast-import <input
2097 cat >input << EOF
2098 blob
2099 data 3
2101 feature date-format=now
2104 test_expect_success 'R: abort on receiving feature after data command' '
2105 test_must_fail git fast-import <input
2108 cat >input << EOF
2109 feature import-marks=git.marks
2110 feature import-marks=git2.marks
2113 test_expect_success 'R: only one import-marks feature allowed per stream' '
2114 test_must_fail git fast-import <input
2117 cat >input << EOF
2118 feature export-marks=git.marks
2119 blob
2120 mark :1
2121 data 3
2126 test_expect_success 'R: export-marks feature results in a marks file being created' '
2127 cat input | git fast-import &&
2128 grep :1 git.marks
2131 test_expect_success 'R: export-marks options can be overridden by commandline options' '
2132 cat input | git fast-import --export-marks=other.marks &&
2133 grep :1 other.marks
2136 test_expect_success 'R: catch typo in marks file name' '
2137 test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2138 echo "feature import-marks=nonexistent.marks" |
2139 test_must_fail git fast-import
2142 test_expect_success 'R: import and output marks can be the same file' '
2143 rm -f io.marks &&
2144 blob=$(echo hi | git hash-object --stdin) &&
2145 cat >expect <<-EOF &&
2146 :1 $blob
2147 :2 $blob
2149 git fast-import --export-marks=io.marks <<-\EOF &&
2150 blob
2151 mark :1
2152 data 3
2156 git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2157 blob
2158 mark :2
2159 data 3
2163 test_cmp expect io.marks
2166 test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
2167 rm -f io.marks &&
2168 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2169 blob
2170 mark :1
2171 data 3
2177 test_expect_success 'R: --import-marks-if-exists' '
2178 rm -f io.marks &&
2179 blob=$(echo hi | git hash-object --stdin) &&
2180 echo ":1 $blob" >expect &&
2181 git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2182 blob
2183 mark :1
2184 data 3
2188 test_cmp expect io.marks
2191 test_expect_success 'R: feature import-marks-if-exists' '
2192 rm -f io.marks &&
2193 >expect &&
2195 git fast-import --export-marks=io.marks <<-\EOF &&
2196 feature import-marks-if-exists=not_io.marks
2198 test_cmp expect io.marks &&
2200 blob=$(echo hi | git hash-object --stdin) &&
2202 echo ":1 $blob" >io.marks &&
2203 echo ":1 $blob" >expect &&
2204 echo ":2 $blob" >>expect &&
2206 git fast-import --export-marks=io.marks <<-\EOF &&
2207 feature import-marks-if-exists=io.marks
2208 blob
2209 mark :2
2210 data 3
2214 test_cmp expect io.marks &&
2216 echo ":3 $blob" >>expect &&
2218 git fast-import --import-marks=io.marks \
2219 --export-marks=io.marks <<-\EOF &&
2220 feature import-marks-if-exists=not_io.marks
2221 blob
2222 mark :3
2223 data 3
2227 test_cmp expect io.marks &&
2229 >expect &&
2231 git fast-import --import-marks-if-exists=not_io.marks \
2232 --export-marks=io.marks <<-\EOF &&
2233 feature import-marks-if-exists=io.marks
2235 test_cmp expect io.marks
2238 cat >input << EOF
2239 feature import-marks=marks.out
2240 feature export-marks=marks.new
2243 test_expect_success 'R: import to output marks works without any content' '
2244 cat input | git fast-import &&
2245 test_cmp marks.out marks.new
2248 cat >input <<EOF
2249 feature import-marks=nonexistent.marks
2250 feature export-marks=marks.new
2253 test_expect_success 'R: import marks prefers commandline marks file over the stream' '
2254 cat input | git fast-import --import-marks=marks.out &&
2255 test_cmp marks.out marks.new
2259 cat >input <<EOF
2260 feature import-marks=nonexistent.marks
2261 feature export-marks=combined.marks
2264 test_expect_success 'R: multiple --import-marks= should be honoured' '
2265 head -n2 marks.out > one.marks &&
2266 tail -n +3 marks.out > two.marks &&
2267 git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
2268 test_cmp marks.out combined.marks
2271 cat >input <<EOF
2272 feature relative-marks
2273 feature import-marks=relative.in
2274 feature export-marks=relative.out
2277 test_expect_success 'R: feature relative-marks should be honoured' '
2278 mkdir -p .git/info/fast-import/ &&
2279 cp marks.new .git/info/fast-import/relative.in &&
2280 git fast-import <input &&
2281 test_cmp marks.new .git/info/fast-import/relative.out
2284 cat >input <<EOF
2285 feature relative-marks
2286 feature import-marks=relative.in
2287 feature no-relative-marks
2288 feature export-marks=non-relative.out
2291 test_expect_success 'R: feature no-relative-marks should be honoured' '
2292 git fast-import <input &&
2293 test_cmp marks.new non-relative.out
2296 test_expect_success 'R: feature ls supported' '
2297 echo "feature ls" |
2298 git fast-import
2301 test_expect_success 'R: feature cat-blob supported' '
2302 echo "feature cat-blob" |
2303 git fast-import
2306 test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
2307 test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2310 test_expect_success !MINGW 'R: print old blob' '
2311 blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2312 cat >expect <<-EOF &&
2313 ${blob} blob 11
2314 yes it can
2317 echo "cat-blob $blob" |
2318 git fast-import --cat-blob-fd=6 6>actual &&
2319 test_cmp expect actual
2322 test_expect_success !MINGW 'R: in-stream cat-blob-fd not respected' '
2323 echo hello >greeting &&
2324 blob=$(git hash-object -w greeting) &&
2325 cat >expect <<-EOF &&
2326 ${blob} blob 6
2327 hello
2330 git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2331 cat-blob $blob
2333 test_cmp expect actual.3 &&
2334 test_cmp empty actual.1 &&
2335 git fast-import 3>actual.3 >actual.1 <<-EOF &&
2336 option cat-blob-fd=3
2337 cat-blob $blob
2339 test_cmp empty actual.3 &&
2340 test_cmp expect actual.1
2343 test_expect_success !MINGW 'R: print mark for new blob' '
2344 echo "effluentish" | git hash-object --stdin >expect &&
2345 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2346 blob
2347 mark :1
2348 data <<BLOB_END
2349 effluentish
2350 BLOB_END
2351 get-mark :1
2353 test_cmp expect actual
2356 test_expect_success !MINGW 'R: print new blob' '
2357 blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2358 cat >expect <<-EOF &&
2359 ${blob} blob 12
2360 yep yep yep
2363 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2364 blob
2365 mark :1
2366 data <<BLOB_END
2367 yep yep yep
2368 BLOB_END
2369 cat-blob :1
2371 test_cmp expect actual
2374 test_expect_success !MINGW 'R: print new blob by sha1' '
2375 blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2376 cat >expect <<-EOF &&
2377 ${blob} blob 25
2378 a new blob named by sha1
2381 git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2382 blob
2383 data <<BLOB_END
2384 a new blob named by sha1
2385 BLOB_END
2386 cat-blob $blob
2388 test_cmp expect actual
2391 test_expect_success 'setup: big file' '
2393 echo "the quick brown fox jumps over the lazy dog" >big &&
2394 for i in 1 2 3
2396 cat big big big big >bigger &&
2397 cat bigger bigger bigger bigger >big ||
2398 exit
2399 done
2403 test_expect_success 'R: print two blobs to stdout' '
2404 blob1=$(git hash-object big) &&
2405 blob1_len=$(wc -c <big) &&
2406 blob2=$(echo hello | git hash-object --stdin) &&
2408 echo ${blob1} blob $blob1_len &&
2409 cat big &&
2410 cat <<-EOF
2412 ${blob2} blob 6
2413 hello
2416 } >expect &&
2418 cat <<-\END_PART1 &&
2419 blob
2420 mark :1
2421 data <<data_end
2422 END_PART1
2423 cat big &&
2424 cat <<-\EOF
2425 data_end
2426 blob
2427 mark :2
2428 data <<data_end
2429 hello
2430 data_end
2431 cat-blob :1
2432 cat-blob :2
2435 git fast-import >actual &&
2436 test_cmp expect actual
2439 test_expect_success PIPE 'R: copy using cat-file' '
2440 expect_id=$(git hash-object big) &&
2441 expect_len=$(wc -c <big) &&
2442 echo $expect_id blob $expect_len >expect.response &&
2444 rm -f blobs &&
2445 cat >frontend <<-\FRONTEND_END &&
2446 #!/bin/sh
2447 FRONTEND_END
2449 mkfifo blobs &&
2451 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2452 cat <<-\EOF &&
2453 feature cat-blob
2454 blob
2455 mark :1
2456 data <<BLOB
2458 cat big &&
2459 cat <<-\EOF &&
2460 BLOB
2461 cat-blob :1
2464 read blob_id type size <&3 &&
2465 echo "$blob_id $type $size" >response &&
2466 head_c $size >blob <&3 &&
2467 read newline <&3 &&
2469 cat <<-EOF &&
2470 commit refs/heads/copied
2471 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2472 data <<COMMIT
2473 copy big file as file3
2474 COMMIT
2475 M 644 inline file3
2476 data <<BLOB
2478 cat blob &&
2479 echo BLOB
2480 ) 3<blobs |
2481 git fast-import --cat-blob-fd=3 3>blobs &&
2482 git show copied:file3 >actual &&
2483 test_cmp expect.response response &&
2484 test_cmp big actual
2487 test_expect_success PIPE 'R: print blob mid-commit' '
2488 rm -f blobs &&
2489 echo "A blob from _before_ the commit." >expect &&
2490 mkfifo blobs &&
2492 exec 3<blobs &&
2493 cat <<-EOF &&
2494 feature cat-blob
2495 blob
2496 mark :1
2497 data <<BLOB
2498 A blob from _before_ the commit.
2499 BLOB
2500 commit refs/heads/temporary
2501 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2502 data <<COMMIT
2503 Empty commit
2504 COMMIT
2505 cat-blob :1
2508 read blob_id type size <&3 &&
2509 head_c $size >actual <&3 &&
2510 read newline <&3 &&
2512 echo
2514 git fast-import --cat-blob-fd=3 3>blobs &&
2515 test_cmp expect actual
2518 test_expect_success PIPE 'R: print staged blob within commit' '
2519 rm -f blobs &&
2520 echo "A blob from _within_ the commit." >expect &&
2521 mkfifo blobs &&
2523 exec 3<blobs &&
2524 cat <<-EOF &&
2525 feature cat-blob
2526 commit refs/heads/within
2527 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2528 data <<COMMIT
2529 Empty commit
2530 COMMIT
2531 M 644 inline within
2532 data <<BLOB
2533 A blob from _within_ the commit.
2534 BLOB
2537 to_get=$(
2538 echo "A blob from _within_ the commit." |
2539 git hash-object --stdin
2540 ) &&
2541 echo "cat-blob $to_get" &&
2543 read blob_id type size <&3 &&
2544 head_c $size >actual <&3 &&
2545 read newline <&3 &&
2547 echo deleteall
2549 git fast-import --cat-blob-fd=3 3>blobs &&
2550 test_cmp expect actual
2553 cat >input << EOF
2554 option git quiet
2555 blob
2556 data 3
2561 test_expect_success 'R: quiet option results in no stats being output' '
2562 cat input | git fast-import 2> output &&
2563 test_cmp empty output
2566 test_expect_success 'R: feature done means terminating "done" is mandatory' '
2567 echo feature done | test_must_fail git fast-import &&
2568 test_must_fail git fast-import --done </dev/null
2571 test_expect_success 'R: terminating "done" with trailing gibberish is ok' '
2572 git fast-import <<-\EOF &&
2573 feature done
2574 done
2575 trailing gibberish
2577 git fast-import <<-\EOF
2578 done
2579 more trailing gibberish
2583 test_expect_success 'R: terminating "done" within commit' '
2584 cat >expect <<-\EOF &&
2585 OBJID
2586 :000000 100644 OBJID OBJID A hello.c
2587 :000000 100644 OBJID OBJID A hello2.c
2589 git fast-import <<-EOF &&
2590 commit refs/heads/done-ends
2591 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2592 data <<EOT
2593 Commit terminated by "done" command
2595 M 100644 inline hello.c
2596 data <<EOT
2597 Hello, world.
2599 C hello.c hello2.c
2600 done
2602 git rev-list done-ends |
2603 git diff-tree -r --stdin --root --always |
2604 sed -e "s/$_x40/OBJID/g" >actual &&
2605 test_cmp expect actual
2608 cat >input <<EOF
2609 option git non-existing-option
2612 test_expect_success 'R: die on unknown option' '
2613 test_must_fail git fast-import <input
2616 test_expect_success 'R: unknown commandline options are rejected' '\
2617 test_must_fail git fast-import --non-existing-option < /dev/null
2620 test_expect_success 'R: die on invalid option argument' '
2621 echo "option git active-branches=-5" |
2622 test_must_fail git fast-import &&
2623 echo "option git depth=" |
2624 test_must_fail git fast-import &&
2625 test_must_fail git fast-import --depth="5 elephants" </dev/null
2628 cat >input <<EOF
2629 option non-existing-vcs non-existing-option
2632 test_expect_success 'R: ignore non-git options' '
2633 git fast-import <input
2637 ## R: very large blobs
2639 blobsize=$((2*1024*1024 + 53))
2640 test-genrandom bar $blobsize >expect
2641 cat >input <<INPUT_END
2642 commit refs/heads/big-file
2643 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2644 data <<COMMIT
2645 R - big file
2646 COMMIT
2648 M 644 inline big1
2649 data $blobsize
2650 INPUT_END
2651 cat expect >>input
2652 cat >>input <<INPUT_END
2653 M 644 inline big2
2654 data $blobsize
2655 INPUT_END
2656 cat expect >>input
2657 echo >>input
2659 test_expect_success 'R: blob bigger than threshold' '
2660 test_create_repo R &&
2661 git --git-dir=R/.git fast-import --big-file-threshold=1 <input
2664 test_expect_success 'R: verify created pack' '
2666 cd R &&
2667 verify_packs -v > ../verify
2671 test_expect_success 'R: verify written objects' '
2672 git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2673 test_cmp_bin expect actual &&
2674 a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2675 b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2676 test $a = $b
2679 test_expect_success 'R: blob appears only once' '
2680 n=$(grep $a verify | wc -l) &&
2681 test 1 = $n
2685 ### series S
2688 # Make sure missing spaces and EOLs after mark references
2689 # cause errors.
2691 # Setup:
2693 # 1--2--4
2694 # \ /
2695 # -3-
2697 # commit marks: 301, 302, 303, 304
2698 # blob marks: 403, 404, resp.
2699 # note mark: 202
2701 # The error message when a space is missing not at the
2702 # end of the line is:
2704 # Missing space after ..
2706 # or when extra characters come after the mark at the end
2707 # of the line:
2709 # Garbage after ..
2711 # or when the dataref is neither "inline " or a known SHA1,
2713 # Invalid dataref ..
2715 test_tick
2717 cat >input <<INPUT_END
2718 commit refs/heads/S
2719 mark :301
2720 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2721 data <<COMMIT
2722 commit 1
2723 COMMIT
2724 M 100644 inline hello.c
2725 data <<BLOB
2726 blob 1
2727 BLOB
2729 commit refs/heads/S
2730 mark :302
2731 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2732 data <<COMMIT
2733 commit 2
2734 COMMIT
2735 from :301
2736 M 100644 inline hello.c
2737 data <<BLOB
2738 blob 2
2739 BLOB
2741 blob
2742 mark :403
2743 data <<BLOB
2744 blob 3
2745 BLOB
2747 blob
2748 mark :202
2749 data <<BLOB
2750 note 2
2751 BLOB
2752 INPUT_END
2754 test_expect_success 'S: initialize for S tests' '
2755 git fast-import --export-marks=marks <input
2759 # filemodify, three datarefs
2761 test_expect_success 'S: filemodify with garbage after mark must fail' '
2762 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2763 commit refs/heads/S
2764 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2765 data <<COMMIT
2766 commit N
2767 COMMIT
2768 M 100644 :403x hello.c
2770 cat err &&
2771 test_i18ngrep "space after mark" err
2774 # inline is misspelled; fast-import thinks it is some unknown dataref
2775 test_expect_success 'S: filemodify with garbage after inline must fail' '
2776 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2777 commit refs/heads/S
2778 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2779 data <<COMMIT
2780 commit N
2781 COMMIT
2782 M 100644 inlineX hello.c
2783 data <<BLOB
2784 inline
2785 BLOB
2787 cat err &&
2788 test_i18ngrep "nvalid dataref" err
2791 test_expect_success 'S: filemodify with garbage after sha1 must fail' '
2792 sha1=$(grep :403 marks | cut -d\ -f2) &&
2793 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2794 commit refs/heads/S
2795 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2796 data <<COMMIT
2797 commit N
2798 COMMIT
2799 M 100644 ${sha1}x hello.c
2801 cat err &&
2802 test_i18ngrep "space after SHA1" err
2806 # notemodify, three ways to say dataref
2808 test_expect_success 'S: notemodify with garabge after mark dataref must fail' '
2809 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2810 commit refs/heads/S
2811 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2812 data <<COMMIT
2813 commit S note dataref markref
2814 COMMIT
2815 N :202x :302
2817 cat err &&
2818 test_i18ngrep "space after mark" err
2821 test_expect_success 'S: notemodify with garbage after inline dataref must fail' '
2822 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2823 commit refs/heads/S
2824 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2825 data <<COMMIT
2826 commit S note dataref inline
2827 COMMIT
2828 N inlineX :302
2829 data <<BLOB
2830 note blob
2831 BLOB
2833 cat err &&
2834 test_i18ngrep "nvalid dataref" err
2837 test_expect_success 'S: notemodify with garbage after sha1 dataref must fail' '
2838 sha1=$(grep :202 marks | cut -d\ -f2) &&
2839 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2840 commit refs/heads/S
2841 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2842 data <<COMMIT
2843 commit S note dataref sha1
2844 COMMIT
2845 N ${sha1}x :302
2847 cat err &&
2848 test_i18ngrep "space after SHA1" err
2852 # notemodify, mark in commit-ish
2854 test_expect_success 'S: notemodify with garbage after mark commit-ish must fail' '
2855 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2856 commit refs/heads/Snotes
2857 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2858 data <<COMMIT
2859 commit S note commit-ish
2860 COMMIT
2861 N :202 :302x
2863 cat err &&
2864 test_i18ngrep "after mark" err
2868 # from
2870 test_expect_success 'S: from with garbage after mark must fail' '
2871 test_must_fail \
2872 git fast-import --import-marks=marks --export-marks=marks <<-EOF 2>err &&
2873 commit refs/heads/S2
2874 mark :303
2875 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2876 data <<COMMIT
2877 commit 3
2878 COMMIT
2879 from :301x
2880 M 100644 :403 hello.c
2884 # go create the commit, need it for merge test
2885 git fast-import --import-marks=marks --export-marks=marks <<-EOF &&
2886 commit refs/heads/S2
2887 mark :303
2888 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2889 data <<COMMIT
2890 commit 3
2891 COMMIT
2892 from :301
2893 M 100644 :403 hello.c
2896 # now evaluate the error
2897 cat err &&
2898 test_i18ngrep "after mark" err
2903 # merge
2905 test_expect_success 'S: merge with garbage after mark must fail' '
2906 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2907 commit refs/heads/S
2908 mark :304
2909 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2910 data <<COMMIT
2911 merge 4
2912 COMMIT
2913 from :302
2914 merge :303x
2915 M 100644 :403 hello.c
2917 cat err &&
2918 test_i18ngrep "after mark" err
2922 # tag, from markref
2924 test_expect_success 'S: tag with garbage after mark must fail' '
2925 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2926 tag refs/tags/Stag
2927 from :302x
2928 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2929 data <<TAG
2930 tag S
2933 cat err &&
2934 test_i18ngrep "after mark" err
2938 # cat-blob markref
2940 test_expect_success 'S: cat-blob with garbage after mark must fail' '
2941 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2942 cat-blob :403x
2944 cat err &&
2945 test_i18ngrep "after mark" err
2949 # ls markref
2951 test_expect_success 'S: ls with garbage after mark must fail' '
2952 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2953 ls :302x hello.c
2955 cat err &&
2956 test_i18ngrep "space after mark" err
2959 test_expect_success 'S: ls with garbage after sha1 must fail' '
2960 sha1=$(grep :302 marks | cut -d\ -f2) &&
2961 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2962 ls ${sha1}x hello.c
2964 cat err &&
2965 test_i18ngrep "space after tree-ish" err
2969 ### series T (ls)
2971 # Setup is carried over from series S.
2973 test_expect_success 'T: ls root tree' '
2974 sed -e "s/Z\$//" >expect <<-EOF &&
2975 040000 tree $(git rev-parse S^{tree}) Z
2977 sha1=$(git rev-parse --verify S) &&
2978 git fast-import --import-marks=marks <<-EOF >actual &&
2979 ls $sha1 ""
2981 test_cmp expect actual
2984 test_expect_success 'T: delete branch' '
2985 git branch to-delete &&
2986 git fast-import <<-EOF &&
2987 reset refs/heads/to-delete
2988 from 0000000000000000000000000000000000000000
2990 test_must_fail git rev-parse --verify refs/heads/to-delete
2993 test_expect_success 'T: empty reset doesnt delete branch' '
2994 git branch not-to-delete &&
2995 git fast-import <<-EOF &&
2996 reset refs/heads/not-to-delete
2998 git show-ref &&
2999 git rev-parse --verify refs/heads/not-to-delete
3003 ### series U (filedelete)
3006 cat >input <<INPUT_END
3007 commit refs/heads/U
3008 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3009 data <<COMMIT
3010 test setup
3011 COMMIT
3012 M 100644 inline hello.c
3013 data <<BLOB
3014 blob 1
3015 BLOB
3016 M 100644 inline good/night.txt
3017 data <<BLOB
3018 sleep well
3019 BLOB
3020 M 100644 inline good/bye.txt
3021 data <<BLOB
3022 au revoir
3023 BLOB
3025 INPUT_END
3027 test_expect_success 'U: initialize for U tests' '
3028 git fast-import <input
3031 cat >input <<INPUT_END
3032 commit refs/heads/U
3033 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3034 data <<COMMIT
3035 delete good/night.txt
3036 COMMIT
3037 from refs/heads/U^0
3038 D good/night.txt
3040 INPUT_END
3042 test_expect_success 'U: filedelete file succeeds' '
3043 git fast-import <input
3046 cat >expect <<EOF
3047 :100644 000000 2907ebb4bf85d91bf0716bb3bd8a68ef48d6da76 0000000000000000000000000000000000000000 D good/night.txt
3050 git diff-tree -M -r U^1 U >actual
3052 test_expect_success 'U: validate file delete result' '
3053 compare_diff_raw expect actual
3056 cat >input <<INPUT_END
3057 commit refs/heads/U
3058 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3059 data <<COMMIT
3060 delete good dir
3061 COMMIT
3062 from refs/heads/U^0
3063 D good
3065 INPUT_END
3067 test_expect_success 'U: filedelete directory succeeds' '
3068 git fast-import <input
3071 cat >expect <<EOF
3072 :100644 000000 69cb75792f55123d8389c156b0b41c2ff00ed507 0000000000000000000000000000000000000000 D good/bye.txt
3075 git diff-tree -M -r U^1 U >actual
3077 test_expect_success 'U: validate directory delete result' '
3078 compare_diff_raw expect actual
3081 cat >input <<INPUT_END
3082 commit refs/heads/U
3083 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3084 data <<COMMIT
3085 must succeed
3086 COMMIT
3087 from refs/heads/U^0
3088 D ""
3090 INPUT_END
3092 test_expect_success 'U: filedelete root succeeds' '
3093 git fast-import <input
3096 cat >expect <<EOF
3097 :100644 000000 c18147dc648481eeb65dc5e66628429a64843327 0000000000000000000000000000000000000000 D hello.c
3100 git diff-tree -M -r U^1 U >actual
3102 test_expect_success 'U: validate root delete result' '
3103 compare_diff_raw expect actual
3106 test_done