modernize t9300: use test_must_be_empty
[git.git] / t / t9300-fast-import.sh
blobceb3db3100e76a4d7c6e2e85b9fe93f364741bed
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 ###
51 ### series A
52 ###
54 test_tick
56 test_expect_success 'empty stream succeeds' '
57 git fast-import </dev/null
60 cat >input <<INPUT_END
61 blob
62 mark :2
63 data <<EOF
64 $file2_data
65 EOF
67 blob
68 mark :3
69 data <<END
70 $file3_data
71 END
73 blob
74 mark :4
75 data $file4_len
76 $file4_data
77 commit refs/heads/master
78 mark :5
79 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
80 data <<COMMIT
81 initial
82 COMMIT
84 M 644 :2 file2
85 M 644 :3 file3
86 M 755 :4 file4
88 tag series-A
89 from :5
90 data <<EOF
91 An annotated tag without a tagger
92 EOF
94 tag series-A-blob
95 from :3
96 data <<EOF
97 An annotated tag that annotates a blob.
98 EOF
100 INPUT_END
101 test_expect_success 'A: create pack from stdin' '
102 git fast-import --export-marks=marks.out <input &&
103 git whatchanged master
106 test_expect_success 'A: verify pack' '
107 verify_packs
110 cat >expect <<EOF
111 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
112 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
114 initial
116 test_expect_success 'A: verify commit' '
117 git cat-file commit master | sed 1d >actual &&
118 test_cmp expect actual
121 cat >expect <<EOF
122 100644 blob file2
123 100644 blob file3
124 100755 blob file4
126 test_expect_success 'A: verify tree' '
127 git cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
128 test_cmp expect actual
131 echo "$file2_data" >expect
132 test_expect_success 'A: verify file2' '
133 git cat-file blob master:file2 >actual && test_cmp expect actual
136 echo "$file3_data" >expect
137 test_expect_success 'A: verify file3' '
138 git cat-file blob master:file3 >actual && test_cmp expect actual
141 printf "$file4_data" >expect
142 test_expect_success 'A: verify file4' '
143 git cat-file blob master:file4 >actual && test_cmp expect actual
146 cat >expect <<EOF
147 object $(git rev-parse refs/heads/master)
148 type commit
149 tag series-A
151 An annotated tag without a tagger
153 test_expect_success 'A: verify tag/series-A' '
154 git cat-file tag tags/series-A >actual &&
155 test_cmp expect actual
158 cat >expect <<EOF
159 object $(git rev-parse refs/heads/master:file3)
160 type blob
161 tag series-A-blob
163 An annotated tag that annotates a blob.
165 test_expect_success 'A: verify tag/series-A-blob' '
166 git cat-file tag tags/series-A-blob >actual &&
167 test_cmp expect actual
170 cat >expect <<EOF
171 :2 `git rev-parse --verify master:file2`
172 :3 `git rev-parse --verify master:file3`
173 :4 `git rev-parse --verify master:file4`
174 :5 `git rev-parse --verify master^0`
176 test_expect_success 'A: verify marks output' '
177 test_cmp expect marks.out
180 test_expect_success 'A: verify marks import' '
181 git fast-import \
182 --import-marks=marks.out \
183 --export-marks=marks.new \
184 </dev/null &&
185 test_cmp expect marks.new
188 test_tick
189 new_blob=$(echo testing | git hash-object --stdin)
190 cat >input <<INPUT_END
191 tag series-A-blob-2
192 from $(git rev-parse refs/heads/master:file3)
193 data <<EOF
194 Tag blob by sha1.
197 blob
198 mark :6
199 data <<EOF
200 testing
203 commit refs/heads/new_blob
204 committer <> 0 +0000
205 data 0
206 M 644 :6 new_blob
207 #pretend we got sha1 from fast-import
208 ls "new_blob"
210 tag series-A-blob-3
211 from $new_blob
212 data <<EOF
213 Tag new_blob.
215 INPUT_END
217 cat >expect <<EOF
218 object $(git rev-parse refs/heads/master:file3)
219 type blob
220 tag series-A-blob-2
222 Tag blob by sha1.
223 object $new_blob
224 type blob
225 tag series-A-blob-3
227 Tag new_blob.
230 test_expect_success 'A: tag blob by sha1' '
231 git fast-import <input &&
232 git cat-file tag tags/series-A-blob-2 >actual &&
233 git cat-file tag tags/series-A-blob-3 >>actual &&
234 test_cmp expect actual
237 test_tick
238 cat >input <<INPUT_END
239 commit refs/heads/verify--import-marks
240 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
241 data <<COMMIT
242 recreate from :5
243 COMMIT
245 from :5
246 M 755 :2 copy-of-file2
248 INPUT_END
249 test_expect_success 'A: verify marks import does not crash' '
250 git fast-import --import-marks=marks.out <input &&
251 git whatchanged verify--import-marks
254 test_expect_success 'A: verify pack' '
255 verify_packs
258 cat >expect <<EOF
259 :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2
261 git diff-tree -M -r master verify--import-marks >actual
262 test_expect_success 'A: verify diff' '
263 compare_diff_raw expect actual &&
264 test `git rev-parse --verify master:file2` \
265 = `git rev-parse --verify verify--import-marks:copy-of-file2`
268 test_tick
269 mt=$(git hash-object --stdin < /dev/null)
270 : >input.blob
271 : >marks.exp
272 : >tree.exp
274 cat >input.commit <<EOF
275 commit refs/heads/verify--dump-marks
276 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
277 data <<COMMIT
278 test the sparse array dumping routines with exponentially growing marks
279 COMMIT
286 while test "$i" -lt 27; do
287 cat >>input.blob <<EOF
288 blob
289 mark :$l
290 data 0
291 blob
292 mark :$m
293 data 0
294 blob
295 mark :$n
296 data 0
298 echo "M 100644 :$l l$i" >>input.commit
299 echo "M 100644 :$m m$i" >>input.commit
300 echo "M 100644 :$n n$i" >>input.commit
302 echo ":$l $mt" >>marks.exp
303 echo ":$m $mt" >>marks.exp
304 echo ":$n $mt" >>marks.exp
306 printf "100644 blob $mt\tl$i\n" >>tree.exp
307 printf "100644 blob $mt\tm$i\n" >>tree.exp
308 printf "100644 blob $mt\tn$i\n" >>tree.exp
310 l=$(($l + $l))
311 m=$(($m + $m))
312 n=$(($l + $n))
314 i=$((1 + $i))
315 done
317 sort tree.exp > tree.exp_s
319 test_expect_success 'A: export marks with large values' '
320 cat input.blob input.commit | git fast-import --export-marks=marks.large &&
321 git ls-tree refs/heads/verify--dump-marks >tree.out &&
322 test_cmp tree.exp_s tree.out &&
323 test_cmp marks.exp marks.large
327 ### series B
330 test_tick
331 cat >input <<INPUT_END
332 commit refs/heads/branch
333 mark :1
334 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
335 data <<COMMIT
336 corrupt
337 COMMIT
339 from refs/heads/master
340 M 755 0000000000000000000000000000000000000001 zero1
342 INPUT_END
343 test_expect_success 'B: fail on invalid blob sha1' '
344 test_must_fail git fast-import <input
346 rm -f .git/objects/pack_* .git/objects/index_*
348 cat >input <<INPUT_END
349 commit TEMP_TAG
350 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
351 data <<COMMIT
352 tag base
353 COMMIT
355 from refs/heads/master
357 INPUT_END
358 test_expect_success 'B: accept branch name "TEMP_TAG"' '
359 git fast-import <input &&
360 test -f .git/TEMP_TAG &&
361 test `git rev-parse master` = `git rev-parse TEMP_TAG^`
363 rm -f .git/TEMP_TAG
365 git gc 2>/dev/null >/dev/null
366 git prune 2>/dev/null >/dev/null
368 cat >input <<INPUT_END
369 commit refs/heads/empty-committer-1
370 committer <> $GIT_COMMITTER_DATE
371 data <<COMMIT
372 empty commit
373 COMMIT
374 INPUT_END
375 test_expect_success 'B: accept empty committer' '
376 git fast-import <input &&
377 out=$(git fsck) &&
378 echo "$out" &&
379 test -z "$out"
381 git update-ref -d refs/heads/empty-committer-1 || true
383 git gc 2>/dev/null >/dev/null
384 git prune 2>/dev/null >/dev/null
386 cat >input <<INPUT_END
387 commit refs/heads/empty-committer-2
388 committer <a@b.com> $GIT_COMMITTER_DATE
389 data <<COMMIT
390 empty commit
391 COMMIT
392 INPUT_END
393 test_expect_success 'B: accept and fixup committer with no name' '
394 git fast-import <input &&
395 out=$(git fsck) &&
396 echo "$out" &&
397 test -z "$out"
399 git update-ref -d refs/heads/empty-committer-2 || true
401 git gc 2>/dev/null >/dev/null
402 git prune 2>/dev/null >/dev/null
404 cat >input <<INPUT_END
405 commit refs/heads/invalid-committer
406 committer Name email> $GIT_COMMITTER_DATE
407 data <<COMMIT
408 empty commit
409 COMMIT
410 INPUT_END
411 test_expect_success 'B: fail on invalid committer (1)' '
412 test_must_fail git fast-import <input
414 git update-ref -d refs/heads/invalid-committer || true
416 cat >input <<INPUT_END
417 commit refs/heads/invalid-committer
418 committer Name <e<mail> $GIT_COMMITTER_DATE
419 data <<COMMIT
420 empty commit
421 COMMIT
422 INPUT_END
423 test_expect_success 'B: fail on invalid committer (2)' '
424 test_must_fail git fast-import <input
426 git update-ref -d refs/heads/invalid-committer || true
428 cat >input <<INPUT_END
429 commit refs/heads/invalid-committer
430 committer Name <email>> $GIT_COMMITTER_DATE
431 data <<COMMIT
432 empty commit
433 COMMIT
434 INPUT_END
435 test_expect_success 'B: fail on invalid committer (3)' '
436 test_must_fail git fast-import <input
438 git update-ref -d refs/heads/invalid-committer || true
440 cat >input <<INPUT_END
441 commit refs/heads/invalid-committer
442 committer Name <email $GIT_COMMITTER_DATE
443 data <<COMMIT
444 empty commit
445 COMMIT
446 INPUT_END
447 test_expect_success 'B: fail on invalid committer (4)' '
448 test_must_fail git fast-import <input
450 git update-ref -d refs/heads/invalid-committer || true
452 cat >input <<INPUT_END
453 commit refs/heads/invalid-committer
454 committer Name<email> $GIT_COMMITTER_DATE
455 data <<COMMIT
456 empty commit
457 COMMIT
458 INPUT_END
459 test_expect_success 'B: fail on invalid committer (5)' '
460 test_must_fail git fast-import <input
462 git update-ref -d refs/heads/invalid-committer || true
465 ### series C
468 newf=`echo hi newf | git hash-object -w --stdin`
469 oldf=`git rev-parse --verify master:file2`
470 test_tick
471 cat >input <<INPUT_END
472 commit refs/heads/branch
473 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
474 data <<COMMIT
475 second
476 COMMIT
478 from refs/heads/master
479 M 644 $oldf file2/oldf
480 M 755 $newf file2/newf
481 D file3
483 INPUT_END
484 test_expect_success 'C: incremental import create pack from stdin' '
485 git fast-import <input &&
486 git whatchanged branch
489 test_expect_success 'C: verify pack' '
490 verify_packs
493 test_expect_success 'C: validate reuse existing blob' '
494 test $newf = `git rev-parse --verify branch:file2/newf` &&
495 test $oldf = `git rev-parse --verify branch:file2/oldf`
498 cat >expect <<EOF
499 parent `git rev-parse --verify master^0`
500 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
501 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
503 second
505 test_expect_success 'C: verify commit' '
506 git cat-file commit branch | sed 1d >actual &&
507 test_cmp expect actual
510 cat >expect <<EOF
511 :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
512 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
513 :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
515 git diff-tree -M -r master branch >actual
516 test_expect_success 'C: validate rename result' '
517 compare_diff_raw expect actual
521 ### series D
524 test_tick
525 cat >input <<INPUT_END
526 commit refs/heads/branch
527 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
528 data <<COMMIT
529 third
530 COMMIT
532 from refs/heads/branch^0
533 M 644 inline newdir/interesting
534 data <<EOF
535 $file5_data
538 M 755 inline newdir/exec.sh
539 data <<EOF
540 $file6_data
543 INPUT_END
544 test_expect_success 'D: inline data in commit' '
545 git fast-import <input &&
546 git whatchanged branch
549 test_expect_success 'D: verify pack' '
550 verify_packs
553 cat >expect <<EOF
554 :000000 100755 0000000000000000000000000000000000000000 e74b7d465e52746be2b4bae983670711e6e66657 A newdir/exec.sh
555 :000000 100644 0000000000000000000000000000000000000000 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 A newdir/interesting
557 git diff-tree -M -r branch^ branch >actual
558 test_expect_success 'D: validate new files added' '
559 compare_diff_raw expect actual
562 echo "$file5_data" >expect
563 test_expect_success 'D: verify file5' '
564 git cat-file blob branch:newdir/interesting >actual &&
565 test_cmp expect actual
568 echo "$file6_data" >expect
569 test_expect_success 'D: verify file6' '
570 git cat-file blob branch:newdir/exec.sh >actual &&
571 test_cmp expect actual
575 ### series E
578 cat >input <<INPUT_END
579 commit refs/heads/branch
580 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
581 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
582 data <<COMMIT
583 RFC 2822 type date
584 COMMIT
586 from refs/heads/branch^0
588 INPUT_END
589 test_expect_success 'E: rfc2822 date, --date-format=raw' '
590 test_must_fail git fast-import --date-format=raw <input
592 test_expect_success 'E: rfc2822 date, --date-format=rfc2822' '
593 git fast-import --date-format=rfc2822 <input
596 test_expect_success 'E: verify pack' '
597 verify_packs
600 cat >expect <<EOF
601 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
602 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
604 RFC 2822 type date
606 test_expect_success 'E: verify commit' '
607 git cat-file commit branch | sed 1,2d >actual &&
608 test_cmp expect actual
612 ### series F
615 old_branch=`git rev-parse --verify branch^0`
616 test_tick
617 cat >input <<INPUT_END
618 commit refs/heads/branch
619 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
620 data <<COMMIT
621 losing things already?
622 COMMIT
624 from refs/heads/branch~1
626 reset refs/heads/other
627 from refs/heads/branch
629 INPUT_END
630 test_expect_success 'F: non-fast-forward update skips' '
631 test_must_fail git fast-import <input &&
632 # branch must remain unaffected
633 test $old_branch = `git rev-parse --verify branch^0`
636 test_expect_success 'F: verify pack' '
637 verify_packs
640 cat >expect <<EOF
641 tree `git rev-parse branch~1^{tree}`
642 parent `git rev-parse branch~1`
643 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
644 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
646 losing things already?
648 test_expect_success 'F: verify other commit' '
649 git cat-file commit other >actual &&
650 test_cmp expect actual
654 ### series G
657 old_branch=`git rev-parse --verify branch^0`
658 test_tick
659 cat >input <<INPUT_END
660 commit refs/heads/branch
661 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
662 data <<COMMIT
663 losing things already?
664 COMMIT
666 from refs/heads/branch~1
668 INPUT_END
669 test_expect_success 'G: non-fast-forward update forced' '
670 git fast-import --force <input
673 test_expect_success 'G: verify pack' '
674 verify_packs
677 test_expect_success 'G: branch changed, but logged' '
678 test $old_branch != `git rev-parse --verify branch^0` &&
679 test $old_branch = `git rev-parse --verify branch@{1}`
683 ### series H
686 test_tick
687 cat >input <<INPUT_END
688 commit refs/heads/H
689 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
690 data <<COMMIT
691 third
692 COMMIT
694 from refs/heads/branch^0
695 M 644 inline i-will-die
696 data <<EOF
697 this file will never exist.
700 deleteall
701 M 644 inline h/e/l/lo
702 data <<EOF
703 $file5_data
706 INPUT_END
707 test_expect_success 'H: deletall, add 1' '
708 git fast-import <input &&
709 git whatchanged H
712 test_expect_success 'H: verify pack' '
713 verify_packs
716 cat >expect <<EOF
717 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf
718 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf
719 :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4
720 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo
721 :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh
723 git diff-tree -M -r H^ H >actual
724 test_expect_success 'H: validate old files removed, new files added' '
725 compare_diff_raw expect actual
728 echo "$file5_data" >expect
729 test_expect_success 'H: verify file' '
730 git cat-file blob H:h/e/l/lo >actual &&
731 test_cmp expect actual
735 ### series I
738 cat >input <<INPUT_END
739 commit refs/heads/export-boundary
740 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
741 data <<COMMIT
742 we have a border. its only 40 characters wide.
743 COMMIT
745 from refs/heads/branch
747 INPUT_END
748 test_expect_success 'I: export-pack-edges' '
749 git fast-import --export-pack-edges=edges.list <input
752 cat >expect <<EOF
753 .git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
755 test_expect_success 'I: verify edge list' '
756 sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
757 test_cmp expect actual
761 ### series J
764 cat >input <<INPUT_END
765 commit refs/heads/J
766 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
767 data <<COMMIT
768 create J
769 COMMIT
771 from refs/heads/branch
773 reset refs/heads/J
775 commit refs/heads/J
776 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
777 data <<COMMIT
778 initialize J
779 COMMIT
781 INPUT_END
782 test_expect_success 'J: reset existing branch creates empty commit' '
783 git fast-import <input
785 test_expect_success 'J: branch has 1 commit, empty tree' '
786 test 1 = `git rev-list J | wc -l` &&
787 test 0 = `git ls-tree J | wc -l`
790 cat >input <<INPUT_END
791 reset refs/heads/J2
793 tag wrong_tag
794 from refs/heads/J2
795 data <<EOF
796 Tag branch that was reset.
798 INPUT_END
799 test_expect_success 'J: tag must fail on empty branch' '
800 test_must_fail git fast-import <input
803 ### series K
806 cat >input <<INPUT_END
807 commit refs/heads/K
808 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
809 data <<COMMIT
810 create K
811 COMMIT
813 from refs/heads/branch
815 commit refs/heads/K
816 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
817 data <<COMMIT
818 redo K
819 COMMIT
821 from refs/heads/branch^1
823 INPUT_END
824 test_expect_success 'K: reinit branch with from' '
825 git fast-import <input
827 test_expect_success 'K: verify K^1 = branch^1' '
828 test `git rev-parse --verify branch^1` \
829 = `git rev-parse --verify K^1`
833 ### series L
836 cat >input <<INPUT_END
837 blob
838 mark :1
839 data <<EOF
840 some data
843 blob
844 mark :2
845 data <<EOF
846 other data
849 commit refs/heads/L
850 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
851 data <<COMMIT
852 create L
853 COMMIT
855 M 644 :1 b.
856 M 644 :1 b/other
857 M 644 :1 ba
859 commit refs/heads/L
860 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
861 data <<COMMIT
862 update L
863 COMMIT
865 M 644 :2 b.
866 M 644 :2 b/other
867 M 644 :2 ba
868 INPUT_END
870 cat >expect <<EXPECT_END
871 :100644 100644 4268632... 55d3a52... M b.
872 :040000 040000 0ae5cac... 443c768... M b
873 :100644 100644 4268632... 55d3a52... M ba
874 EXPECT_END
876 test_expect_success 'L: verify internal tree sorting' '
877 git fast-import <input &&
878 git diff-tree --abbrev --raw L^ L >output &&
879 test_cmp expect output
882 cat >input <<INPUT_END
883 blob
884 mark :1
885 data <<EOF
886 the data
889 commit refs/heads/L2
890 committer C O Mitter <committer@example.com> 1112912473 -0700
891 data <<COMMIT
892 init L2
893 COMMIT
894 M 644 :1 a/b/c
895 M 644 :1 a/b/d
896 M 644 :1 a/e/f
898 commit refs/heads/L2
899 committer C O Mitter <committer@example.com> 1112912473 -0700
900 data <<COMMIT
901 update L2
902 COMMIT
903 C a g
904 C a/e g/b
905 M 644 :1 g/b/h
906 INPUT_END
908 cat <<EOF >expect
909 g/b/f
910 g/b/h
913 test_expect_success 'L: nested tree copy does not corrupt deltas' '
914 git fast-import <input &&
915 git ls-tree L2 g/b/ >tmp &&
916 cat tmp | cut -f 2 >actual &&
917 test_cmp expect actual &&
918 git fsck `git rev-parse L2`
921 git update-ref -d refs/heads/L2
924 ### series M
927 test_tick
928 cat >input <<INPUT_END
929 commit refs/heads/M1
930 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
931 data <<COMMIT
932 file rename
933 COMMIT
935 from refs/heads/branch^0
936 R file2/newf file2/n.e.w.f
938 INPUT_END
940 cat >expect <<EOF
941 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f
943 test_expect_success 'M: rename file in same subdirectory' '
944 git fast-import <input &&
945 git diff-tree -M -r M1^ M1 >actual &&
946 compare_diff_raw expect actual
949 cat >input <<INPUT_END
950 commit refs/heads/M2
951 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
952 data <<COMMIT
953 file rename
954 COMMIT
956 from refs/heads/branch^0
957 R file2/newf i/am/new/to/you
959 INPUT_END
961 cat >expect <<EOF
962 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you
964 test_expect_success 'M: rename file to new subdirectory' '
965 git fast-import <input &&
966 git diff-tree -M -r M2^ M2 >actual &&
967 compare_diff_raw expect actual
970 cat >input <<INPUT_END
971 commit refs/heads/M3
972 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
973 data <<COMMIT
974 file rename
975 COMMIT
977 from refs/heads/M2^0
978 R i other/sub
980 INPUT_END
982 cat >expect <<EOF
983 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you
985 test_expect_success 'M: rename subdirectory to new subdirectory' '
986 git fast-import <input &&
987 git diff-tree -M -r M3^ M3 >actual &&
988 compare_diff_raw expect actual
991 cat >input <<INPUT_END
992 commit refs/heads/M4
993 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
994 data <<COMMIT
995 rename root
996 COMMIT
998 from refs/heads/M2^0
999 R "" sub
1001 INPUT_END
1003 cat >expect <<EOF
1004 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2/oldf sub/file2/oldf
1005 :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 R100 file4 sub/file4
1006 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you sub/i/am/new/to/you
1007 :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 R100 newdir/exec.sh sub/newdir/exec.sh
1008 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting sub/newdir/interesting
1010 test_expect_success 'M: rename root to subdirectory' '
1011 git fast-import <input &&
1012 git diff-tree -M -r M4^ M4 >actual &&
1013 cat actual &&
1014 compare_diff_raw expect actual
1018 ### series N
1021 test_tick
1022 cat >input <<INPUT_END
1023 commit refs/heads/N1
1024 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1025 data <<COMMIT
1026 file copy
1027 COMMIT
1029 from refs/heads/branch^0
1030 C file2/newf file2/n.e.w.f
1032 INPUT_END
1034 cat >expect <<EOF
1035 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f
1037 test_expect_success 'N: copy file in same subdirectory' '
1038 git fast-import <input &&
1039 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1040 compare_diff_raw expect actual
1043 cat >input <<INPUT_END
1044 commit refs/heads/N2
1045 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1046 data <<COMMIT
1047 clean directory copy
1048 COMMIT
1050 from refs/heads/branch^0
1051 C file2 file3
1053 commit refs/heads/N2
1054 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1055 data <<COMMIT
1056 modify directory copy
1057 COMMIT
1059 M 644 inline file3/file5
1060 data <<EOF
1061 $file5_data
1064 INPUT_END
1066 cat >expect <<EOF
1067 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1068 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1069 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1071 test_expect_success 'N: copy then modify subdirectory' '
1072 git fast-import <input &&
1073 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1074 compare_diff_raw expect actual
1077 cat >input <<INPUT_END
1078 commit refs/heads/N3
1079 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1080 data <<COMMIT
1081 dirty directory copy
1082 COMMIT
1084 from refs/heads/branch^0
1085 M 644 inline file2/file5
1086 data <<EOF
1087 $file5_data
1090 C file2 file3
1091 D file2/file5
1093 INPUT_END
1095 test_expect_success 'N: copy dirty subdirectory' '
1096 git fast-import <input &&
1097 test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`
1100 test_expect_success 'N: copy directory by id' '
1101 cat >expect <<-\EOF &&
1102 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1103 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1105 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1106 cat >input <<-INPUT_END &&
1107 commit refs/heads/N4
1108 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1109 data <<COMMIT
1110 copy by tree hash
1111 COMMIT
1113 from refs/heads/branch^0
1114 M 040000 $subdir file3
1115 INPUT_END
1116 git fast-import <input &&
1117 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1118 compare_diff_raw expect actual
1121 test_expect_success PIPE 'N: read and copy directory' '
1122 cat >expect <<-\EOF &&
1123 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1124 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1126 git update-ref -d refs/heads/N4 &&
1127 rm -f backflow &&
1128 mkfifo backflow &&
1130 exec <backflow &&
1131 cat <<-EOF &&
1132 commit refs/heads/N4
1133 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1134 data <<COMMIT
1135 copy by tree hash, part 2
1136 COMMIT
1138 from refs/heads/branch^0
1139 ls "file2"
1141 read mode type tree filename &&
1142 echo "M 040000 $tree file3"
1144 git fast-import --cat-blob-fd=3 3>backflow &&
1145 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1146 compare_diff_raw expect actual
1149 test_expect_success PIPE 'N: empty directory reads as missing' '
1150 cat <<-\EOF >expect &&
1151 OBJNAME
1152 :000000 100644 OBJNAME OBJNAME A unrelated
1154 echo "missing src" >expect.response &&
1155 git update-ref -d refs/heads/read-empty &&
1156 rm -f backflow &&
1157 mkfifo backflow &&
1159 exec <backflow &&
1160 cat <<-EOF &&
1161 commit refs/heads/read-empty
1162 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1163 data <<COMMIT
1164 read "empty" (missing) directory
1165 COMMIT
1167 M 100644 inline src/greeting
1168 data <<BLOB
1169 hello
1170 BLOB
1171 C src/greeting dst1/non-greeting
1172 C src/greeting unrelated
1173 # leave behind "empty" src directory
1174 D src/greeting
1175 ls "src"
1177 read -r line &&
1178 printf "%s\n" "$line" >response &&
1179 cat <<-\EOF
1180 D dst1
1181 D dst2
1184 git fast-import --cat-blob-fd=3 3>backflow &&
1185 test_cmp expect.response response &&
1186 git rev-list read-empty |
1187 git diff-tree -r --root --stdin |
1188 sed "s/$_x40/OBJNAME/g" >actual &&
1189 test_cmp expect actual
1192 test_expect_success 'N: copy root directory by tree hash' '
1193 cat >expect <<-\EOF &&
1194 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file3/newf
1195 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file3/oldf
1197 root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1198 cat >input <<-INPUT_END &&
1199 commit refs/heads/N6
1200 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1201 data <<COMMIT
1202 copy root directory by tree hash
1203 COMMIT
1205 from refs/heads/branch^0
1206 M 040000 $root ""
1207 INPUT_END
1208 git fast-import <input &&
1209 git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1210 compare_diff_raw expect actual
1213 test_expect_success 'N: copy root by path' '
1214 cat >expect <<-\EOF &&
1215 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf oldroot/file2/newf
1216 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf oldroot/file2/oldf
1217 :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 C100 file4 oldroot/file4
1218 :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 C100 newdir/exec.sh oldroot/newdir/exec.sh
1219 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting oldroot/newdir/interesting
1221 cat >input <<-INPUT_END &&
1222 commit refs/heads/N-copy-root-path
1223 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1224 data <<COMMIT
1225 copy root directory by (empty) path
1226 COMMIT
1228 from refs/heads/branch^0
1229 C "" oldroot
1230 INPUT_END
1231 git fast-import <input &&
1232 git diff-tree -C --find-copies-harder -r branch N-copy-root-path >actual &&
1233 compare_diff_raw expect actual
1236 test_expect_success 'N: delete directory by copying' '
1237 cat >expect <<-\EOF &&
1238 OBJID
1239 :100644 000000 OBJID OBJID D foo/bar/qux
1240 OBJID
1241 :000000 100644 OBJID OBJID A foo/bar/baz
1242 :000000 100644 OBJID OBJID A foo/bar/qux
1244 empty_tree=$(git mktree </dev/null) &&
1245 cat >input <<-INPUT_END &&
1246 commit refs/heads/N-delete
1247 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1248 data <<COMMIT
1249 collect data to be deleted
1250 COMMIT
1252 deleteall
1253 M 100644 inline foo/bar/baz
1254 data <<DATA_END
1255 hello
1256 DATA_END
1257 C "foo/bar/baz" "foo/bar/qux"
1258 C "foo/bar/baz" "foo/bar/quux/1"
1259 C "foo/bar/baz" "foo/bar/quuux"
1260 M 040000 $empty_tree foo/bar/quux
1261 M 040000 $empty_tree foo/bar/quuux
1263 commit refs/heads/N-delete
1264 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1265 data <<COMMIT
1266 delete subdirectory
1267 COMMIT
1269 M 040000 $empty_tree foo/bar/qux
1270 INPUT_END
1271 git fast-import <input &&
1272 git rev-list N-delete |
1273 git diff-tree -r --stdin --root --always |
1274 sed -e "s/$_x40/OBJID/g" >actual &&
1275 test_cmp expect actual
1278 test_expect_success 'N: modify copied tree' '
1279 cat >expect <<-\EOF &&
1280 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1281 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1282 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1284 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1285 cat >input <<-INPUT_END &&
1286 commit refs/heads/N5
1287 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1288 data <<COMMIT
1289 copy by tree hash
1290 COMMIT
1292 from refs/heads/branch^0
1293 M 040000 $subdir file3
1295 commit refs/heads/N5
1296 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1297 data <<COMMIT
1298 modify directory copy
1299 COMMIT
1301 M 644 inline file3/file5
1302 data <<EOF
1303 $file5_data
1305 INPUT_END
1306 git fast-import <input &&
1307 git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1308 compare_diff_raw expect actual
1311 test_expect_success 'N: reject foo/ syntax' '
1312 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1313 test_must_fail git fast-import <<-INPUT_END
1314 commit refs/heads/N5B
1315 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1316 data <<COMMIT
1317 copy with invalid syntax
1318 COMMIT
1320 from refs/heads/branch^0
1321 M 040000 $subdir file3/
1322 INPUT_END
1325 test_expect_success 'N: reject foo/ syntax in copy source' '
1326 test_must_fail git fast-import <<-INPUT_END
1327 commit refs/heads/N5C
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 C file2/ file3
1335 INPUT_END
1338 test_expect_success 'N: reject foo/ syntax in rename source' '
1339 test_must_fail git fast-import <<-INPUT_END
1340 commit refs/heads/N5D
1341 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1342 data <<COMMIT
1343 rename with invalid syntax
1344 COMMIT
1346 from refs/heads/branch^0
1347 R file2/ file3
1348 INPUT_END
1351 test_expect_success 'N: reject foo/ syntax in ls argument' '
1352 test_must_fail git fast-import <<-INPUT_END
1353 commit refs/heads/N5E
1354 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1355 data <<COMMIT
1356 copy with invalid syntax
1357 COMMIT
1359 from refs/heads/branch^0
1360 ls "file2/"
1361 INPUT_END
1364 test_expect_success 'N: copy to root by id and modify' '
1365 echo "hello, world" >expect.foo &&
1366 echo hello >expect.bar &&
1367 git fast-import <<-SETUP_END &&
1368 commit refs/heads/N7
1369 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1370 data <<COMMIT
1371 hello, tree
1372 COMMIT
1374 deleteall
1375 M 644 inline foo/bar
1376 data <<EOF
1377 hello
1379 SETUP_END
1381 tree=$(git rev-parse --verify N7:) &&
1382 git fast-import <<-INPUT_END &&
1383 commit refs/heads/N8
1384 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1385 data <<COMMIT
1386 copy to root by id and modify
1387 COMMIT
1389 M 040000 $tree ""
1390 M 644 inline foo/foo
1391 data <<EOF
1392 hello, world
1394 INPUT_END
1395 git show N8:foo/foo >actual.foo &&
1396 git show N8:foo/bar >actual.bar &&
1397 test_cmp expect.foo actual.foo &&
1398 test_cmp expect.bar actual.bar
1401 test_expect_success 'N: extract subtree' '
1402 branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1403 cat >input <<-INPUT_END &&
1404 commit refs/heads/N9
1405 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1406 data <<COMMIT
1407 extract subtree branch:newdir
1408 COMMIT
1410 M 040000 $branch ""
1411 C "newdir" ""
1412 INPUT_END
1413 git fast-import <input &&
1414 git diff --exit-code branch:newdir N9
1417 test_expect_success 'N: modify subtree, extract it, and modify again' '
1418 echo hello >expect.baz &&
1419 echo hello, world >expect.qux &&
1420 git fast-import <<-SETUP_END &&
1421 commit refs/heads/N10
1422 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1423 data <<COMMIT
1424 hello, tree
1425 COMMIT
1427 deleteall
1428 M 644 inline foo/bar/baz
1429 data <<EOF
1430 hello
1432 SETUP_END
1434 tree=$(git rev-parse --verify N10:) &&
1435 git fast-import <<-INPUT_END &&
1436 commit refs/heads/N11
1437 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1438 data <<COMMIT
1439 copy to root by id and modify
1440 COMMIT
1442 M 040000 $tree ""
1443 M 100644 inline foo/bar/qux
1444 data <<EOF
1445 hello, world
1447 R "foo" ""
1448 C "bar/qux" "bar/quux"
1449 INPUT_END
1450 git show N11:bar/baz >actual.baz &&
1451 git show N11:bar/qux >actual.qux &&
1452 git show N11:bar/quux >actual.quux &&
1453 test_cmp expect.baz actual.baz &&
1454 test_cmp expect.qux actual.qux &&
1455 test_cmp expect.qux actual.quux'
1458 ### series O
1461 cat >input <<INPUT_END
1462 #we will
1463 commit refs/heads/O1
1464 # -- ignore all of this text
1465 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1466 # $GIT_COMMITTER_NAME has inserted here for his benefit.
1467 data <<COMMIT
1468 dirty directory copy
1469 COMMIT
1471 # don't forget the import blank line!
1473 # yes, we started from our usual base of branch^0.
1474 # i like branch^0.
1475 from refs/heads/branch^0
1476 # and we need to reuse file2/file5 from N3 above.
1477 M 644 inline file2/file5
1478 # otherwise the tree will be different
1479 data <<EOF
1480 $file5_data
1483 # don't forget to copy file2 to file3
1484 C file2 file3
1486 # or to delete file5 from file2.
1487 D file2/file5
1488 # are we done yet?
1490 INPUT_END
1492 test_expect_success 'O: comments are all skipped' '
1493 git fast-import <input &&
1494 test `git rev-parse N3` = `git rev-parse O1`
1497 cat >input <<INPUT_END
1498 commit refs/heads/O2
1499 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1500 data <<COMMIT
1501 dirty directory copy
1502 COMMIT
1503 from refs/heads/branch^0
1504 M 644 inline file2/file5
1505 data <<EOF
1506 $file5_data
1508 C file2 file3
1509 D file2/file5
1511 INPUT_END
1513 test_expect_success 'O: blank lines not necessary after data commands' '
1514 git fast-import <input &&
1515 test `git rev-parse N3` = `git rev-parse O2`
1518 test_expect_success 'O: repack before next test' '
1519 git repack -a -d
1522 cat >input <<INPUT_END
1523 commit refs/heads/O3
1524 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1525 data <<COMMIT
1526 zstring
1527 COMMIT
1528 commit refs/heads/O3
1529 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1530 data <<COMMIT
1532 COMMIT
1533 checkpoint
1534 commit refs/heads/O3
1535 mark :5
1536 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1537 data <<COMMIT
1538 zempty
1539 COMMIT
1540 checkpoint
1541 commit refs/heads/O3
1542 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1543 data <<COMMIT
1544 zcommits
1545 COMMIT
1546 reset refs/tags/O3-2nd
1547 from :5
1548 reset refs/tags/O3-3rd
1549 from :5
1550 INPUT_END
1552 cat >expect <<INPUT_END
1553 string
1555 empty
1556 commits
1557 INPUT_END
1558 test_expect_success 'O: blank lines not necessary after other commands' '
1559 git fast-import <input &&
1560 test 8 = `find .git/objects/pack -type f | wc -l` &&
1561 test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
1562 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1563 test_cmp expect actual
1566 cat >input <<INPUT_END
1567 commit refs/heads/O4
1568 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1569 data <<COMMIT
1570 zstring
1571 COMMIT
1572 commit refs/heads/O4
1573 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1574 data <<COMMIT
1576 COMMIT
1577 progress Two commits down, 2 to go!
1578 commit refs/heads/O4
1579 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1580 data <<COMMIT
1581 zempty
1582 COMMIT
1583 progress Three commits down, 1 to go!
1584 commit refs/heads/O4
1585 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1586 data <<COMMIT
1587 zcommits
1588 COMMIT
1589 progress I'm done!
1590 INPUT_END
1591 test_expect_success 'O: progress outputs as requested by input' '
1592 git fast-import <input >actual &&
1593 grep "progress " <input >expect &&
1594 test_cmp expect actual
1598 ### series P (gitlinks)
1601 cat >input <<INPUT_END
1602 blob
1603 mark :1
1604 data 10
1605 test file
1607 reset refs/heads/sub
1608 commit refs/heads/sub
1609 mark :2
1610 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1611 data 12
1612 sub_initial
1613 M 100644 :1 file
1615 blob
1616 mark :3
1617 data <<DATAEND
1618 [submodule "sub"]
1619 path = sub
1620 url = "`pwd`/sub"
1621 DATAEND
1623 commit refs/heads/subuse1
1624 mark :4
1625 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1626 data 8
1627 initial
1628 from refs/heads/master
1629 M 100644 :3 .gitmodules
1630 M 160000 :2 sub
1632 blob
1633 mark :5
1634 data 20
1635 test file
1636 more data
1638 commit refs/heads/sub
1639 mark :6
1640 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1641 data 11
1642 sub_second
1643 from :2
1644 M 100644 :5 file
1646 commit refs/heads/subuse1
1647 mark :7
1648 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1649 data 7
1650 second
1651 from :4
1652 M 160000 :6 sub
1654 INPUT_END
1656 test_expect_success 'P: superproject & submodule mix' '
1657 git fast-import <input &&
1658 git checkout subuse1 &&
1659 rm -rf sub && mkdir sub && (cd sub &&
1660 git init &&
1661 git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1662 git checkout master) &&
1663 git submodule init &&
1664 git submodule update
1667 SUBLAST=$(git rev-parse --verify sub)
1668 SUBPREV=$(git rev-parse --verify sub^)
1670 cat >input <<INPUT_END
1671 blob
1672 mark :1
1673 data <<DATAEND
1674 [submodule "sub"]
1675 path = sub
1676 url = "`pwd`/sub"
1677 DATAEND
1679 commit refs/heads/subuse2
1680 mark :2
1681 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1682 data 8
1683 initial
1684 from refs/heads/master
1685 M 100644 :1 .gitmodules
1686 M 160000 $SUBPREV sub
1688 commit refs/heads/subuse2
1689 mark :3
1690 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1691 data 7
1692 second
1693 from :2
1694 M 160000 $SUBLAST sub
1696 INPUT_END
1698 test_expect_success 'P: verbatim SHA gitlinks' '
1699 git branch -D sub &&
1700 git gc && git prune &&
1701 git fast-import <input &&
1702 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)
1705 test_tick
1706 cat >input <<INPUT_END
1707 commit refs/heads/subuse3
1708 mark :1
1709 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1710 data <<COMMIT
1711 corrupt
1712 COMMIT
1714 from refs/heads/subuse2
1715 M 160000 inline sub
1716 data <<DATA
1717 $SUBPREV
1718 DATA
1720 INPUT_END
1722 test_expect_success 'P: fail on inline gitlink' '
1723 test_must_fail git fast-import <input
1726 test_tick
1727 cat >input <<INPUT_END
1728 blob
1729 mark :1
1730 data <<DATA
1731 $SUBPREV
1732 DATA
1734 commit refs/heads/subuse3
1735 mark :2
1736 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1737 data <<COMMIT
1738 corrupt
1739 COMMIT
1741 from refs/heads/subuse2
1742 M 160000 :1 sub
1744 INPUT_END
1746 test_expect_success 'P: fail on blob mark in gitlink' '
1747 test_must_fail git fast-import <input
1751 ### series Q (notes)
1754 note1_data="The first note for the first commit"
1755 note2_data="The first note for the second commit"
1756 note3_data="The first note for the third commit"
1757 note1b_data="The second note for the first commit"
1758 note1c_data="The third note for the first commit"
1759 note2b_data="The second note for the second commit"
1761 test_tick
1762 cat >input <<INPUT_END
1763 blob
1764 mark :2
1765 data <<EOF
1766 $file2_data
1769 commit refs/heads/notes-test
1770 mark :3
1771 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1772 data <<COMMIT
1773 first (:3)
1774 COMMIT
1776 M 644 :2 file2
1778 blob
1779 mark :4
1780 data $file4_len
1781 $file4_data
1782 commit refs/heads/notes-test
1783 mark :5
1784 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1785 data <<COMMIT
1786 second (:5)
1787 COMMIT
1789 M 644 :4 file4
1791 commit refs/heads/notes-test
1792 mark :6
1793 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1794 data <<COMMIT
1795 third (:6)
1796 COMMIT
1798 M 644 inline file5
1799 data <<EOF
1800 $file5_data
1803 M 755 inline file6
1804 data <<EOF
1805 $file6_data
1808 blob
1809 mark :7
1810 data <<EOF
1811 $note1_data
1814 blob
1815 mark :8
1816 data <<EOF
1817 $note2_data
1820 commit refs/notes/foobar
1821 mark :9
1822 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1823 data <<COMMIT
1824 notes (:9)
1825 COMMIT
1827 N :7 :3
1828 N :8 :5
1829 N inline :6
1830 data <<EOF
1831 $note3_data
1834 commit refs/notes/foobar
1835 mark :10
1836 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1837 data <<COMMIT
1838 notes (:10)
1839 COMMIT
1841 N inline :3
1842 data <<EOF
1843 $note1b_data
1846 commit refs/notes/foobar2
1847 mark :11
1848 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1849 data <<COMMIT
1850 notes (:11)
1851 COMMIT
1853 N inline :3
1854 data <<EOF
1855 $note1c_data
1858 commit refs/notes/foobar
1859 mark :12
1860 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1861 data <<COMMIT
1862 notes (:12)
1863 COMMIT
1865 deleteall
1866 N inline :5
1867 data <<EOF
1868 $note2b_data
1871 INPUT_END
1873 test_expect_success 'Q: commit notes' '
1874 git fast-import <input &&
1875 git whatchanged notes-test
1878 test_expect_success 'Q: verify pack' '
1879 verify_packs
1882 commit1=$(git rev-parse notes-test~2)
1883 commit2=$(git rev-parse notes-test^)
1884 commit3=$(git rev-parse notes-test)
1886 cat >expect <<EOF
1887 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1888 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1890 first (:3)
1892 test_expect_success 'Q: verify first commit' '
1893 git cat-file commit notes-test~2 | sed 1d >actual &&
1894 test_cmp expect actual
1897 cat >expect <<EOF
1898 parent $commit1
1899 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1900 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1902 second (:5)
1904 test_expect_success 'Q: verify second commit' '
1905 git cat-file commit notes-test^ | sed 1d >actual &&
1906 test_cmp expect actual
1909 cat >expect <<EOF
1910 parent $commit2
1911 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1912 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1914 third (:6)
1916 test_expect_success 'Q: verify third commit' '
1917 git cat-file commit notes-test | sed 1d >actual &&
1918 test_cmp expect actual
1921 cat >expect <<EOF
1922 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1923 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1925 notes (:9)
1927 test_expect_success 'Q: verify first notes commit' '
1928 git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1929 test_cmp expect actual
1932 cat >expect.unsorted <<EOF
1933 100644 blob $commit1
1934 100644 blob $commit2
1935 100644 blob $commit3
1937 cat expect.unsorted | sort >expect
1938 test_expect_success 'Q: verify first notes tree' '
1939 git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1940 test_cmp expect actual
1943 echo "$note1_data" >expect
1944 test_expect_success 'Q: verify first note for first commit' '
1945 git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual
1948 echo "$note2_data" >expect
1949 test_expect_success 'Q: verify first note for second commit' '
1950 git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual
1953 echo "$note3_data" >expect
1954 test_expect_success 'Q: verify first note for third commit' '
1955 git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual
1958 cat >expect <<EOF
1959 parent `git rev-parse --verify refs/notes/foobar~2`
1960 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1961 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1963 notes (:10)
1965 test_expect_success 'Q: verify second notes commit' '
1966 git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
1967 test_cmp expect actual
1970 cat >expect.unsorted <<EOF
1971 100644 blob $commit1
1972 100644 blob $commit2
1973 100644 blob $commit3
1975 cat expect.unsorted | sort >expect
1976 test_expect_success 'Q: verify second notes tree' '
1977 git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1978 test_cmp expect actual
1981 echo "$note1b_data" >expect
1982 test_expect_success 'Q: verify second note for first commit' '
1983 git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual
1986 echo "$note2_data" >expect
1987 test_expect_success 'Q: verify first note for second commit' '
1988 git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual
1991 echo "$note3_data" >expect
1992 test_expect_success 'Q: verify first note for third commit' '
1993 git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual
1996 cat >expect <<EOF
1997 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1998 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2000 notes (:11)
2002 test_expect_success 'Q: verify third notes commit' '
2003 git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
2004 test_cmp expect actual
2007 cat >expect.unsorted <<EOF
2008 100644 blob $commit1
2010 cat expect.unsorted | sort >expect
2011 test_expect_success 'Q: verify third notes tree' '
2012 git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2013 test_cmp expect actual
2016 echo "$note1c_data" >expect
2017 test_expect_success 'Q: verify third note for first commit' '
2018 git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual
2021 cat >expect <<EOF
2022 parent `git rev-parse --verify refs/notes/foobar^`
2023 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2024 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2026 notes (:12)
2028 test_expect_success 'Q: verify fourth notes commit' '
2029 git cat-file commit refs/notes/foobar | sed 1d >actual &&
2030 test_cmp expect actual
2033 cat >expect.unsorted <<EOF
2034 100644 blob $commit2
2036 cat expect.unsorted | sort >expect
2037 test_expect_success 'Q: verify fourth notes tree' '
2038 git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2039 test_cmp expect actual
2042 echo "$note2b_data" >expect
2043 test_expect_success 'Q: verify second note for second commit' '
2044 git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual
2047 cat >input <<EOF
2048 reset refs/heads/Q0
2050 commit refs/heads/note-Q0
2051 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2052 data <<COMMIT
2053 Note for an empty branch.
2054 COMMIT
2056 N inline refs/heads/Q0
2057 data <<NOTE
2058 some note
2059 NOTE
2061 test_expect_success 'Q: deny note on empty branch' '
2062 test_must_fail git fast-import <input
2065 ### series R (feature and option)
2068 cat >input <<EOF
2069 feature no-such-feature-exists
2072 test_expect_success 'R: abort on unsupported feature' '
2073 test_must_fail git fast-import <input
2076 cat >input <<EOF
2077 feature date-format=now
2080 test_expect_success 'R: supported feature is accepted' '
2081 git fast-import <input
2084 cat >input << EOF
2085 blob
2086 data 3
2088 feature date-format=now
2091 test_expect_success 'R: abort on receiving feature after data command' '
2092 test_must_fail git fast-import <input
2095 cat >input << EOF
2096 feature import-marks=git.marks
2097 feature import-marks=git2.marks
2100 test_expect_success 'R: only one import-marks feature allowed per stream' '
2101 test_must_fail git fast-import <input
2104 cat >input << EOF
2105 feature export-marks=git.marks
2106 blob
2107 mark :1
2108 data 3
2113 test_expect_success 'R: export-marks feature results in a marks file being created' '
2114 cat input | git fast-import &&
2115 grep :1 git.marks
2118 test_expect_success 'R: export-marks options can be overridden by commandline options' '
2119 cat input | git fast-import --export-marks=other.marks &&
2120 grep :1 other.marks
2123 test_expect_success 'R: catch typo in marks file name' '
2124 test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2125 echo "feature import-marks=nonexistent.marks" |
2126 test_must_fail git fast-import
2129 test_expect_success 'R: import and output marks can be the same file' '
2130 rm -f io.marks &&
2131 blob=$(echo hi | git hash-object --stdin) &&
2132 cat >expect <<-EOF &&
2133 :1 $blob
2134 :2 $blob
2136 git fast-import --export-marks=io.marks <<-\EOF &&
2137 blob
2138 mark :1
2139 data 3
2143 git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2144 blob
2145 mark :2
2146 data 3
2150 test_cmp expect io.marks
2153 test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
2154 rm -f io.marks &&
2155 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2156 blob
2157 mark :1
2158 data 3
2164 test_expect_success 'R: --import-marks-if-exists' '
2165 rm -f io.marks &&
2166 blob=$(echo hi | git hash-object --stdin) &&
2167 echo ":1 $blob" >expect &&
2168 git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2169 blob
2170 mark :1
2171 data 3
2175 test_cmp expect io.marks
2178 test_expect_success 'R: feature import-marks-if-exists' '
2179 rm -f io.marks &&
2180 >expect &&
2182 git fast-import --export-marks=io.marks <<-\EOF &&
2183 feature import-marks-if-exists=not_io.marks
2185 test_cmp expect io.marks &&
2187 blob=$(echo hi | git hash-object --stdin) &&
2189 echo ":1 $blob" >io.marks &&
2190 echo ":1 $blob" >expect &&
2191 echo ":2 $blob" >>expect &&
2193 git fast-import --export-marks=io.marks <<-\EOF &&
2194 feature import-marks-if-exists=io.marks
2195 blob
2196 mark :2
2197 data 3
2201 test_cmp expect io.marks &&
2203 echo ":3 $blob" >>expect &&
2205 git fast-import --import-marks=io.marks \
2206 --export-marks=io.marks <<-\EOF &&
2207 feature import-marks-if-exists=not_io.marks
2208 blob
2209 mark :3
2210 data 3
2214 test_cmp expect io.marks &&
2216 >expect &&
2218 git fast-import --import-marks-if-exists=not_io.marks \
2219 --export-marks=io.marks <<-\EOF &&
2220 feature import-marks-if-exists=io.marks
2222 test_cmp expect io.marks
2225 cat >input << EOF
2226 feature import-marks=marks.out
2227 feature export-marks=marks.new
2230 test_expect_success 'R: import to output marks works without any content' '
2231 cat input | git fast-import &&
2232 test_cmp marks.out marks.new
2235 cat >input <<EOF
2236 feature import-marks=nonexistent.marks
2237 feature export-marks=marks.new
2240 test_expect_success 'R: import marks prefers commandline marks file over the stream' '
2241 cat input | git fast-import --import-marks=marks.out &&
2242 test_cmp marks.out marks.new
2246 cat >input <<EOF
2247 feature import-marks=nonexistent.marks
2248 feature export-marks=combined.marks
2251 test_expect_success 'R: multiple --import-marks= should be honoured' '
2252 head -n2 marks.out > one.marks &&
2253 tail -n +3 marks.out > two.marks &&
2254 git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
2255 test_cmp marks.out combined.marks
2258 cat >input <<EOF
2259 feature relative-marks
2260 feature import-marks=relative.in
2261 feature export-marks=relative.out
2264 test_expect_success 'R: feature relative-marks should be honoured' '
2265 mkdir -p .git/info/fast-import/ &&
2266 cp marks.new .git/info/fast-import/relative.in &&
2267 git fast-import <input &&
2268 test_cmp marks.new .git/info/fast-import/relative.out
2271 cat >input <<EOF
2272 feature relative-marks
2273 feature import-marks=relative.in
2274 feature no-relative-marks
2275 feature export-marks=non-relative.out
2278 test_expect_success 'R: feature no-relative-marks should be honoured' '
2279 git fast-import <input &&
2280 test_cmp marks.new non-relative.out
2283 test_expect_success 'R: feature ls supported' '
2284 echo "feature ls" |
2285 git fast-import
2288 test_expect_success 'R: feature cat-blob supported' '
2289 echo "feature cat-blob" |
2290 git fast-import
2293 test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
2294 test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2297 test_expect_success !MINGW 'R: print old blob' '
2298 blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2299 cat >expect <<-EOF &&
2300 ${blob} blob 11
2301 yes it can
2304 echo "cat-blob $blob" |
2305 git fast-import --cat-blob-fd=6 6>actual &&
2306 test_cmp expect actual
2309 test_expect_success !MINGW 'R: in-stream cat-blob-fd not respected' '
2310 echo hello >greeting &&
2311 blob=$(git hash-object -w greeting) &&
2312 cat >expect <<-EOF &&
2313 ${blob} blob 6
2314 hello
2317 git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2318 cat-blob $blob
2320 test_cmp expect actual.3 &&
2321 test_must_be_empty actual.1 &&
2322 git fast-import 3>actual.3 >actual.1 <<-EOF &&
2323 option cat-blob-fd=3
2324 cat-blob $blob
2326 test_must_be_empty actual.3 &&
2327 test_cmp expect actual.1
2330 test_expect_success !MINGW 'R: print mark for new blob' '
2331 echo "effluentish" | git hash-object --stdin >expect &&
2332 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2333 blob
2334 mark :1
2335 data <<BLOB_END
2336 effluentish
2337 BLOB_END
2338 get-mark :1
2340 test_cmp expect actual
2343 test_expect_success !MINGW 'R: print new blob' '
2344 blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2345 cat >expect <<-EOF &&
2346 ${blob} blob 12
2347 yep yep yep
2350 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2351 blob
2352 mark :1
2353 data <<BLOB_END
2354 yep yep yep
2355 BLOB_END
2356 cat-blob :1
2358 test_cmp expect actual
2361 test_expect_success !MINGW 'R: print new blob by sha1' '
2362 blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2363 cat >expect <<-EOF &&
2364 ${blob} blob 25
2365 a new blob named by sha1
2368 git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2369 blob
2370 data <<BLOB_END
2371 a new blob named by sha1
2372 BLOB_END
2373 cat-blob $blob
2375 test_cmp expect actual
2378 test_expect_success 'setup: big file' '
2380 echo "the quick brown fox jumps over the lazy dog" >big &&
2381 for i in 1 2 3
2383 cat big big big big >bigger &&
2384 cat bigger bigger bigger bigger >big ||
2385 exit
2386 done
2390 test_expect_success 'R: print two blobs to stdout' '
2391 blob1=$(git hash-object big) &&
2392 blob1_len=$(wc -c <big) &&
2393 blob2=$(echo hello | git hash-object --stdin) &&
2395 echo ${blob1} blob $blob1_len &&
2396 cat big &&
2397 cat <<-EOF
2399 ${blob2} blob 6
2400 hello
2403 } >expect &&
2405 cat <<-\END_PART1 &&
2406 blob
2407 mark :1
2408 data <<data_end
2409 END_PART1
2410 cat big &&
2411 cat <<-\EOF
2412 data_end
2413 blob
2414 mark :2
2415 data <<data_end
2416 hello
2417 data_end
2418 cat-blob :1
2419 cat-blob :2
2422 git fast-import >actual &&
2423 test_cmp expect actual
2426 test_expect_success PIPE 'R: copy using cat-file' '
2427 expect_id=$(git hash-object big) &&
2428 expect_len=$(wc -c <big) &&
2429 echo $expect_id blob $expect_len >expect.response &&
2431 rm -f blobs &&
2432 cat >frontend <<-\FRONTEND_END &&
2433 #!/bin/sh
2434 FRONTEND_END
2436 mkfifo blobs &&
2438 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2439 cat <<-\EOF &&
2440 feature cat-blob
2441 blob
2442 mark :1
2443 data <<BLOB
2445 cat big &&
2446 cat <<-\EOF &&
2447 BLOB
2448 cat-blob :1
2451 read blob_id type size <&3 &&
2452 echo "$blob_id $type $size" >response &&
2453 head_c $size >blob <&3 &&
2454 read newline <&3 &&
2456 cat <<-EOF &&
2457 commit refs/heads/copied
2458 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2459 data <<COMMIT
2460 copy big file as file3
2461 COMMIT
2462 M 644 inline file3
2463 data <<BLOB
2465 cat blob &&
2466 echo BLOB
2467 ) 3<blobs |
2468 git fast-import --cat-blob-fd=3 3>blobs &&
2469 git show copied:file3 >actual &&
2470 test_cmp expect.response response &&
2471 test_cmp big actual
2474 test_expect_success PIPE 'R: print blob mid-commit' '
2475 rm -f blobs &&
2476 echo "A blob from _before_ the commit." >expect &&
2477 mkfifo blobs &&
2479 exec 3<blobs &&
2480 cat <<-EOF &&
2481 feature cat-blob
2482 blob
2483 mark :1
2484 data <<BLOB
2485 A blob from _before_ the commit.
2486 BLOB
2487 commit refs/heads/temporary
2488 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2489 data <<COMMIT
2490 Empty commit
2491 COMMIT
2492 cat-blob :1
2495 read blob_id type size <&3 &&
2496 head_c $size >actual <&3 &&
2497 read newline <&3 &&
2499 echo
2501 git fast-import --cat-blob-fd=3 3>blobs &&
2502 test_cmp expect actual
2505 test_expect_success PIPE 'R: print staged blob within commit' '
2506 rm -f blobs &&
2507 echo "A blob from _within_ the commit." >expect &&
2508 mkfifo blobs &&
2510 exec 3<blobs &&
2511 cat <<-EOF &&
2512 feature cat-blob
2513 commit refs/heads/within
2514 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2515 data <<COMMIT
2516 Empty commit
2517 COMMIT
2518 M 644 inline within
2519 data <<BLOB
2520 A blob from _within_ the commit.
2521 BLOB
2524 to_get=$(
2525 echo "A blob from _within_ the commit." |
2526 git hash-object --stdin
2527 ) &&
2528 echo "cat-blob $to_get" &&
2530 read blob_id type size <&3 &&
2531 head_c $size >actual <&3 &&
2532 read newline <&3 &&
2534 echo deleteall
2536 git fast-import --cat-blob-fd=3 3>blobs &&
2537 test_cmp expect actual
2540 cat >input << EOF
2541 option git quiet
2542 blob
2543 data 3
2548 test_expect_success 'R: quiet option results in no stats being output' '
2549 cat input | git fast-import 2> output &&
2550 test_must_be_empty output
2553 test_expect_success 'R: feature done means terminating "done" is mandatory' '
2554 echo feature done | test_must_fail git fast-import &&
2555 test_must_fail git fast-import --done </dev/null
2558 test_expect_success 'R: terminating "done" with trailing gibberish is ok' '
2559 git fast-import <<-\EOF &&
2560 feature done
2561 done
2562 trailing gibberish
2564 git fast-import <<-\EOF
2565 done
2566 more trailing gibberish
2570 test_expect_success 'R: terminating "done" within commit' '
2571 cat >expect <<-\EOF &&
2572 OBJID
2573 :000000 100644 OBJID OBJID A hello.c
2574 :000000 100644 OBJID OBJID A hello2.c
2576 git fast-import <<-EOF &&
2577 commit refs/heads/done-ends
2578 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2579 data <<EOT
2580 Commit terminated by "done" command
2582 M 100644 inline hello.c
2583 data <<EOT
2584 Hello, world.
2586 C hello.c hello2.c
2587 done
2589 git rev-list done-ends |
2590 git diff-tree -r --stdin --root --always |
2591 sed -e "s/$_x40/OBJID/g" >actual &&
2592 test_cmp expect actual
2595 cat >input <<EOF
2596 option git non-existing-option
2599 test_expect_success 'R: die on unknown option' '
2600 test_must_fail git fast-import <input
2603 test_expect_success 'R: unknown commandline options are rejected' '\
2604 test_must_fail git fast-import --non-existing-option < /dev/null
2607 test_expect_success 'R: die on invalid option argument' '
2608 echo "option git active-branches=-5" |
2609 test_must_fail git fast-import &&
2610 echo "option git depth=" |
2611 test_must_fail git fast-import &&
2612 test_must_fail git fast-import --depth="5 elephants" </dev/null
2615 cat >input <<EOF
2616 option non-existing-vcs non-existing-option
2619 test_expect_success 'R: ignore non-git options' '
2620 git fast-import <input
2624 ## R: very large blobs
2626 blobsize=$((2*1024*1024 + 53))
2627 test-genrandom bar $blobsize >expect
2628 cat >input <<INPUT_END
2629 commit refs/heads/big-file
2630 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2631 data <<COMMIT
2632 R - big file
2633 COMMIT
2635 M 644 inline big1
2636 data $blobsize
2637 INPUT_END
2638 cat expect >>input
2639 cat >>input <<INPUT_END
2640 M 644 inline big2
2641 data $blobsize
2642 INPUT_END
2643 cat expect >>input
2644 echo >>input
2646 test_expect_success 'R: blob bigger than threshold' '
2647 test_create_repo R &&
2648 git --git-dir=R/.git fast-import --big-file-threshold=1 <input
2651 test_expect_success 'R: verify created pack' '
2653 cd R &&
2654 verify_packs -v > ../verify
2658 test_expect_success 'R: verify written objects' '
2659 git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2660 test_cmp_bin expect actual &&
2661 a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2662 b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2663 test $a = $b
2666 test_expect_success 'R: blob appears only once' '
2667 n=$(grep $a verify | wc -l) &&
2668 test 1 = $n
2672 ### series S
2675 # Make sure missing spaces and EOLs after mark references
2676 # cause errors.
2678 # Setup:
2680 # 1--2--4
2681 # \ /
2682 # -3-
2684 # commit marks: 301, 302, 303, 304
2685 # blob marks: 403, 404, resp.
2686 # note mark: 202
2688 # The error message when a space is missing not at the
2689 # end of the line is:
2691 # Missing space after ..
2693 # or when extra characters come after the mark at the end
2694 # of the line:
2696 # Garbage after ..
2698 # or when the dataref is neither "inline " or a known SHA1,
2700 # Invalid dataref ..
2702 test_tick
2704 cat >input <<INPUT_END
2705 commit refs/heads/S
2706 mark :301
2707 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2708 data <<COMMIT
2709 commit 1
2710 COMMIT
2711 M 100644 inline hello.c
2712 data <<BLOB
2713 blob 1
2714 BLOB
2716 commit refs/heads/S
2717 mark :302
2718 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2719 data <<COMMIT
2720 commit 2
2721 COMMIT
2722 from :301
2723 M 100644 inline hello.c
2724 data <<BLOB
2725 blob 2
2726 BLOB
2728 blob
2729 mark :403
2730 data <<BLOB
2731 blob 3
2732 BLOB
2734 blob
2735 mark :202
2736 data <<BLOB
2737 note 2
2738 BLOB
2739 INPUT_END
2741 test_expect_success 'S: initialize for S tests' '
2742 git fast-import --export-marks=marks <input
2746 # filemodify, three datarefs
2748 test_expect_success 'S: filemodify with garbage after mark must fail' '
2749 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2750 commit refs/heads/S
2751 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2752 data <<COMMIT
2753 commit N
2754 COMMIT
2755 M 100644 :403x hello.c
2757 cat err &&
2758 test_i18ngrep "space after mark" err
2761 # inline is misspelled; fast-import thinks it is some unknown dataref
2762 test_expect_success 'S: filemodify with garbage after inline must fail' '
2763 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2764 commit refs/heads/S
2765 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2766 data <<COMMIT
2767 commit N
2768 COMMIT
2769 M 100644 inlineX hello.c
2770 data <<BLOB
2771 inline
2772 BLOB
2774 cat err &&
2775 test_i18ngrep "nvalid dataref" err
2778 test_expect_success 'S: filemodify with garbage after sha1 must fail' '
2779 sha1=$(grep :403 marks | cut -d\ -f2) &&
2780 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2781 commit refs/heads/S
2782 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2783 data <<COMMIT
2784 commit N
2785 COMMIT
2786 M 100644 ${sha1}x hello.c
2788 cat err &&
2789 test_i18ngrep "space after SHA1" err
2793 # notemodify, three ways to say dataref
2795 test_expect_success 'S: notemodify with garabge after mark dataref must fail' '
2796 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2797 commit refs/heads/S
2798 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2799 data <<COMMIT
2800 commit S note dataref markref
2801 COMMIT
2802 N :202x :302
2804 cat err &&
2805 test_i18ngrep "space after mark" err
2808 test_expect_success 'S: notemodify with garbage after inline 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 inline
2814 COMMIT
2815 N inlineX :302
2816 data <<BLOB
2817 note blob
2818 BLOB
2820 cat err &&
2821 test_i18ngrep "nvalid dataref" err
2824 test_expect_success 'S: notemodify with garbage after sha1 dataref must fail' '
2825 sha1=$(grep :202 marks | cut -d\ -f2) &&
2826 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2827 commit refs/heads/S
2828 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2829 data <<COMMIT
2830 commit S note dataref sha1
2831 COMMIT
2832 N ${sha1}x :302
2834 cat err &&
2835 test_i18ngrep "space after SHA1" err
2839 # notemodify, mark in commit-ish
2841 test_expect_success 'S: notemodify with garbage after mark commit-ish must fail' '
2842 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2843 commit refs/heads/Snotes
2844 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2845 data <<COMMIT
2846 commit S note commit-ish
2847 COMMIT
2848 N :202 :302x
2850 cat err &&
2851 test_i18ngrep "after mark" err
2855 # from
2857 test_expect_success 'S: from with garbage after mark must fail' '
2858 test_must_fail \
2859 git fast-import --import-marks=marks --export-marks=marks <<-EOF 2>err &&
2860 commit refs/heads/S2
2861 mark :303
2862 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2863 data <<COMMIT
2864 commit 3
2865 COMMIT
2866 from :301x
2867 M 100644 :403 hello.c
2871 # go create the commit, need it for merge test
2872 git fast-import --import-marks=marks --export-marks=marks <<-EOF &&
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 :301
2880 M 100644 :403 hello.c
2883 # now evaluate the error
2884 cat err &&
2885 test_i18ngrep "after mark" err
2890 # merge
2892 test_expect_success 'S: merge with garbage after mark must fail' '
2893 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2894 commit refs/heads/S
2895 mark :304
2896 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2897 data <<COMMIT
2898 merge 4
2899 COMMIT
2900 from :302
2901 merge :303x
2902 M 100644 :403 hello.c
2904 cat err &&
2905 test_i18ngrep "after mark" err
2909 # tag, from markref
2911 test_expect_success 'S: tag with garbage after mark must fail' '
2912 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2913 tag refs/tags/Stag
2914 from :302x
2915 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2916 data <<TAG
2917 tag S
2920 cat err &&
2921 test_i18ngrep "after mark" err
2925 # cat-blob markref
2927 test_expect_success 'S: cat-blob with garbage after mark must fail' '
2928 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2929 cat-blob :403x
2931 cat err &&
2932 test_i18ngrep "after mark" err
2936 # ls markref
2938 test_expect_success 'S: ls with garbage after mark must fail' '
2939 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2940 ls :302x hello.c
2942 cat err &&
2943 test_i18ngrep "space after mark" err
2946 test_expect_success 'S: ls with garbage after sha1 must fail' '
2947 sha1=$(grep :302 marks | cut -d\ -f2) &&
2948 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2949 ls ${sha1}x hello.c
2951 cat err &&
2952 test_i18ngrep "space after tree-ish" err
2956 ### series T (ls)
2958 # Setup is carried over from series S.
2960 test_expect_success 'T: ls root tree' '
2961 sed -e "s/Z\$//" >expect <<-EOF &&
2962 040000 tree $(git rev-parse S^{tree}) Z
2964 sha1=$(git rev-parse --verify S) &&
2965 git fast-import --import-marks=marks <<-EOF >actual &&
2966 ls $sha1 ""
2968 test_cmp expect actual
2971 test_expect_success 'T: delete branch' '
2972 git branch to-delete &&
2973 git fast-import <<-EOF &&
2974 reset refs/heads/to-delete
2975 from 0000000000000000000000000000000000000000
2977 test_must_fail git rev-parse --verify refs/heads/to-delete
2980 test_expect_success 'T: empty reset doesnt delete branch' '
2981 git branch not-to-delete &&
2982 git fast-import <<-EOF &&
2983 reset refs/heads/not-to-delete
2985 git show-ref &&
2986 git rev-parse --verify refs/heads/not-to-delete
2990 ### series U (filedelete)
2993 cat >input <<INPUT_END
2994 commit refs/heads/U
2995 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2996 data <<COMMIT
2997 test setup
2998 COMMIT
2999 M 100644 inline hello.c
3000 data <<BLOB
3001 blob 1
3002 BLOB
3003 M 100644 inline good/night.txt
3004 data <<BLOB
3005 sleep well
3006 BLOB
3007 M 100644 inline good/bye.txt
3008 data <<BLOB
3009 au revoir
3010 BLOB
3012 INPUT_END
3014 test_expect_success 'U: initialize for U tests' '
3015 git fast-import <input
3018 cat >input <<INPUT_END
3019 commit refs/heads/U
3020 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3021 data <<COMMIT
3022 delete good/night.txt
3023 COMMIT
3024 from refs/heads/U^0
3025 D good/night.txt
3027 INPUT_END
3029 test_expect_success 'U: filedelete file succeeds' '
3030 git fast-import <input
3033 cat >expect <<EOF
3034 :100644 000000 2907ebb4bf85d91bf0716bb3bd8a68ef48d6da76 0000000000000000000000000000000000000000 D good/night.txt
3037 git diff-tree -M -r U^1 U >actual
3039 test_expect_success 'U: validate file delete result' '
3040 compare_diff_raw expect actual
3043 cat >input <<INPUT_END
3044 commit refs/heads/U
3045 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3046 data <<COMMIT
3047 delete good dir
3048 COMMIT
3049 from refs/heads/U^0
3050 D good
3052 INPUT_END
3054 test_expect_success 'U: filedelete directory succeeds' '
3055 git fast-import <input
3058 cat >expect <<EOF
3059 :100644 000000 69cb75792f55123d8389c156b0b41c2ff00ed507 0000000000000000000000000000000000000000 D good/bye.txt
3062 git diff-tree -M -r U^1 U >actual
3064 test_expect_success 'U: validate directory delete result' '
3065 compare_diff_raw expect actual
3068 cat >input <<INPUT_END
3069 commit refs/heads/U
3070 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3071 data <<COMMIT
3072 must succeed
3073 COMMIT
3074 from refs/heads/U^0
3075 D ""
3077 INPUT_END
3079 test_expect_success 'U: filedelete root succeeds' '
3080 git fast-import <input
3083 cat >expect <<EOF
3084 :100644 000000 c18147dc648481eeb65dc5e66628429a64843327 0000000000000000000000000000000000000000 D hello.c
3087 git diff-tree -M -r U^1 U >actual
3089 test_expect_success 'U: validate root delete result' '
3090 compare_diff_raw expect actual
3093 test_done