3 # Copyright (c) 2007 Shawn Pearce
6 test_description
='test git fast-import utility'
8 .
"$TEST_DIRECTORY"/diff-lib.sh
;# test-lib chdir's into trash
11 for p
in .git
/objects
/pack
/*.pack
13 git verify-pack
"$@" "$p" ||
return
27 file5_data
='an inline file.
28 we should see it later.'
37 test_expect_success
'empty stream succeeds' '
38 git config fastimport.unpackLimit 0 &&
39 git fast-import </dev/null
42 test_expect_success
'truncated stream complains' '
43 echo "tag foo" | test_must_fail git fast-import
46 test_expect_success
'A: create pack from stdin' '
48 cat >input <<-INPUT_END &&
65 commit refs/heads/master
67 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
79 An annotated tag without a tagger
85 An annotated tag that annotates a blob.
91 Another annotated tag that annotates a blob.
94 reset refs/tags/to-be-deleted
95 from 0000000000000000000000000000000000000000
101 Tag of our lovely commit
104 reset refs/tags/nested
105 from 0000000000000000000000000000000000000000
111 Tag of tag of our lovely commit
119 git fast-import --export-marks=marks.out <input &&
120 git whatchanged master
123 test_expect_success
'A: verify pack' '
127 test_expect_success
'A: verify commit' '
128 cat >expect <<-EOF &&
129 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
130 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
134 git cat-file commit master | sed 1d >actual &&
135 test_cmp expect actual
138 test_expect_success
'A: verify tree' '
139 cat >expect <<-EOF &&
144 git cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
145 test_cmp expect actual
148 test_expect_success
'A: verify file2' '
149 echo "$file2_data" >expect &&
150 git cat-file blob master:file2 >actual &&
151 test_cmp expect actual
154 test_expect_success
'A: verify file3' '
155 echo "$file3_data" >expect &&
156 git cat-file blob master:file3 >actual &&
157 test_cmp expect actual
160 test_expect_success
'A: verify file4' '
161 printf "$file4_data" >expect &&
162 git cat-file blob master:file4 >actual &&
163 test_cmp expect actual
166 test_expect_success
'A: verify tag/series-A' '
167 cat >expect <<-EOF &&
168 object $(git rev-parse refs/heads/master)
172 An annotated tag without a tagger
174 git cat-file tag tags/series-A >actual &&
175 test_cmp expect actual
178 test_expect_success
'A: verify tag/series-A-blob' '
179 cat >expect <<-EOF &&
180 object $(git rev-parse refs/heads/master:file3)
184 An annotated tag that annotates a blob.
186 git cat-file tag tags/series-A-blob >actual &&
187 test_cmp expect actual
190 test_expect_success
'A: verify tag deletion is successful' '
191 test_must_fail git rev-parse --verify refs/tags/to-be-deleted
194 test_expect_success
'A: verify marks output' '
195 cat >expect <<-EOF &&
196 :2 $(git rev-parse --verify master:file2)
197 :3 $(git rev-parse --verify master:file3)
198 :4 $(git rev-parse --verify master:file4)
199 :5 $(git rev-parse --verify master^0)
200 :6 $(git cat-file tag nested | grep object | cut -d" " -f 2)
201 :7 $(git rev-parse --verify nested)
202 :8 $(git rev-parse --verify master^0)
204 test_cmp expect marks.out
207 test_expect_success
'A: verify marks import' '
209 --import-marks=marks.out \
210 --export-marks=marks.new \
212 test_cmp expect marks.new
215 test_expect_success
'A: tag blob by sha1' '
217 new_blob=$(echo testing | git hash-object --stdin) &&
218 cat >input <<-INPUT_END &&
220 from $(git rev-parse refs/heads/master:file3)
231 commit refs/heads/new_blob
235 #pretend we got sha1 from fast-import
245 cat >expect <<-EOF &&
246 object $(git rev-parse refs/heads/master:file3)
258 git fast-import <input &&
259 git cat-file tag tags/series-A-blob-2 >actual &&
260 git cat-file tag tags/series-A-blob-3 >>actual &&
261 test_cmp expect actual
264 test_expect_success
'A: verify marks import does not crash' '
266 cat >input <<-INPUT_END &&
267 commit refs/heads/verify--import-marks
268 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
274 M 755 :2 copy-of-file2
278 git fast-import --import-marks=marks.out <input &&
279 git whatchanged verify--import-marks
282 test_expect_success
'A: verify pack' '
286 test_expect_success
'A: verify diff' '
287 cat >expect <<-EOF &&
288 :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2
290 git diff-tree -M -r master verify--import-marks >actual &&
291 compare_diff_raw expect actual &&
292 test $(git rev-parse --verify master:file2) \
293 = $(git rev-parse --verify verify--import-marks:copy-of-file2)
296 test_expect_success
'A: export marks with large values' '
298 mt=$(git hash-object --stdin < /dev/null) &&
303 cat >input.commit <<-EOF &&
304 commit refs/heads/verify--dump-marks
305 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
307 test the sparse array dumping routines with exponentially growing marks
312 while test "$i" -lt 27
314 cat >>input.blob <<-EOF &&
325 echo "M 100644 :$l l$i" >>input.commit &&
326 echo "M 100644 :$m m$i" >>input.commit &&
327 echo "M 100644 :$n n$i" >>input.commit &&
329 echo ":$l $mt" >>marks.exp &&
330 echo ":$m $mt" >>marks.exp &&
331 echo ":$n $mt" >>marks.exp &&
333 printf "100644 blob $mt\tl$i\n" >>tree.exp &&
334 printf "100644 blob $mt\tm$i\n" >>tree.exp &&
335 printf "100644 blob $mt\tn$i\n" >>tree.exp &&
341 i=$((1 + $i)) || return 1
344 sort tree.exp > tree.exp_s &&
346 cat input.blob input.commit | git fast-import --export-marks=marks.large &&
347 git ls-tree refs/heads/verify--dump-marks >tree.out &&
348 test_cmp tree.exp_s tree.out &&
349 test_cmp marks.exp marks.large
356 test_expect_success
'B: fail on invalid blob sha1' '
358 cat >input <<-INPUT_END &&
359 commit refs/heads/branch
361 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
366 from refs/heads/master
367 M 755 0000000000000000000000000000000000000001 zero1
371 test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" &&
372 test_must_fail git fast-import <input
375 test_expect_success
'B: accept branch name "TEMP_TAG"' '
376 cat >input <<-INPUT_END &&
378 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
383 from refs/heads/master
387 test_when_finished "rm -f .git/TEMP_TAG
390 git fast-import <input &&
391 test -f .git/TEMP_TAG &&
392 test $(git rev-parse master) = $(git rev-parse TEMP_TAG^)
395 test_expect_success
'B: accept empty committer' '
396 cat >input <<-INPUT_END &&
397 commit refs/heads/empty-committer-1
398 committer <> $GIT_COMMITTER_DATE
404 test_when_finished "git update-ref -d refs/heads/empty-committer-1
407 git fast-import <input &&
413 test_expect_success
'B: reject invalid timezone' '
414 cat >input <<-INPUT_END &&
415 commit refs/heads/invalid-timezone
416 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800
422 test_when_finished "git update-ref -d refs/heads/invalid-timezone" &&
423 test_must_fail git fast-import <input
426 test_expect_success
'B: accept invalid timezone with raw-permissive' '
427 cat >input <<-INPUT_END &&
428 commit refs/heads/invalid-timezone
429 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800
435 git init invalid-timezone &&
436 git -C invalid-timezone fast-import --date-format=raw-permissive <input &&
437 git -C invalid-timezone cat-file -p invalid-timezone >out &&
438 grep "1234567890 [+]051800" out
441 test_expect_success
'B: accept and fixup committer with no name' '
442 cat >input <<-INPUT_END &&
443 commit refs/heads/empty-committer-2
444 committer <a@b.com> $GIT_COMMITTER_DATE
450 test_when_finished "git update-ref -d refs/heads/empty-committer-2
453 git fast-import <input &&
459 test_expect_success
'B: fail on invalid committer (1)' '
460 cat >input <<-INPUT_END &&
461 commit refs/heads/invalid-committer
462 committer Name email> $GIT_COMMITTER_DATE
468 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
469 test_must_fail git fast-import <input
472 test_expect_success
'B: fail on invalid committer (2)' '
473 cat >input <<-INPUT_END &&
474 commit refs/heads/invalid-committer
475 committer Name <e<mail> $GIT_COMMITTER_DATE
481 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
482 test_must_fail git fast-import <input
485 test_expect_success
'B: fail on invalid committer (3)' '
486 cat >input <<-INPUT_END &&
487 commit refs/heads/invalid-committer
488 committer Name <email>> $GIT_COMMITTER_DATE
494 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
495 test_must_fail git fast-import <input
498 test_expect_success
'B: fail on invalid committer (4)' '
499 cat >input <<-INPUT_END &&
500 commit refs/heads/invalid-committer
501 committer Name <email $GIT_COMMITTER_DATE
507 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
508 test_must_fail git fast-import <input
511 test_expect_success
'B: fail on invalid committer (5)' '
512 cat >input <<-INPUT_END &&
513 commit refs/heads/invalid-committer
514 committer Name<email> $GIT_COMMITTER_DATE
520 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
521 test_must_fail git fast-import <input
528 test_expect_success
'C: incremental import create pack from stdin' '
529 newf=$(echo hi newf | git hash-object -w --stdin) &&
530 oldf=$(git rev-parse --verify master:file2) &&
532 cat >input <<-INPUT_END &&
533 commit refs/heads/branch
534 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
539 from refs/heads/master
540 M 644 $oldf file2/oldf
541 M 755 $newf file2/newf
546 git fast-import <input &&
547 git whatchanged branch
550 test_expect_success
'C: verify pack' '
554 test_expect_success
'C: validate reuse existing blob' '
555 test $newf = $(git rev-parse --verify branch:file2/newf) &&
556 test $oldf = $(git rev-parse --verify branch:file2/oldf)
559 test_expect_success
'C: verify commit' '
560 cat >expect <<-EOF &&
561 parent $(git rev-parse --verify master^0)
562 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
563 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
568 git cat-file commit branch | sed 1d >actual &&
569 test_cmp expect actual
572 test_expect_success
'C: validate rename result' '
573 cat >expect <<-EOF &&
574 :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
575 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
576 :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
578 git diff-tree -M -r master branch >actual &&
579 compare_diff_raw expect actual
586 test_expect_success
'D: inline data in commit' '
588 cat >input <<-INPUT_END &&
589 commit refs/heads/branch
590 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
595 from refs/heads/branch^0
596 M 644 inline newdir/interesting
601 M 755 inline newdir/exec.sh
608 git fast-import <input &&
609 git whatchanged branch
612 test_expect_success
'D: verify pack' '
616 test_expect_success
'D: validate new files added' '
617 cat >expect <<-EOF &&
618 :000000 100755 0000000000000000000000000000000000000000 e74b7d465e52746be2b4bae983670711e6e66657 A newdir/exec.sh
619 :000000 100644 0000000000000000000000000000000000000000 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 A newdir/interesting
621 git diff-tree -M -r branch^ branch >actual &&
622 compare_diff_raw expect actual
625 test_expect_success
'D: verify file5' '
626 echo "$file5_data" >expect &&
627 git cat-file blob branch:newdir/interesting >actual &&
628 test_cmp expect actual
631 test_expect_success
'D: verify file6' '
632 echo "$file6_data" >expect &&
633 git cat-file blob branch:newdir/exec.sh >actual &&
634 test_cmp expect actual
641 test_expect_success
'E: rfc2822 date, --date-format=raw' '
642 cat >input <<-INPUT_END &&
643 commit refs/heads/branch
644 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
645 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
650 from refs/heads/branch^0
654 test_must_fail git fast-import --date-format=raw <input
656 test_expect_success
'E: rfc2822 date, --date-format=rfc2822' '
657 git fast-import --date-format=rfc2822 <input
660 test_expect_success
'E: verify pack' '
664 test_expect_success
'E: verify commit' '
665 cat >expect <<-EOF &&
666 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
667 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
671 git cat-file commit branch | sed 1,2d >actual &&
672 test_cmp expect actual
679 test_expect_success
'F: non-fast-forward update skips' '
680 old_branch=$(git rev-parse --verify branch^0) &&
682 cat >input <<-INPUT_END &&
683 commit refs/heads/branch
684 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
686 losing things already?
689 from refs/heads/branch~1
691 reset refs/heads/other
692 from refs/heads/branch
696 test_must_fail git fast-import <input &&
697 # branch must remain unaffected
698 test $old_branch = $(git rev-parse --verify branch^0)
701 test_expect_success
'F: verify pack' '
705 test_expect_success
'F: verify other commit' '
706 cat >expect <<-EOF &&
707 tree $(git rev-parse branch~1^{tree})
708 parent $(git rev-parse branch~1)
709 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
710 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
712 losing things already?
714 git cat-file commit other >actual &&
715 test_cmp expect actual
722 test_expect_success
'G: non-fast-forward update forced' '
723 old_branch=$(git rev-parse --verify branch^0) &&
725 cat >input <<-INPUT_END &&
726 commit refs/heads/branch
727 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
729 losing things already?
732 from refs/heads/branch~1
735 git fast-import --force <input
738 test_expect_success
'G: verify pack' '
742 test_expect_success
'G: branch changed, but logged' '
743 test $old_branch != $(git rev-parse --verify branch^0) &&
744 test $old_branch = $(git rev-parse --verify branch@{1})
751 test_expect_success
'H: deletall, add 1' '
753 cat >input <<-INPUT_END &&
755 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
760 from refs/heads/branch^0
761 M 644 inline i-will-die
763 this file will never exist.
767 M 644 inline h/e/l/lo
773 git fast-import <input &&
777 test_expect_success
'H: verify pack' '
781 test_expect_success
'H: validate old files removed, new files added' '
782 cat >expect <<-EOF &&
783 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf
784 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf
785 :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4
786 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo
787 :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh
789 git diff-tree -M -r H^ H >actual &&
790 compare_diff_raw expect actual
793 test_expect_success
'H: verify file' '
794 echo "$file5_data" >expect &&
795 git cat-file blob H:h/e/l/lo >actual &&
796 test_cmp expect actual
803 test_expect_success
'I: export-pack-edges' '
804 cat >input <<-INPUT_END &&
805 commit refs/heads/export-boundary
806 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
808 we have a border. its only 40 characters wide.
811 from refs/heads/branch
814 git fast-import --export-pack-edges=edges.list <input
817 test_expect_success
'I: verify edge list' '
818 cat >expect <<-EOF &&
819 .git/objects/pack/pack-.pack: $(git rev-parse --verify export-boundary)
821 sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
822 test_cmp expect actual
829 test_expect_success
'J: reset existing branch creates empty commit' '
830 cat >input <<-INPUT_END &&
832 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
837 from refs/heads/branch
842 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
848 git fast-import <input
850 test_expect_success
'J: branch has 1 commit, empty tree' '
851 test 1 = $(git rev-list J | wc -l) &&
852 test 0 = $(git ls-tree J | wc -l)
855 test_expect_success
'J: tag must fail on empty branch' '
856 cat >input <<-INPUT_END &&
862 Tag branch that was reset.
865 test_must_fail git fast-import <input
872 test_expect_success
'K: reinit branch with from' '
873 cat >input <<-INPUT_END &&
875 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
880 from refs/heads/branch
883 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
888 from refs/heads/branch^1
891 git fast-import <input
893 test_expect_success
'K: verify K^1 = branch^1' '
894 test $(git rev-parse --verify branch^1) \
895 = $(git rev-parse --verify K^1)
902 test_expect_success
'L: verify internal tree sorting' '
903 cat >input <<-INPUT_END &&
917 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
927 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
937 cat >expect <<-EXPECT_END &&
938 :100644 100644 4268632... 55d3a52... M b.
939 :040000 040000 0ae5cac... 443c768... M b
940 :100644 100644 4268632... 55d3a52... M ba
943 git fast-import <input &&
944 GIT_PRINT_SHA1_ELLIPSIS="yes" git diff-tree --abbrev --raw L^ L >output &&
945 test_cmp expect output
948 test_expect_success
'L: nested tree copy does not corrupt deltas' '
949 cat >input <<-INPUT_END &&
957 committer C O Mitter <committer@example.com> 1112912473 -0700
966 committer C O Mitter <committer@example.com> 1112912473 -0700
975 cat >expect <<-\EOF &&
980 test_when_finished "git update-ref -d refs/heads/L2" &&
981 git fast-import <input &&
982 git ls-tree L2 g/b/ >tmp &&
983 cat tmp | cut -f 2 >actual &&
984 test_cmp expect actual &&
985 git fsck $(git rev-parse L2)
992 test_expect_success
'M: rename file in same subdirectory' '
994 cat >input <<-INPUT_END &&
996 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1001 from refs/heads/branch^0
1002 R file2/newf file2/n.e.w.f
1006 cat >expect <<-EOF &&
1007 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f
1009 git fast-import <input &&
1010 git diff-tree -M -r M1^ M1 >actual &&
1011 compare_diff_raw expect actual
1014 test_expect_success
'M: rename file to new subdirectory' '
1015 cat >input <<-INPUT_END &&
1016 commit refs/heads/M2
1017 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1022 from refs/heads/branch^0
1023 R file2/newf i/am/new/to/you
1027 cat >expect <<-EOF &&
1028 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you
1030 git fast-import <input &&
1031 git diff-tree -M -r M2^ M2 >actual &&
1032 compare_diff_raw expect actual
1035 test_expect_success
'M: rename subdirectory to new subdirectory' '
1036 cat >input <<-INPUT_END &&
1037 commit refs/heads/M3
1038 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1043 from refs/heads/M2^0
1048 cat >expect <<-EOF &&
1049 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you
1051 git fast-import <input &&
1052 git diff-tree -M -r M3^ M3 >actual &&
1053 compare_diff_raw expect actual
1056 test_expect_success
'M: rename root to subdirectory' '
1057 cat >input <<-INPUT_END &&
1058 commit refs/heads/M4
1059 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1064 from refs/heads/M2^0
1069 cat >expect <<-EOF &&
1070 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2/oldf sub/file2/oldf
1071 :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 R100 file4 sub/file4
1072 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you sub/i/am/new/to/you
1073 :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 R100 newdir/exec.sh sub/newdir/exec.sh
1074 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting sub/newdir/interesting
1076 git fast-import <input &&
1077 git diff-tree -M -r M4^ M4 >actual &&
1078 compare_diff_raw expect actual
1085 test_expect_success
'N: copy file in same subdirectory' '
1087 cat >input <<-INPUT_END &&
1088 commit refs/heads/N1
1089 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1094 from refs/heads/branch^0
1095 C file2/newf file2/n.e.w.f
1099 cat >expect <<-EOF &&
1100 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f
1102 git fast-import <input &&
1103 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1104 compare_diff_raw expect actual
1107 test_expect_success
'N: copy then modify subdirectory' '
1108 cat >input <<-INPUT_END &&
1109 commit refs/heads/N2
1110 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1112 clean directory copy
1115 from refs/heads/branch^0
1118 commit refs/heads/N2
1119 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1121 modify directory copy
1124 M 644 inline file3/file5
1131 cat >expect <<-EOF &&
1132 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1133 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1134 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1136 git fast-import <input &&
1137 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1138 compare_diff_raw expect actual
1141 test_expect_success
'N: copy dirty subdirectory' '
1142 cat >input <<-INPUT_END &&
1143 commit refs/heads/N3
1144 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1146 dirty directory copy
1149 from refs/heads/branch^0
1150 M 644 inline file2/file5
1160 git fast-import <input &&
1161 test $(git rev-parse N2^{tree}) = $(git rev-parse N3^{tree})
1164 test_expect_success
'N: copy directory by id' '
1165 cat >expect <<-\EOF &&
1166 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1167 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1169 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1170 cat >input <<-INPUT_END &&
1171 commit refs/heads/N4
1172 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1177 from refs/heads/branch^0
1178 M 040000 $subdir file3
1180 git fast-import <input &&
1181 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1182 compare_diff_raw expect actual
1185 test_expect_success PIPE
'N: read and copy directory' '
1186 cat >expect <<-\EOF &&
1187 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1188 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1190 git update-ref -d refs/heads/N4 &&
1196 commit refs/heads/N4
1197 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1199 copy by tree hash, part 2
1202 from refs/heads/branch^0
1205 read mode type tree filename &&
1206 echo "M 040000 $tree file3"
1208 git fast-import --cat-blob-fd=3 3>backflow &&
1209 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1210 compare_diff_raw expect actual
1213 test_expect_success PIPE
'N: empty directory reads as missing' '
1214 cat <<-\EOF >expect &&
1216 :000000 100644 OBJNAME OBJNAME A unrelated
1218 echo "missing src" >expect.response &&
1219 git update-ref -d refs/heads/read-empty &&
1225 commit refs/heads/read-empty
1226 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1228 read "empty" (missing) directory
1231 M 100644 inline src/greeting
1235 C src/greeting dst1/non-greeting
1236 C src/greeting unrelated
1237 # leave behind "empty" src directory
1242 printf "%s\n" "$line" >response &&
1248 git fast-import --cat-blob-fd=3 3>backflow &&
1249 test_cmp expect.response response &&
1250 git rev-list read-empty |
1251 git diff-tree -r --root --stdin |
1252 sed "s/$OID_REGEX/OBJNAME/g" >actual &&
1253 test_cmp expect actual
1256 test_expect_success
'N: copy root directory by tree hash' '
1257 cat >expect <<-\EOF &&
1258 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file3/newf
1259 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file3/oldf
1261 root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1262 cat >input <<-INPUT_END &&
1263 commit refs/heads/N6
1264 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1266 copy root directory by tree hash
1269 from refs/heads/branch^0
1272 git fast-import <input &&
1273 git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1274 compare_diff_raw expect actual
1277 test_expect_success
'N: copy root by path' '
1278 cat >expect <<-\EOF &&
1279 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf oldroot/file2/newf
1280 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf oldroot/file2/oldf
1281 :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 C100 file4 oldroot/file4
1282 :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 C100 newdir/exec.sh oldroot/newdir/exec.sh
1283 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting oldroot/newdir/interesting
1285 cat >input <<-INPUT_END &&
1286 commit refs/heads/N-copy-root-path
1287 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1289 copy root directory by (empty) path
1292 from refs/heads/branch^0
1295 git fast-import <input &&
1296 git diff-tree -C --find-copies-harder -r branch N-copy-root-path >actual &&
1297 compare_diff_raw expect actual
1300 test_expect_success
'N: delete directory by copying' '
1301 cat >expect <<-\EOF &&
1303 :100644 000000 OBJID OBJID D foo/bar/qux
1305 :000000 100644 OBJID OBJID A foo/bar/baz
1306 :000000 100644 OBJID OBJID A foo/bar/qux
1308 empty_tree=$(git mktree </dev/null) &&
1309 cat >input <<-INPUT_END &&
1310 commit refs/heads/N-delete
1311 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1313 collect data to be deleted
1317 M 100644 inline foo/bar/baz
1321 C "foo/bar/baz" "foo/bar/qux"
1322 C "foo/bar/baz" "foo/bar/quux/1"
1323 C "foo/bar/baz" "foo/bar/quuux"
1324 M 040000 $empty_tree foo/bar/quux
1325 M 040000 $empty_tree foo/bar/quuux
1327 commit refs/heads/N-delete
1328 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1333 M 040000 $empty_tree foo/bar/qux
1335 git fast-import <input &&
1336 git rev-list N-delete |
1337 git diff-tree -r --stdin --root --always |
1338 sed -e "s/$OID_REGEX/OBJID/g" >actual &&
1339 test_cmp expect actual
1342 test_expect_success
'N: modify copied tree' '
1343 cat >expect <<-\EOF &&
1344 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1345 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1346 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1348 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1349 cat >input <<-INPUT_END &&
1350 commit refs/heads/N5
1351 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1356 from refs/heads/branch^0
1357 M 040000 $subdir file3
1359 commit refs/heads/N5
1360 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1362 modify directory copy
1365 M 644 inline file3/file5
1370 git fast-import <input &&
1371 git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1372 compare_diff_raw expect actual
1375 test_expect_success
'N: reject foo/ syntax' '
1376 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1377 test_must_fail git fast-import <<-INPUT_END
1378 commit refs/heads/N5B
1379 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1381 copy with invalid syntax
1384 from refs/heads/branch^0
1385 M 040000 $subdir file3/
1389 test_expect_success
'N: reject foo/ syntax in copy source' '
1390 test_must_fail git fast-import <<-INPUT_END
1391 commit refs/heads/N5C
1392 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1394 copy with invalid syntax
1397 from refs/heads/branch^0
1402 test_expect_success
'N: reject foo/ syntax in rename source' '
1403 test_must_fail git fast-import <<-INPUT_END
1404 commit refs/heads/N5D
1405 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1407 rename with invalid syntax
1410 from refs/heads/branch^0
1415 test_expect_success
'N: reject foo/ syntax in ls argument' '
1416 test_must_fail git fast-import <<-INPUT_END
1417 commit refs/heads/N5E
1418 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1420 copy with invalid syntax
1423 from refs/heads/branch^0
1428 test_expect_success
'N: copy to root by id and modify' '
1429 echo "hello, world" >expect.foo &&
1430 echo hello >expect.bar &&
1431 git fast-import <<-SETUP_END &&
1432 commit refs/heads/N7
1433 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1439 M 644 inline foo/bar
1445 tree=$(git rev-parse --verify N7:) &&
1446 git fast-import <<-INPUT_END &&
1447 commit refs/heads/N8
1448 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1450 copy to root by id and modify
1454 M 644 inline foo/foo
1459 git show N8:foo/foo >actual.foo &&
1460 git show N8:foo/bar >actual.bar &&
1461 test_cmp expect.foo actual.foo &&
1462 test_cmp expect.bar actual.bar
1465 test_expect_success
'N: extract subtree' '
1466 branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1467 cat >input <<-INPUT_END &&
1468 commit refs/heads/N9
1469 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1471 extract subtree branch:newdir
1477 git fast-import <input &&
1478 git diff --exit-code branch:newdir N9
1481 test_expect_success
'N: modify subtree, extract it, and modify again' '
1482 echo hello >expect.baz &&
1483 echo hello, world >expect.qux &&
1484 git fast-import <<-SETUP_END &&
1485 commit refs/heads/N10
1486 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1492 M 644 inline foo/bar/baz
1498 tree=$(git rev-parse --verify N10:) &&
1499 git fast-import <<-INPUT_END &&
1500 commit refs/heads/N11
1501 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1503 copy to root by id and modify
1507 M 100644 inline foo/bar/qux
1512 C "bar/qux" "bar/quux"
1514 git show N11:bar/baz >actual.baz &&
1515 git show N11:bar/qux >actual.qux &&
1516 git show N11:bar/quux >actual.quux &&
1517 test_cmp expect.baz actual.baz &&
1518 test_cmp expect.qux actual.qux &&
1519 test_cmp expect.qux actual.quux'
1525 test_expect_success
'O: comments are all skipped' '
1526 cat >input <<-INPUT_END &&
1528 commit refs/heads/O1
1529 # -- ignore all of this text
1530 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1531 # $GIT_COMMITTER_NAME has inserted here for his benefit.
1533 dirty directory copy
1536 # do not forget the import blank line!
1538 # yes, we started from our usual base of branch^0.
1540 from refs/heads/branch^0
1541 # and we need to reuse file2/file5 from N3 above.
1542 M 644 inline file2/file5
1543 # otherwise the tree will be different
1548 # do not forget to copy file2 to file3
1551 # or to delete file5 from file2.
1557 git fast-import <input &&
1558 test $(git rev-parse N3) = $(git rev-parse O1)
1561 test_expect_success
'O: blank lines not necessary after data commands' '
1562 cat >input <<-INPUT_END &&
1563 commit refs/heads/O2
1564 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1566 dirty directory copy
1568 from refs/heads/branch^0
1569 M 644 inline file2/file5
1578 git fast-import <input &&
1579 test $(git rev-parse N3) = $(git rev-parse O2)
1582 test_expect_success
'O: repack before next test' '
1586 test_expect_success
'O: blank lines not necessary after other commands' '
1587 cat >input <<-INPUT_END &&
1588 commit refs/heads/O3
1589 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1593 commit refs/heads/O3
1594 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1599 commit refs/heads/O3
1601 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1606 commit refs/heads/O3
1607 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1611 reset refs/tags/O3-2nd
1613 reset refs/tags/O3-3rd
1617 cat >expect <<-INPUT_END &&
1624 git fast-import <input &&
1625 test 8 = $(find .git/objects/pack -type f | grep -v multi-pack-index | wc -l) &&
1626 test $(git rev-parse refs/tags/O3-2nd) = $(git rev-parse O3^) &&
1627 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1628 test_cmp expect actual
1631 test_expect_success
'O: progress outputs as requested by input' '
1632 cat >input <<-INPUT_END &&
1633 commit refs/heads/O4
1634 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1638 commit refs/heads/O4
1639 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1643 progress Two commits down, 2 to go!
1644 commit refs/heads/O4
1645 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1649 progress Three commits down, 1 to go!
1650 commit refs/heads/O4
1651 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1657 git fast-import <input >actual &&
1658 grep "progress " <input >expect &&
1659 test_cmp expect actual
1663 ### series P (gitlinks)
1666 test_expect_success
'P: superproject & submodule mix' '
1667 cat >input <<-INPUT_END &&
1673 reset refs/heads/sub
1674 commit refs/heads/sub
1676 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1689 commit refs/heads/subuse1
1691 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1694 from refs/heads/master
1695 M 100644 :3 .gitmodules
1704 commit refs/heads/sub
1706 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1712 commit refs/heads/subuse1
1714 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1722 git fast-import <input &&
1723 git checkout subuse1 &&
1729 git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1732 git submodule init &&
1733 git submodule update
1736 test_expect_success
'P: verbatim SHA gitlinks' '
1737 SUBLAST=$(git rev-parse --verify sub) &&
1738 SUBPREV=$(git rev-parse --verify sub^) &&
1740 cat >input <<-INPUT_END &&
1749 commit refs/heads/subuse2
1751 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1754 from refs/heads/master
1755 M 100644 :1 .gitmodules
1756 M 160000 $SUBPREV sub
1758 commit refs/heads/subuse2
1760 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1764 M 160000 $SUBLAST sub
1768 git branch -D sub &&
1771 git fast-import <input &&
1772 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)
1775 test_expect_success
'P: fail on inline gitlink' '
1777 cat >input <<-INPUT_END &&
1778 commit refs/heads/subuse3
1780 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1785 from refs/heads/subuse2
1793 test_must_fail git fast-import <input
1796 test_expect_success
'P: fail on blob mark in gitlink' '
1798 cat >input <<-INPUT_END &&
1805 commit refs/heads/subuse3
1807 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1812 from refs/heads/subuse2
1817 test_must_fail git fast-import <input
1821 ### series Q (notes)
1824 test_expect_success
'Q: commit notes' '
1825 note1_data="The first note for the first commit" &&
1826 note2_data="The first note for the second commit" &&
1827 note3_data="The first note for the third commit" &&
1828 note1b_data="The second note for the first commit" &&
1829 note1c_data="The third note for the first commit" &&
1830 note2b_data="The second note for the second commit" &&
1833 cat >input <<-INPUT_END &&
1840 commit refs/heads/notes-test
1842 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1853 commit refs/heads/notes-test
1855 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1862 commit refs/heads/notes-test
1864 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1891 commit refs/notes/foobar
1893 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1905 commit refs/notes/foobar
1907 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1917 commit refs/notes/foobar2
1919 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1929 commit refs/notes/foobar
1931 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1944 git fast-import <input &&
1945 git whatchanged notes-test
1948 test_expect_success
'Q: verify pack' '
1952 test_expect_success
'Q: verify first commit' '
1953 commit1=$(git rev-parse notes-test~2) &&
1954 commit2=$(git rev-parse notes-test^) &&
1955 commit3=$(git rev-parse notes-test) &&
1957 cat >expect <<-EOF &&
1958 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1959 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1963 git cat-file commit notes-test~2 | sed 1d >actual &&
1964 test_cmp expect actual
1967 test_expect_success
'Q: verify second commit' '
1968 cat >expect <<-EOF &&
1970 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1971 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1975 git cat-file commit notes-test^ | sed 1d >actual &&
1976 test_cmp expect actual
1979 test_expect_success
'Q: verify third commit' '
1980 cat >expect <<-EOF &&
1982 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1983 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1987 git cat-file commit notes-test | sed 1d >actual &&
1988 test_cmp expect actual
1991 test_expect_success
'Q: verify first notes commit' '
1992 cat >expect <<-EOF &&
1993 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1994 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1998 git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1999 test_cmp expect actual
2002 test_expect_success
'Q: verify first notes tree' '
2003 cat >expect.unsorted <<-EOF &&
2004 100644 blob $commit1
2005 100644 blob $commit2
2006 100644 blob $commit3
2008 cat expect.unsorted | sort >expect &&
2009 git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2010 test_cmp expect actual
2013 test_expect_success
'Q: verify first note for first commit' '
2014 echo "$note1_data" >expect &&
2015 git cat-file blob refs/notes/foobar~2:$commit1 >actual &&
2016 test_cmp expect actual
2019 test_expect_success
'Q: verify first note for second commit' '
2020 echo "$note2_data" >expect &&
2021 git cat-file blob refs/notes/foobar~2:$commit2 >actual &&
2022 test_cmp expect actual
2025 test_expect_success
'Q: verify first note for third commit' '
2026 echo "$note3_data" >expect &&
2027 git cat-file blob refs/notes/foobar~2:$commit3 >actual &&
2028 test_cmp expect actual
2031 test_expect_success
'Q: verify second notes commit' '
2032 cat >expect <<-EOF &&
2033 parent $(git rev-parse --verify refs/notes/foobar~2)
2034 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2035 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2039 git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
2040 test_cmp expect actual
2043 test_expect_success
'Q: verify second notes tree' '
2044 cat >expect.unsorted <<-EOF &&
2045 100644 blob $commit1
2046 100644 blob $commit2
2047 100644 blob $commit3
2049 cat expect.unsorted | sort >expect &&
2050 git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2051 test_cmp expect actual
2054 test_expect_success
'Q: verify second note for first commit' '
2055 echo "$note1b_data" >expect &&
2056 git cat-file blob refs/notes/foobar^:$commit1 >actual &&
2057 test_cmp expect actual
2060 test_expect_success
'Q: verify first note for second commit' '
2061 echo "$note2_data" >expect &&
2062 git cat-file blob refs/notes/foobar^:$commit2 >actual &&
2063 test_cmp expect actual
2066 test_expect_success
'Q: verify first note for third commit' '
2067 echo "$note3_data" >expect &&
2068 git cat-file blob refs/notes/foobar^:$commit3 >actual &&
2069 test_cmp expect actual
2072 test_expect_success
'Q: verify third notes commit' '
2073 cat >expect <<-EOF &&
2074 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2075 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2079 git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
2080 test_cmp expect actual
2083 test_expect_success
'Q: verify third notes tree' '
2084 cat >expect.unsorted <<-EOF &&
2085 100644 blob $commit1
2087 cat expect.unsorted | sort >expect &&
2088 git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2089 test_cmp expect actual
2092 test_expect_success
'Q: verify third note for first commit' '
2093 echo "$note1c_data" >expect &&
2094 git cat-file blob refs/notes/foobar2:$commit1 >actual &&
2095 test_cmp expect actual
2098 test_expect_success
'Q: verify fourth notes commit' '
2099 cat >expect <<-EOF &&
2100 parent $(git rev-parse --verify refs/notes/foobar^)
2101 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2102 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2106 git cat-file commit refs/notes/foobar | sed 1d >actual &&
2107 test_cmp expect actual
2110 test_expect_success
'Q: verify fourth notes tree' '
2111 cat >expect.unsorted <<-EOF &&
2112 100644 blob $commit2
2114 cat expect.unsorted | sort >expect &&
2115 git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2116 test_cmp expect actual
2119 test_expect_success
'Q: verify second note for second commit' '
2120 echo "$note2b_data" >expect &&
2121 git cat-file blob refs/notes/foobar:$commit2 >actual &&
2122 test_cmp expect actual
2125 test_expect_success
'Q: deny note on empty branch' '
2126 cat >input <<-EOF &&
2129 commit refs/heads/note-Q0
2130 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2132 Note for an empty branch.
2135 N inline refs/heads/Q0
2140 test_must_fail git fast-import <input
2143 ### series R (feature and option)
2146 test_expect_success
'R: abort on unsupported feature' '
2147 cat >input <<-EOF &&
2148 feature no-such-feature-exists
2151 test_must_fail git fast-import <input
2154 test_expect_success
'R: supported feature is accepted' '
2155 cat >input <<-EOF &&
2156 feature date-format=now
2159 git fast-import <input
2162 test_expect_success
'R: abort on receiving feature after data command' '
2163 cat >input <<-EOF &&
2167 feature date-format=now
2170 test_must_fail git fast-import <input
2173 test_expect_success
'R: import-marks features forbidden by default' '
2175 echo "feature import-marks=git.marks" >input &&
2176 test_must_fail git fast-import <input &&
2177 echo "feature import-marks-if-exists=git.marks" >input &&
2178 test_must_fail git fast-import <input
2181 test_expect_success
'R: only one import-marks feature allowed per stream' '
2184 cat >input <<-EOF &&
2185 feature import-marks=git.marks
2186 feature import-marks=git2.marks
2189 test_must_fail git fast-import --allow-unsafe-features <input
2192 test_expect_success
'R: export-marks feature forbidden by default' '
2193 echo "feature export-marks=git.marks" >input &&
2194 test_must_fail git fast-import <input
2197 test_expect_success
'R: export-marks feature results in a marks file being created' '
2198 cat >input <<-EOF &&
2199 feature export-marks=git.marks
2207 git fast-import --allow-unsafe-features <input &&
2211 test_expect_success
'R: export-marks options can be overridden by commandline options' '
2212 cat >input <<-\EOF &&
2213 feature export-marks=feature-sub/git.marks
2220 git fast-import --allow-unsafe-features \
2221 --export-marks=cmdline-sub/other.marks <input &&
2222 grep :1 cmdline-sub/other.marks &&
2223 test_path_is_missing feature-sub
2226 test_expect_success
'R: catch typo in marks file name' '
2227 test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2228 echo "feature import-marks=nonexistent.marks" |
2229 test_must_fail git fast-import --allow-unsafe-features
2232 test_expect_success
'R: import and output marks can be the same file' '
2234 blob=$(echo hi | git hash-object --stdin) &&
2235 cat >expect <<-EOF &&
2239 git fast-import --export-marks=io.marks <<-\EOF &&
2246 git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2253 test_cmp expect io.marks
2256 test_expect_success
'R: --import-marks=foo --output-marks=foo to create foo fails' '
2258 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2267 test_expect_success
'R: --import-marks-if-exists' '
2269 blob=$(echo hi | git hash-object --stdin) &&
2270 echo ":1 $blob" >expect &&
2271 git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2278 test_cmp expect io.marks
2281 test_expect_success
'R: feature import-marks-if-exists' '
2284 git fast-import --export-marks=io.marks \
2285 --allow-unsafe-features <<-\EOF &&
2286 feature import-marks-if-exists=not_io.marks
2288 test_must_be_empty io.marks &&
2290 blob=$(echo hi | git hash-object --stdin) &&
2292 echo ":1 $blob" >io.marks &&
2293 echo ":1 $blob" >expect &&
2294 echo ":2 $blob" >>expect &&
2296 git fast-import --export-marks=io.marks \
2297 --allow-unsafe-features <<-\EOF &&
2298 feature import-marks-if-exists=io.marks
2305 test_cmp expect io.marks &&
2307 echo ":3 $blob" >>expect &&
2309 git fast-import --import-marks=io.marks \
2310 --export-marks=io.marks \
2311 --allow-unsafe-features <<-\EOF &&
2312 feature import-marks-if-exists=not_io.marks
2319 test_cmp expect io.marks &&
2321 git fast-import --import-marks-if-exists=not_io.marks \
2322 --export-marks=io.marks \
2323 --allow-unsafe-features <<-\EOF &&
2324 feature import-marks-if-exists=io.marks
2326 test_must_be_empty io.marks
2329 test_expect_success
'R: import to output marks works without any content' '
2330 cat >input <<-EOF &&
2331 feature import-marks=marks.out
2332 feature export-marks=marks.new
2335 git fast-import --allow-unsafe-features <input &&
2336 test_cmp marks.out marks.new
2339 test_expect_success
'R: import marks prefers commandline marks file over the stream' '
2340 cat >input <<-EOF &&
2341 feature import-marks=nonexistent.marks
2342 feature export-marks=marks.new
2345 git fast-import --import-marks=marks.out --allow-unsafe-features <input &&
2346 test_cmp marks.out marks.new
2350 test_expect_success
'R: multiple --import-marks= should be honoured' '
2351 cat >input <<-EOF &&
2352 feature import-marks=nonexistent.marks
2353 feature export-marks=combined.marks
2356 head -n2 marks.out > one.marks &&
2357 tail -n +3 marks.out > two.marks &&
2358 git fast-import --import-marks=one.marks --import-marks=two.marks \
2359 --allow-unsafe-features <input &&
2360 test_cmp marks.out combined.marks
2363 test_expect_success
'R: feature relative-marks should be honoured' '
2364 cat >input <<-EOF &&
2365 feature relative-marks
2366 feature import-marks=relative.in
2367 feature export-marks=relative.out
2370 mkdir -p .git/info/fast-import/ &&
2371 cp marks.new .git/info/fast-import/relative.in &&
2372 git fast-import --allow-unsafe-features <input &&
2373 test_cmp marks.new .git/info/fast-import/relative.out
2376 test_expect_success
'R: feature no-relative-marks should be honoured' '
2377 cat >input <<-EOF &&
2378 feature relative-marks
2379 feature import-marks=relative.in
2380 feature no-relative-marks
2381 feature export-marks=non-relative.out
2384 git fast-import --allow-unsafe-features <input &&
2385 test_cmp marks.new non-relative.out
2388 test_expect_success
'R: feature ls supported' '
2393 test_expect_success
'R: feature cat-blob supported' '
2394 echo "feature cat-blob" |
2398 test_expect_success
'R: cat-blob-fd must be a nonnegative integer' '
2399 test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2402 test_expect_success
!MINGW
'R: print old blob' '
2403 blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2404 cat >expect <<-EOF &&
2409 echo "cat-blob $blob" |
2410 git fast-import --cat-blob-fd=6 6>actual &&
2411 test_cmp expect actual
2414 test_expect_success
!MINGW
'R: in-stream cat-blob-fd not respected' '
2415 echo hello >greeting &&
2416 blob=$(git hash-object -w greeting) &&
2417 cat >expect <<-EOF &&
2422 git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2425 test_cmp expect actual.3 &&
2426 test_must_be_empty actual.1 &&
2427 git fast-import 3>actual.3 >actual.1 <<-EOF &&
2428 option cat-blob-fd=3
2431 test_must_be_empty actual.3 &&
2432 test_cmp expect actual.1
2435 test_expect_success
!MINGW
'R: print mark for new blob' '
2436 echo "effluentish" | git hash-object --stdin >expect &&
2437 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2445 test_cmp expect actual
2448 test_expect_success
!MINGW
'R: print new blob' '
2449 blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2450 cat >expect <<-EOF &&
2455 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2463 test_cmp expect actual
2466 test_expect_success
!MINGW
'R: print new blob by sha1' '
2467 blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2468 cat >expect <<-EOF &&
2470 a new blob named by sha1
2473 git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2476 a new blob named by sha1
2480 test_cmp expect actual
2483 test_expect_success
'setup: big file' '
2485 echo "the quick brown fox jumps over the lazy dog" >big &&
2488 cat big big big big >bigger &&
2489 cat bigger bigger bigger bigger >big ||
2495 test_expect_success
'R: print two blobs to stdout' '
2496 blob1=$(git hash-object big) &&
2497 blob1_len=$(wc -c <big) &&
2498 blob2=$(echo hello | git hash-object --stdin) &&
2500 echo ${blob1} blob $blob1_len &&
2510 cat <<-\END_PART1 &&
2527 git fast-import >actual &&
2528 test_cmp expect actual
2531 test_expect_success PIPE
'R: copy using cat-file' '
2532 expect_id=$(git hash-object big) &&
2533 expect_len=$(wc -c <big) &&
2534 echo $expect_id blob $expect_len >expect.response &&
2540 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2553 read blob_id type size <&3 &&
2554 echo "$blob_id $type $size" >response &&
2555 test_copy_bytes $size >blob <&3 &&
2559 commit refs/heads/copied
2560 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2562 copy big file as file3
2570 git fast-import --cat-blob-fd=3 3>blobs &&
2571 git show copied:file3 >actual &&
2572 test_cmp expect.response response &&
2576 test_expect_success PIPE
'R: print blob mid-commit' '
2578 echo "A blob from _before_ the commit." >expect &&
2587 A blob from _before_ the commit.
2589 commit refs/heads/temporary
2590 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2597 read blob_id type size <&3 &&
2598 test_copy_bytes $size >actual <&3 &&
2603 git fast-import --cat-blob-fd=3 3>blobs &&
2604 test_cmp expect actual
2607 test_expect_success PIPE
'R: print staged blob within commit' '
2609 echo "A blob from _within_ the commit." >expect &&
2615 commit refs/heads/within
2616 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2622 A blob from _within_ the commit.
2627 echo "A blob from _within_ the commit." |
2628 git hash-object --stdin
2630 echo "cat-blob $to_get" &&
2632 read blob_id type size <&3 &&
2633 test_copy_bytes $size >actual <&3 &&
2638 git fast-import --cat-blob-fd=3 3>blobs &&
2639 test_cmp expect actual
2642 test_expect_success
'R: quiet option results in no stats being output' '
2643 cat >input <<-EOF &&
2651 git fast-import 2>output <input &&
2652 test_must_be_empty output
2655 test_expect_success
'R: feature done means terminating "done" is mandatory' '
2656 echo feature done | test_must_fail git fast-import &&
2657 test_must_fail git fast-import --done </dev/null
2660 test_expect_success
'R: terminating "done" with trailing gibberish is ok' '
2661 git fast-import <<-\EOF &&
2666 git fast-import <<-\EOF
2668 more trailing gibberish
2672 test_expect_success
'R: terminating "done" within commit' '
2673 cat >expect <<-\EOF &&
2675 :000000 100644 OBJID OBJID A hello.c
2676 :000000 100644 OBJID OBJID A hello2.c
2678 git fast-import <<-EOF &&
2679 commit refs/heads/done-ends
2680 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2682 Commit terminated by "done" command
2684 M 100644 inline hello.c
2691 git rev-list done-ends |
2692 git diff-tree -r --stdin --root --always |
2693 sed -e "s/$OID_REGEX/OBJID/g" >actual &&
2694 test_cmp expect actual
2697 test_expect_success
'R: die on unknown option' '
2698 cat >input <<-EOF &&
2699 option git non-existing-option
2702 test_must_fail git fast-import <input
2705 test_expect_success
'R: unknown commandline options are rejected' '\
2706 test_must_fail git fast-import --non-existing-option < /dev/null
2709 test_expect_success
'R: die on invalid option argument' '
2710 echo "option git active-branches=-5" |
2711 test_must_fail git fast-import &&
2712 echo "option git depth=" |
2713 test_must_fail git fast-import &&
2714 test_must_fail git fast-import --depth="5 elephants" </dev/null
2717 test_expect_success
'R: ignore non-git options' '
2718 cat >input <<-EOF &&
2719 option non-existing-vcs non-existing-option
2722 git fast-import <input
2725 test_expect_success
'R: corrupt lines do not mess marks file' '
2727 blob=$(echo hi | git hash-object --stdin) &&
2728 cat >expect <<-EOF &&
2729 :3 0000000000000000000000000000000000000000
2733 cp expect io.marks &&
2734 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2737 test_cmp expect io.marks
2741 ## R: very large blobs
2743 test_expect_success
'R: blob bigger than threshold' '
2744 blobsize=$((2*1024*1024 + 53)) &&
2745 test-tool genrandom bar $blobsize >expect &&
2746 cat >input <<-INPUT_END &&
2747 commit refs/heads/big-file
2748 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2756 cat expect >>input &&
2757 cat >>input <<-INPUT_END &&
2761 cat expect >>input &&
2764 test_create_repo R &&
2765 git --git-dir=R/.git config fastimport.unpackLimit 0 &&
2766 git --git-dir=R/.git fast-import --big-file-threshold=1 <input
2769 test_expect_success
'R: verify created pack' '
2772 verify_packs -v > ../verify
2776 test_expect_success
'R: verify written objects' '
2777 git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2778 test_cmp_bin expect actual &&
2779 a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2780 b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2784 test_expect_success
'R: blob appears only once' '
2785 n=$(grep $a verify | wc -l) &&
2793 # Make sure missing spaces and EOLs after mark references
2802 # commit marks: 301, 302, 303, 304
2803 # blob marks: 403, 404, resp.
2806 # The error message when a space is missing not at the
2807 # end of the line is:
2809 # Missing space after ..
2811 # or when extra characters come after the mark at the end
2816 # or when the dataref is neither "inline " or a known SHA1,
2818 # Invalid dataref ..
2820 test_expect_success
'S: initialize for S tests' '
2823 cat >input <<-INPUT_END &&
2826 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2830 M 100644 inline hello.c
2837 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2842 M 100644 inline hello.c
2860 git fast-import --export-marks=marks <input
2864 # filemodify, three datarefs
2866 test_expect_success
'S: filemodify with garbage after mark must fail' '
2867 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2869 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2873 M 100644 :403x hello.c
2875 test_i18ngrep "space after mark" err
2878 # inline is misspelled; fast-import thinks it is some unknown dataref
2879 test_expect_success
'S: filemodify with garbage after inline must fail' '
2880 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2882 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2886 M 100644 inlineX hello.c
2891 test_i18ngrep "nvalid dataref" err
2894 test_expect_success
'S: filemodify with garbage after sha1 must fail' '
2895 sha1=$(grep :403 marks | cut -d\ -f2) &&
2896 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2898 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2902 M 100644 ${sha1}x hello.c
2904 test_i18ngrep "space after SHA1" err
2908 # notemodify, three ways to say dataref
2910 test_expect_success
'S: notemodify with garbage after mark dataref must fail' '
2911 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2913 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2915 commit S note dataref markref
2919 test_i18ngrep "space after mark" err
2922 test_expect_success
'S: notemodify with garbage after inline dataref must fail' '
2923 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2925 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2927 commit S note dataref inline
2934 test_i18ngrep "nvalid dataref" err
2937 test_expect_success
'S: notemodify with garbage after sha1 dataref must fail' '
2938 sha1=$(grep :202 marks | cut -d\ -f2) &&
2939 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2941 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2943 commit S note dataref sha1
2947 test_i18ngrep "space after SHA1" err
2951 # notemodify, mark in commit-ish
2953 test_expect_success
'S: notemodify with garbage after mark commit-ish must fail' '
2954 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2955 commit refs/heads/Snotes
2956 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2958 commit S note commit-ish
2962 test_i18ngrep "after mark" err
2968 test_expect_success
'S: from with garbage after mark must fail' '
2970 git fast-import --import-marks=marks --export-marks=marks <<-EOF 2>err &&
2971 commit refs/heads/S2
2973 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2978 M 100644 :403 hello.c
2982 # go create the commit, need it for merge test
2983 git fast-import --import-marks=marks --export-marks=marks <<-EOF &&
2984 commit refs/heads/S2
2986 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2991 M 100644 :403 hello.c
2994 # now evaluate the error
2995 test_i18ngrep "after mark" err
3002 test_expect_success
'S: merge with garbage after mark must fail' '
3003 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3006 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3012 M 100644 :403 hello.c
3014 test_i18ngrep "after mark" err
3020 test_expect_success
'S: tag with garbage after mark must fail' '
3021 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3024 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3029 test_i18ngrep "after mark" err
3035 test_expect_success
'S: cat-blob with garbage after mark must fail' '
3036 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3039 test_i18ngrep "after mark" err
3045 test_expect_success
'S: ls with garbage after mark must fail' '
3046 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3049 test_i18ngrep "space after mark" err
3052 test_expect_success
'S: ls with garbage after sha1 must fail' '
3053 sha1=$(grep :302 marks | cut -d\ -f2) &&
3054 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3057 test_i18ngrep "space after tree-ish" err
3063 # Setup is carried over from series S.
3065 test_expect_success
'T: ls root tree' '
3066 sed -e "s/Z\$//" >expect <<-EOF &&
3067 040000 tree $(git rev-parse S^{tree}) Z
3069 sha1=$(git rev-parse --verify S) &&
3070 git fast-import --import-marks=marks <<-EOF >actual &&
3073 test_cmp expect actual
3076 test_expect_success
'T: delete branch' '
3077 git branch to-delete &&
3078 git fast-import <<-EOF &&
3079 reset refs/heads/to-delete
3080 from 0000000000000000000000000000000000000000
3082 test_must_fail git rev-parse --verify refs/heads/to-delete
3085 test_expect_success
'T: empty reset doesnt delete branch' '
3086 git branch not-to-delete &&
3087 git fast-import <<-EOF &&
3088 reset refs/heads/not-to-delete
3091 git rev-parse --verify refs/heads/not-to-delete
3095 ### series U (filedelete)
3098 test_expect_success
'U: initialize for U tests' '
3099 cat >input <<-INPUT_END &&
3101 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3105 M 100644 inline hello.c
3109 M 100644 inline good/night.txt
3113 M 100644 inline good/bye.txt
3120 git fast-import <input
3123 test_expect_success
'U: filedelete file succeeds' '
3124 cat >input <<-INPUT_END &&
3126 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3128 delete good/night.txt
3135 git fast-import <input
3138 test_expect_success
'U: validate file delete result' '
3139 cat >expect <<-EOF &&
3140 :100644 000000 2907ebb4bf85d91bf0716bb3bd8a68ef48d6da76 0000000000000000000000000000000000000000 D good/night.txt
3143 git diff-tree -M -r U^1 U >actual &&
3145 compare_diff_raw expect actual
3148 test_expect_success
'U: filedelete directory succeeds' '
3149 cat >input <<-INPUT_END &&
3151 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3160 git fast-import <input
3163 test_expect_success
'U: validate directory delete result' '
3164 cat >expect <<-EOF &&
3165 :100644 000000 69cb75792f55123d8389c156b0b41c2ff00ed507 0000000000000000000000000000000000000000 D good/bye.txt
3168 git diff-tree -M -r U^1 U >actual &&
3170 compare_diff_raw expect actual
3173 test_expect_success
'U: filedelete root succeeds' '
3174 cat >input <<-INPUT_END &&
3176 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3185 git fast-import <input
3188 test_expect_success
'U: validate root delete result' '
3189 cat >expect <<-EOF &&
3190 :100644 000000 c18147dc648481eeb65dc5e66628429a64843327 0000000000000000000000000000000000000000 D hello.c
3193 git diff-tree -M -r U^1 U >actual &&
3195 compare_diff_raw expect actual
3199 ### series V (checkpoint)
3202 # The commands in input_file should not produce any output on the file
3203 # descriptor set with --cat-blob-fd (or stdout if unspecified).
3205 # To make sure you're observing the side effects of checkpoint *before*
3206 # fast-import terminates (and thus writes out its state), check that the
3207 # fast-import process is still running using background_import_still_running
3208 # *after* evaluating the test conditions.
3209 background_import_then_checkpoint
() {
3222 git fast-import
$options <&8 >&9 &
3225 echo >&2 "background fast-import terminated too early with exit code $?"
3226 # Un-block the read loop in the main shell process.
3231 # We don't mind if fast-import has already died by the time the test
3233 test_when_finished
"
3234 exec 8>&-; exec 9>&-;
3235 kill $sh_pid && wait $sh_pid
3236 kill $fi_pid && wait $fi_pid
3239 # Start in the background to ensure we adhere strictly to (blocking)
3240 # pipes writing sequence. We want to assume that the write below could
3241 # block, e.g. if fast-import blocks writing its own output to &9
3242 # because there is no reader on &9 yet.
3246 echo "progress checkpoint"
3249 error
=1 ;# assume the worst
3250 while read output
<&9
3252 if test "$output" = "progress checkpoint"
3256 elif test "$output" = "UNEXPECTED"
3260 # otherwise ignore cruft
3261 echo >&2 "cruft: $output"
3264 if test $error -eq 1
3270 background_import_still_running
() {
3271 if ! kill -0 "$fi_pid"
3273 echo >&2 "background fast-import terminated too early"
3278 test_expect_success PIPE
'V: checkpoint helper does not get stuck with extra output' '
3279 cat >input <<-INPUT_END &&
3285 background_import_then_checkpoint "" input &&
3286 background_import_still_running
3289 test_expect_success PIPE
'V: checkpoint updates refs after reset' '
3290 cat >input <<-\INPUT_END &&
3296 background_import_then_checkpoint "" input &&
3297 test "$(git rev-parse --verify V)" = "$(git rev-parse --verify U)" &&
3298 background_import_still_running
3301 test_expect_success PIPE
'V: checkpoint updates refs and marks after commit' '
3302 cat >input <<-INPUT_END &&
3305 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3311 background_import_then_checkpoint "--export-marks=marks.actual" input &&
3313 echo ":1 $(git rev-parse --verify V)" >marks.expected &&
3315 test "$(git rev-parse --verify V^)" = "$(git rev-parse --verify U)" &&
3316 test_cmp marks.expected marks.actual &&
3317 background_import_still_running
3320 # Re-create the exact same commit, but on a different branch: no new object is
3321 # created in the database, but the refs and marks still need to be updated.
3322 test_expect_success PIPE
'V: checkpoint updates refs and marks after commit (no new objects)' '
3323 cat >input <<-INPUT_END &&
3324 commit refs/heads/V2
3326 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3332 background_import_then_checkpoint "--export-marks=marks.actual" input &&
3334 echo ":2 $(git rev-parse --verify V2)" >marks.expected &&
3336 test "$(git rev-parse --verify V2)" = "$(git rev-parse --verify V)" &&
3337 test_cmp marks.expected marks.actual &&
3338 background_import_still_running
3341 test_expect_success PIPE
'V: checkpoint updates tags after tag' '
3342 cat >input <<-INPUT_END &&
3345 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3350 background_import_then_checkpoint "" input &&
3351 git show-ref -d Vtag &&
3352 background_import_still_running
3356 ### series W (get-mark and empty orphan commits)
3359 cat >>W-input
<<-W_INPUT_END
3360 commit refs/heads/W-branch
3362 author Full Name <user@company.tld> 1000000000 +0100
3363 committer Full Name <user@company.tld> 1000000000 +0100
3365 Intentionally empty commit
3369 test_expect_success
!MINGW
'W: get-mark & empty orphan commit with no newlines' '
3370 sed -e s/LFs// W-input | tr L "\n" | git fast-import
3373 test_expect_success
!MINGW
'W: get-mark & empty orphan commit with one newline' '
3374 sed -e s/LFs/L/ W-input | tr L "\n" | git fast-import
3377 test_expect_success
!MINGW
'W: get-mark & empty orphan commit with ugly second newline' '
3378 # Technically, this should fail as it has too many linefeeds
3379 # according to the grammar in fast-import.txt. But, for whatever
3380 # reason, it works. Since using the correct number of newlines
3381 # does not work with older (pre-2.22) versions of git, allow apps
3382 # that used this second-newline workaround to keep working by
3383 # checking it with this test...
3384 sed -e s/LFs/LL/ W-input | tr L "\n" | git fast-import
3387 test_expect_success
!MINGW
'W: get-mark & empty orphan commit with erroneous third newline' '
3388 # ...but do NOT allow more empty lines than that (see previous test).
3389 sed -e s/LFs/LLL/ W-input | tr L "\n" | test_must_fail git fast-import
3393 ### series X (other new features)
3396 test_expect_success
'X: handling encoding' '
3398 cat >input <<-INPUT_END &&
3399 commit refs/heads/encoding
3400 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3405 printf "Pi: \360\nCOMMIT\n" >>input &&
3407 git fast-import <input &&
3408 git cat-file -p encoding | grep $(printf "\360") &&
3409 git log -1 --format=%B encoding | grep $(printf "\317\200")
3413 ### series Y (submodules and hash algorithms)
3416 cat >Y-sub-input
<<\Y_INPUT_END
3422 reset refs
/heads
/master
3423 commit refs
/heads
/master
3425 author Full Name
<user@company.tld
> 1000000000 +0100
3426 committer Full Name
<user@company.tld
> 1000000000 +0100
3428 Test submodule commit
1
3437 commit refs
/heads
/master
3439 author Full Name
<user@company.tld
> 1000000001 +0100
3440 committer Full Name
<user@company.tld
> 1000000001 +0100
3442 Test submodule commit
2
3447 # Note that the submodule object IDs are intentionally not translated.
3448 cat >Y-main-input
<<\Y_INPUT_END
3454 reset refs
/heads
/master
3455 commit refs
/heads
/master
3457 author Full Name
<user@company.tld
> 2000000000 +0100
3458 committer Full Name
<user@company.tld
> 2000000000 +0100
3468 url
= https
://void.example.com
/main.git
3470 commit refs
/heads
/master
3472 author Full Name
<user@company.tld
> 2000000001 +0100
3473 committer Full Name
<user@company.tld
> 2000000001 +0100
3477 M
100644 :3 .gitmodules
3478 M
160000 0712c5be7cf681388e355ef47525aaf23aee1a6d sub1
3486 commit refs
/heads
/master
3488 author Full Name
<user@company.tld
> 2000000002 +0100
3489 committer Full Name
<user@company.tld
> 2000000002 +0100
3494 M
160000 ff729f5e62f72c0c3978207d9a80e5f3a65f14d7 sub1
3497 cat >Y-marks
<<\Y_INPUT_END
3498 :2 0712c5be7cf681388e355ef47525aaf23aee1a6d
3499 :4 ff729f5e62f72c0c3978207d9a80e5f3a65f14d7
3502 test_expect_success
'Y: setup' '
3503 test_oid_cache <<-EOF
3504 Ymaster sha1:9afed2f9161ddf416c0a1863b8b0725b00070504
3505 Ymaster sha256:c0a1010da1df187b2e287654793df01b464bd6f8e3f17fc1481a7dadf84caee3
3509 test_expect_success
'Y: rewrite submodules' '
3514 git -C sub2 fast-import --export-marks=../sub2-marks <../Y-sub-input &&
3515 git fast-import --rewrite-submodules-from=sub:../Y-marks \
3516 --rewrite-submodules-to=sub:sub2-marks <../Y-main-input &&
3517 test "$(git rev-parse master)" = "$(test_oid Ymaster)"