3 # Copyright (c) 2007 Shawn Pearce
6 test_description
='test git fast-import utility'
7 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
8 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 .
"$TEST_DIRECTORY"/lib-diff.sh
;# test-lib chdir's into trash
14 for p
in .git
/objects
/pack
/*.pack
16 git verify-pack
"$@" "$p" ||
return
30 file5_data
='an inline file.
31 we should see it later.'
40 test_expect_success
'empty stream succeeds' '
41 git config fastimport.unpackLimit 0 &&
42 git fast-import </dev/null
45 test_expect_success
'truncated stream complains' '
46 echo "tag foo" | test_must_fail git fast-import
49 test_expect_success
'A: create pack from stdin' '
51 cat >input <<-INPUT_END &&
68 commit refs/heads/main
70 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
82 An annotated tag without a tagger
88 An annotated tag that annotates a blob.
94 Another annotated tag that annotates a blob.
97 reset refs/tags/to-be-deleted
104 Tag of our lovely commit
107 reset refs/tags/nested
114 Tag of tag of our lovely commit
122 git fast-import --export-marks=marks.out <input &&
126 test_expect_success
'A: verify pack' '
130 test_expect_success
'A: verify commit' '
131 cat >expect <<-EOF &&
132 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
133 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
137 git cat-file commit main | sed 1d >actual &&
138 test_cmp expect actual
141 test_expect_success
'A: verify tree' '
142 cat >expect <<-EOF &&
147 git cat-file -p main^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
148 test_cmp expect actual
151 test_expect_success
'A: verify file2' '
152 echo "$file2_data" >expect &&
153 git cat-file blob main:file2 >actual &&
154 test_cmp expect actual
157 test_expect_success
'A: verify file3' '
158 echo "$file3_data" >expect &&
159 git cat-file blob main:file3 >actual &&
160 test_cmp expect actual
163 test_expect_success
'A: verify file4' '
164 printf "$file4_data" >expect &&
165 git cat-file blob main:file4 >actual &&
166 test_cmp expect actual
169 test_expect_success
'A: verify tag/series-A' '
170 cat >expect <<-EOF &&
171 object $(git rev-parse refs/heads/main)
175 An annotated tag without a tagger
177 git cat-file tag tags/series-A >actual &&
178 test_cmp expect actual
181 test_expect_success
'A: verify tag/series-A-blob' '
182 cat >expect <<-EOF &&
183 object $(git rev-parse refs/heads/main:file3)
187 An annotated tag that annotates a blob.
189 git cat-file tag tags/series-A-blob >actual &&
190 test_cmp expect actual
193 test_expect_success
'A: verify tag deletion is successful' '
194 test_must_fail git rev-parse --verify refs/tags/to-be-deleted
197 test_expect_success
'A: verify marks output' '
198 cat >expect <<-EOF &&
199 :2 $(git rev-parse --verify main:file2)
200 :3 $(git rev-parse --verify main:file3)
201 :4 $(git rev-parse --verify main:file4)
202 :5 $(git rev-parse --verify main^0)
203 :6 $(git cat-file tag nested | grep object | cut -d" " -f 2)
204 :7 $(git rev-parse --verify nested)
205 :8 $(git rev-parse --verify main^0)
207 test_cmp expect marks.out
210 test_expect_success
'A: verify marks import' '
212 --import-marks=marks.out \
213 --export-marks=marks.new \
215 test_cmp expect marks.new
218 test_expect_success
'A: tag blob by sha1' '
220 new_blob=$(echo testing | git hash-object --stdin) &&
221 cat >input <<-INPUT_END &&
223 from $(git rev-parse refs/heads/main:file3)
234 commit refs/heads/new_blob
238 #pretend we got sha1 from fast-import
248 cat >expect <<-EOF &&
249 object $(git rev-parse refs/heads/main:file3)
261 git fast-import <input &&
262 git cat-file tag tags/series-A-blob-2 >actual &&
263 git cat-file tag tags/series-A-blob-3 >>actual &&
264 test_cmp expect actual
267 test_expect_success
'A: verify marks import does not crash' '
269 cat >input <<-INPUT_END &&
270 commit refs/heads/verify--import-marks
271 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
277 M 755 :2 copy-of-file2
281 git fast-import --import-marks=marks.out <input &&
282 git whatchanged verify--import-marks
285 test_expect_success
'A: verify pack' '
289 test_expect_success
'A: verify diff' '
290 copy=$(git rev-parse --verify main:file2) &&
291 cat >expect <<-EOF &&
292 :000000 100755 $ZERO_OID $copy A copy-of-file2
294 git diff-tree -M -r main verify--import-marks >actual &&
295 compare_diff_raw expect actual &&
296 test $(git rev-parse --verify main:file2) \
297 = $(git rev-parse --verify verify--import-marks:copy-of-file2)
300 test_expect_success
'A: export marks with large values' '
302 mt=$(git hash-object --stdin < /dev/null) &&
307 cat >input.commit <<-EOF &&
308 commit refs/heads/verify--dump-marks
309 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
311 test the sparse array dumping routines with exponentially growing marks
316 while test "$i" -lt 27
318 cat >>input.blob <<-EOF &&
329 echo "M 100644 :$l l$i" >>input.commit &&
330 echo "M 100644 :$m m$i" >>input.commit &&
331 echo "M 100644 :$n n$i" >>input.commit &&
333 echo ":$l $mt" >>marks.exp &&
334 echo ":$m $mt" >>marks.exp &&
335 echo ":$n $mt" >>marks.exp &&
337 printf "100644 blob $mt\tl$i\n" >>tree.exp &&
338 printf "100644 blob $mt\tm$i\n" >>tree.exp &&
339 printf "100644 blob $mt\tn$i\n" >>tree.exp &&
345 i=$((1 + $i)) || return 1
348 sort tree.exp > tree.exp_s &&
350 cat input.blob input.commit | git fast-import --export-marks=marks.large &&
351 git ls-tree refs/heads/verify--dump-marks >tree.out &&
352 test_cmp tree.exp_s tree.out &&
353 test_cmp marks.exp marks.large
360 test_expect_success
'B: fail on invalid blob sha1' '
362 cat >input <<-INPUT_END &&
363 commit refs/heads/branch
365 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
371 M 755 $(echo $ZERO_OID | sed -e "s/0$/1/") zero1
375 test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" &&
376 test_must_fail git fast-import <input
379 test_expect_success
'B: accept branch name "TEMP_TAG"' '
380 cat >input <<-INPUT_END &&
382 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
391 test_when_finished "rm -f .git/TEMP_TAG && git gc --prune=now" &&
392 git fast-import <input &&
393 test $(test-tool ref-store main resolve-ref TEMP_TAG 0 | cut -f1 -d " " ) != "$ZERO_OID" &&
394 test $(git rev-parse main) = $(git rev-parse TEMP_TAG^)
397 test_expect_success
'B: accept empty committer' '
398 cat >input <<-INPUT_END &&
399 commit refs/heads/empty-committer-1
400 committer <> $GIT_COMMITTER_DATE
406 test_when_finished "git update-ref -d refs/heads/empty-committer-1
407 git gc --prune=now" &&
408 git fast-import <input &&
414 test_expect_success
'B: reject invalid timezone' '
415 cat >input <<-INPUT_END &&
416 commit refs/heads/invalid-timezone
417 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800
423 test_when_finished "git update-ref -d refs/heads/invalid-timezone" &&
424 test_must_fail git fast-import <input
427 test_expect_success
'B: accept invalid timezone with raw-permissive' '
428 cat >input <<-INPUT_END &&
429 commit refs/heads/invalid-timezone
430 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800
436 git init invalid-timezone &&
437 git -C invalid-timezone fast-import --date-format=raw-permissive <input &&
438 git -C invalid-timezone cat-file -p invalid-timezone >out &&
439 grep "1234567890 [+]051800" out
442 test_expect_success
'B: accept and fixup committer with no name' '
443 cat >input <<-INPUT_END &&
444 commit refs/heads/empty-committer-2
445 committer <a@b.com> $GIT_COMMITTER_DATE
451 test_when_finished "git update-ref -d refs/heads/empty-committer-2
452 git gc --prune=now" &&
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 main:file2) &&
531 thrf=$(git rev-parse --verify main:file3) &&
533 cat >input <<-INPUT_END &&
534 commit refs/heads/branch
535 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
541 M 644 $oldf file2/oldf
542 M 755 $newf file2/newf
547 git fast-import <input &&
548 git whatchanged branch
551 test_expect_success
'C: verify pack' '
555 test_expect_success
'C: validate reuse existing blob' '
556 test $newf = $(git rev-parse --verify branch:file2/newf) &&
557 test $oldf = $(git rev-parse --verify branch:file2/oldf)
560 test_expect_success
'C: verify commit' '
561 cat >expect <<-EOF &&
562 parent $(git rev-parse --verify main^0)
563 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
564 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
569 git cat-file commit branch | sed 1d >actual &&
570 test_cmp expect actual
573 test_expect_success
'C: validate rename result' '
575 cat >expect <<-EOF &&
576 :000000 100755 $zero $newf A file2/newf
577 :100644 100644 $oldf $oldf R100 file2 file2/oldf
578 :100644 000000 $thrf $zero D file3
580 git diff-tree -M -r main branch >actual &&
581 compare_diff_raw expect actual
588 test_expect_success
'D: inline data in commit' '
590 cat >input <<-INPUT_END &&
591 commit refs/heads/branch
592 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
597 from refs/heads/branch^0
598 M 644 inline newdir/interesting
603 M 755 inline newdir/exec.sh
610 git fast-import <input &&
611 git whatchanged branch
614 test_expect_success
'D: verify pack' '
618 test_expect_success
'D: validate new files added' '
619 f5id=$(echo "$file5_data" | git hash-object --stdin) &&
620 f6id=$(echo "$file6_data" | git hash-object --stdin) &&
621 cat >expect <<-EOF &&
622 :000000 100755 $ZERO_OID $f6id A newdir/exec.sh
623 :000000 100644 $ZERO_OID $f5id A newdir/interesting
625 git diff-tree -M -r branch^ branch >actual &&
626 compare_diff_raw expect actual
629 test_expect_success
'D: verify file5' '
630 echo "$file5_data" >expect &&
631 git cat-file blob branch:newdir/interesting >actual &&
632 test_cmp expect actual
635 test_expect_success
'D: verify file6' '
636 echo "$file6_data" >expect &&
637 git cat-file blob branch:newdir/exec.sh >actual &&
638 test_cmp expect actual
645 test_expect_success
'E: rfc2822 date, --date-format=raw' '
646 cat >input <<-INPUT_END &&
647 commit refs/heads/branch
648 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
649 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
654 from refs/heads/branch^0
658 test_must_fail git fast-import --date-format=raw <input
660 test_expect_success
'E: rfc2822 date, --date-format=rfc2822' '
661 git fast-import --date-format=rfc2822 <input
664 test_expect_success
'E: verify pack' '
668 test_expect_success
'E: verify commit' '
669 cat >expect <<-EOF &&
670 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
671 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
675 git cat-file commit branch | sed 1,2d >actual &&
676 test_cmp expect actual
683 test_expect_success
'F: non-fast-forward update skips' '
684 old_branch=$(git rev-parse --verify branch^0) &&
686 cat >input <<-INPUT_END &&
687 commit refs/heads/branch
688 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
690 losing things already?
693 from refs/heads/branch~1
695 reset refs/heads/other
696 from refs/heads/branch
700 test_must_fail git fast-import <input &&
701 # branch must remain unaffected
702 test $old_branch = $(git rev-parse --verify branch^0)
705 test_expect_success
'F: verify pack' '
709 test_expect_success
'F: verify other commit' '
710 cat >expect <<-EOF &&
711 tree $(git rev-parse branch~1^{tree})
712 parent $(git rev-parse branch~1)
713 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
714 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
716 losing things already?
718 git cat-file commit other >actual &&
719 test_cmp expect actual
726 test_expect_success
'G: non-fast-forward update forced' '
727 old_branch=$(git rev-parse --verify branch^0) &&
729 cat >input <<-INPUT_END &&
730 commit refs/heads/branch
731 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
733 losing things already?
736 from refs/heads/branch~1
739 git fast-import --force <input
742 test_expect_success
'G: verify pack' '
746 test_expect_success
'G: branch changed, but logged' '
747 test $old_branch != $(git rev-parse --verify branch^0) &&
748 test $old_branch = $(git rev-parse --verify branch@{1})
755 test_expect_success
'H: deletall, add 1' '
757 cat >input <<-INPUT_END &&
759 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
764 from refs/heads/branch^0
765 M 644 inline i-will-die
767 this file will never exist.
771 M 644 inline h/e/l/lo
777 git fast-import <input &&
781 test_expect_success
'H: verify pack' '
785 test_expect_success
'H: validate old files removed, new files added' '
786 f4id=$(git rev-parse HEAD:file4) &&
787 cat >expect <<-EOF &&
788 :100755 000000 $newf $zero D file2/newf
789 :100644 000000 $oldf $zero D file2/oldf
790 :100755 000000 $f4id $zero D file4
791 :100644 100644 $f5id $f5id R100 newdir/interesting h/e/l/lo
792 :100755 000000 $f6id $zero D newdir/exec.sh
794 git diff-tree -M -r H^ H >actual &&
795 compare_diff_raw expect actual
798 test_expect_success
'H: verify file' '
799 echo "$file5_data" >expect &&
800 git cat-file blob H:h/e/l/lo >actual &&
801 test_cmp expect actual
808 test_expect_success
'I: export-pack-edges' '
809 cat >input <<-INPUT_END &&
810 commit refs/heads/export-boundary
811 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
813 we have a border. its only 40 characters wide.
816 from refs/heads/branch
819 git fast-import --export-pack-edges=edges.list <input
822 test_expect_success
'I: verify edge list' '
823 cat >expect <<-EOF &&
824 .git/objects/pack/pack-.pack: $(git rev-parse --verify export-boundary)
826 sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
827 test_cmp expect actual
834 test_expect_success
'J: reset existing branch creates empty commit' '
835 cat >input <<-INPUT_END &&
837 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
842 from refs/heads/branch
847 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
853 git fast-import <input
855 test_expect_success
'J: branch has 1 commit, empty tree' '
856 test 1 = $(git rev-list J | wc -l) &&
857 test 0 = $(git ls-tree J | wc -l)
860 test_expect_success
'J: tag must fail on empty branch' '
861 cat >input <<-INPUT_END &&
867 Tag branch that was reset.
870 test_must_fail git fast-import <input
877 test_expect_success
'K: reinit branch with from' '
878 cat >input <<-INPUT_END &&
880 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
885 from refs/heads/branch
888 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
893 from refs/heads/branch^1
896 git fast-import <input
898 test_expect_success
'K: verify K^1 = branch^1' '
899 test $(git rev-parse --verify branch^1) \
900 = $(git rev-parse --verify K^1)
907 test_expect_success
'L: verify internal tree sorting' '
908 cat >input <<-INPUT_END &&
922 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
932 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
942 cat >expect <<-EXPECT_END &&
948 git fast-import <input &&
949 GIT_PRINT_SHA1_ELLIPSIS="yes" git diff-tree --abbrev --raw L^ L >output &&
950 cut -d" " -f1,2,5 output >actual &&
951 test_cmp expect actual
954 test_expect_success
'L: nested tree copy does not corrupt deltas' '
955 cat >input <<-INPUT_END &&
963 committer C O Mitter <committer@example.com> 1112912473 -0700
972 committer C O Mitter <committer@example.com> 1112912473 -0700
981 cat >expect <<-\EOF &&
986 test_when_finished "git update-ref -d refs/heads/L2" &&
987 git fast-import <input &&
988 git ls-tree L2 g/b/ >tmp &&
989 cat tmp | cut -f 2 >actual &&
990 test_cmp expect actual &&
991 git fsck $(git rev-parse L2)
998 test_expect_success
'M: rename file in same subdirectory' '
1000 cat >input <<-INPUT_END &&
1001 commit refs/heads/M1
1002 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1007 from refs/heads/branch^0
1008 R file2/newf file2/n.e.w.f
1012 cat >expect <<-EOF &&
1013 :100755 100755 $newf $newf R100 file2/newf file2/n.e.w.f
1015 git fast-import <input &&
1016 git diff-tree -M -r M1^ M1 >actual &&
1017 compare_diff_raw expect actual
1020 test_expect_success
'M: rename file to new subdirectory' '
1021 cat >input <<-INPUT_END &&
1022 commit refs/heads/M2
1023 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1028 from refs/heads/branch^0
1029 R file2/newf i/am/new/to/you
1033 cat >expect <<-EOF &&
1034 :100755 100755 $newf $newf R100 file2/newf i/am/new/to/you
1036 git fast-import <input &&
1037 git diff-tree -M -r M2^ M2 >actual &&
1038 compare_diff_raw expect actual
1041 test_expect_success
'M: rename subdirectory to new subdirectory' '
1042 cat >input <<-INPUT_END &&
1043 commit refs/heads/M3
1044 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1049 from refs/heads/M2^0
1054 cat >expect <<-EOF &&
1055 :100755 100755 $newf $newf R100 i/am/new/to/you other/sub/am/new/to/you
1057 git fast-import <input &&
1058 git diff-tree -M -r M3^ M3 >actual &&
1059 compare_diff_raw expect actual
1062 test_expect_success
'M: rename root to subdirectory' '
1063 cat >input <<-INPUT_END &&
1064 commit refs/heads/M4
1065 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1070 from refs/heads/M2^0
1075 cat >expect <<-EOF &&
1076 :100644 100644 $oldf $oldf R100 file2/oldf sub/file2/oldf
1077 :100755 100755 $f4id $f4id R100 file4 sub/file4
1078 :100755 100755 $newf $newf R100 i/am/new/to/you sub/i/am/new/to/you
1079 :100755 100755 $f6id $f6id R100 newdir/exec.sh sub/newdir/exec.sh
1080 :100644 100644 $f5id $f5id R100 newdir/interesting sub/newdir/interesting
1082 git fast-import <input &&
1083 git diff-tree -M -r M4^ M4 >actual &&
1084 compare_diff_raw expect actual
1091 test_expect_success
'N: copy file in same subdirectory' '
1093 cat >input <<-INPUT_END &&
1094 commit refs/heads/N1
1095 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1100 from refs/heads/branch^0
1101 C file2/newf file2/n.e.w.f
1105 cat >expect <<-EOF &&
1106 :100755 100755 $newf $newf C100 file2/newf file2/n.e.w.f
1108 git fast-import <input &&
1109 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1110 compare_diff_raw expect actual
1113 test_expect_success
'N: copy then modify subdirectory' '
1114 cat >input <<-INPUT_END &&
1115 commit refs/heads/N2
1116 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1118 clean directory copy
1121 from refs/heads/branch^0
1124 commit refs/heads/N2
1125 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1127 modify directory copy
1130 M 644 inline file3/file5
1137 cat >expect <<-EOF &&
1138 :100644 100644 $f5id $f5id C100 newdir/interesting file3/file5
1139 :100755 100755 $newf $newf C100 file2/newf file3/newf
1140 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
1142 git fast-import <input &&
1143 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1144 compare_diff_raw expect actual
1147 test_expect_success
'N: copy dirty subdirectory' '
1148 cat >input <<-INPUT_END &&
1149 commit refs/heads/N3
1150 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1152 dirty directory copy
1155 from refs/heads/branch^0
1156 M 644 inline file2/file5
1166 git fast-import <input &&
1167 test $(git rev-parse N2^{tree}) = $(git rev-parse N3^{tree})
1170 test_expect_success
'N: copy directory by id' '
1171 cat >expect <<-EOF &&
1172 :100755 100755 $newf $newf C100 file2/newf file3/newf
1173 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
1175 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1176 cat >input <<-INPUT_END &&
1177 commit refs/heads/N4
1178 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1183 from refs/heads/branch^0
1184 M 040000 $subdir file3
1186 git fast-import <input &&
1187 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1188 compare_diff_raw expect actual
1191 test_expect_success PIPE
'N: read and copy directory' '
1192 cat >expect <<-EOF &&
1193 :100755 100755 $newf $newf C100 file2/newf file3/newf
1194 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
1196 git update-ref -d refs/heads/N4 &&
1202 commit refs/heads/N4
1203 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1205 copy by tree hash, part 2
1208 from refs/heads/branch^0
1211 read mode type tree filename &&
1212 echo "M 040000 $tree file3"
1214 git fast-import --cat-blob-fd=3 3>backflow &&
1215 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1216 compare_diff_raw expect actual
1219 test_expect_success PIPE
'N: empty directory reads as missing' '
1220 cat <<-\EOF >expect &&
1222 :000000 100644 OBJNAME OBJNAME A unrelated
1224 echo "missing src" >expect.response &&
1225 git update-ref -d refs/heads/read-empty &&
1231 commit refs/heads/read-empty
1232 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1234 read "empty" (missing) directory
1237 M 100644 inline src/greeting
1241 C src/greeting dst1/non-greeting
1242 C src/greeting unrelated
1243 # leave behind "empty" src directory
1248 printf "%s\n" "$line" >response &&
1254 git fast-import --cat-blob-fd=3 3>backflow &&
1255 test_cmp expect.response response &&
1256 git rev-list read-empty |
1257 git diff-tree -r --root --stdin |
1258 sed "s/$OID_REGEX/OBJNAME/g" >actual &&
1259 test_cmp expect actual
1262 test_expect_success
'N: copy root directory by tree hash' '
1263 cat >expect <<-EOF &&
1264 :100755 000000 $newf $zero D file3/newf
1265 :100644 000000 $oldf $zero D file3/oldf
1267 root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1268 cat >input <<-INPUT_END &&
1269 commit refs/heads/N6
1270 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1272 copy root directory by tree hash
1275 from refs/heads/branch^0
1278 git fast-import <input &&
1279 git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1280 compare_diff_raw expect actual
1283 test_expect_success
'N: copy root by path' '
1284 cat >expect <<-EOF &&
1285 :100755 100755 $newf $newf C100 file2/newf oldroot/file2/newf
1286 :100644 100644 $oldf $oldf C100 file2/oldf oldroot/file2/oldf
1287 :100755 100755 $f4id $f4id C100 file4 oldroot/file4
1288 :100755 100755 $f6id $f6id C100 newdir/exec.sh oldroot/newdir/exec.sh
1289 :100644 100644 $f5id $f5id C100 newdir/interesting oldroot/newdir/interesting
1291 cat >input <<-INPUT_END &&
1292 commit refs/heads/N-copy-root-path
1293 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1295 copy root directory by (empty) path
1298 from refs/heads/branch^0
1301 git fast-import <input &&
1302 git diff-tree -C --find-copies-harder -r branch N-copy-root-path >actual &&
1303 compare_diff_raw expect actual
1306 test_expect_success
'N: delete directory by copying' '
1307 cat >expect <<-\EOF &&
1309 :100644 000000 OBJID OBJID D foo/bar/qux
1311 :000000 100644 OBJID OBJID A foo/bar/baz
1312 :000000 100644 OBJID OBJID A foo/bar/qux
1314 empty_tree=$(git mktree </dev/null) &&
1315 cat >input <<-INPUT_END &&
1316 commit refs/heads/N-delete
1317 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1319 collect data to be deleted
1323 M 100644 inline foo/bar/baz
1327 C "foo/bar/baz" "foo/bar/qux"
1328 C "foo/bar/baz" "foo/bar/quux/1"
1329 C "foo/bar/baz" "foo/bar/quuux"
1330 M 040000 $empty_tree foo/bar/quux
1331 M 040000 $empty_tree foo/bar/quuux
1333 commit refs/heads/N-delete
1334 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1339 M 040000 $empty_tree foo/bar/qux
1341 git fast-import <input &&
1342 git rev-list N-delete |
1343 git diff-tree -r --stdin --root --always |
1344 sed -e "s/$OID_REGEX/OBJID/g" >actual &&
1345 test_cmp expect actual
1348 test_expect_success
'N: modify copied tree' '
1349 cat >expect <<-EOF &&
1350 :100644 100644 $f5id $f5id C100 newdir/interesting file3/file5
1351 :100755 100755 $newf $newf C100 file2/newf file3/newf
1352 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
1354 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1355 cat >input <<-INPUT_END &&
1356 commit refs/heads/N5
1357 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1362 from refs/heads/branch^0
1363 M 040000 $subdir file3
1365 commit refs/heads/N5
1366 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1368 modify directory copy
1371 M 644 inline file3/file5
1376 git fast-import <input &&
1377 git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1378 compare_diff_raw expect actual
1381 test_expect_success
'N: reject foo/ syntax' '
1382 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1383 test_must_fail git fast-import <<-INPUT_END
1384 commit refs/heads/N5B
1385 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1387 copy with invalid syntax
1390 from refs/heads/branch^0
1391 M 040000 $subdir file3/
1395 test_expect_success
'N: reject foo/ syntax in copy source' '
1396 test_must_fail git fast-import <<-INPUT_END
1397 commit refs/heads/N5C
1398 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1400 copy with invalid syntax
1403 from refs/heads/branch^0
1408 test_expect_success
'N: reject foo/ syntax in rename source' '
1409 test_must_fail git fast-import <<-INPUT_END
1410 commit refs/heads/N5D
1411 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1413 rename with invalid syntax
1416 from refs/heads/branch^0
1421 test_expect_success
'N: reject foo/ syntax in ls argument' '
1422 test_must_fail git fast-import <<-INPUT_END
1423 commit refs/heads/N5E
1424 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1426 copy with invalid syntax
1429 from refs/heads/branch^0
1434 test_expect_success
'N: copy to root by id and modify' '
1435 echo "hello, world" >expect.foo &&
1436 echo hello >expect.bar &&
1437 git fast-import <<-SETUP_END &&
1438 commit refs/heads/N7
1439 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1445 M 644 inline foo/bar
1451 tree=$(git rev-parse --verify N7:) &&
1452 git fast-import <<-INPUT_END &&
1453 commit refs/heads/N8
1454 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1456 copy to root by id and modify
1460 M 644 inline foo/foo
1465 git show N8:foo/foo >actual.foo &&
1466 git show N8:foo/bar >actual.bar &&
1467 test_cmp expect.foo actual.foo &&
1468 test_cmp expect.bar actual.bar
1471 test_expect_success
'N: extract subtree' '
1472 branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1473 cat >input <<-INPUT_END &&
1474 commit refs/heads/N9
1475 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1477 extract subtree branch:newdir
1483 git fast-import <input &&
1484 git diff --exit-code branch:newdir N9
1487 test_expect_success
'N: modify subtree, extract it, and modify again' '
1488 echo hello >expect.baz &&
1489 echo hello, world >expect.qux &&
1490 git fast-import <<-SETUP_END &&
1491 commit refs/heads/N10
1492 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1498 M 644 inline foo/bar/baz
1504 tree=$(git rev-parse --verify N10:) &&
1505 git fast-import <<-INPUT_END &&
1506 commit refs/heads/N11
1507 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1509 copy to root by id and modify
1513 M 100644 inline foo/bar/qux
1518 C "bar/qux" "bar/quux"
1520 git show N11:bar/baz >actual.baz &&
1521 git show N11:bar/qux >actual.qux &&
1522 git show N11:bar/quux >actual.quux &&
1523 test_cmp expect.baz actual.baz &&
1524 test_cmp expect.qux actual.qux &&
1525 test_cmp expect.qux actual.quux'
1531 test_expect_success
'O: comments are all skipped' '
1532 cat >input <<-INPUT_END &&
1534 commit refs/heads/O1
1535 # -- ignore all of this text
1536 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1538 dirty directory copy
1541 # do not forget the import blank line!
1543 # yes, we started from our usual base of branch^0.
1545 from refs/heads/branch^0
1546 # and we need to reuse file2/file5 from N3 above.
1547 M 644 inline file2/file5
1548 # otherwise the tree will be different
1553 # do not forget to copy file2 to file3
1556 # or to delete file5 from file2.
1562 git fast-import <input &&
1563 test $(git rev-parse N3) = $(git rev-parse O1)
1566 test_expect_success
'O: blank lines not necessary after data commands' '
1567 cat >input <<-INPUT_END &&
1568 commit refs/heads/O2
1569 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1571 dirty directory copy
1573 from refs/heads/branch^0
1574 M 644 inline file2/file5
1583 git fast-import <input &&
1584 test $(git rev-parse N3) = $(git rev-parse O2)
1587 test_expect_success
'O: repack before next test' '
1591 test_expect_success
'O: blank lines not necessary after other commands' '
1592 cat >input <<-INPUT_END &&
1593 commit refs/heads/O3
1594 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1598 commit refs/heads/O3
1599 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1604 commit refs/heads/O3
1606 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1611 commit refs/heads/O3
1612 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1616 reset refs/tags/O3-2nd
1618 reset refs/tags/O3-3rd
1622 cat >expect <<-INPUT_END &&
1629 git fast-import <input &&
1630 ls -la .git/objects/pack/pack-*.pack >packlist &&
1631 ls -la .git/objects/pack/pack-*.pack >idxlist &&
1632 test_line_count = 4 idxlist &&
1633 test_line_count = 4 packlist &&
1634 test $(git rev-parse refs/tags/O3-2nd) = $(git rev-parse O3^) &&
1635 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1636 test_cmp expect actual
1639 test_expect_success
'O: progress outputs as requested by input' '
1640 cat >input <<-INPUT_END &&
1641 commit refs/heads/O4
1642 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1646 commit refs/heads/O4
1647 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1651 progress Two commits down, 2 to go!
1652 commit refs/heads/O4
1653 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1657 progress Three commits down, 1 to go!
1658 commit refs/heads/O4
1659 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1665 git fast-import <input >actual &&
1666 grep "progress " <input >expect &&
1667 test_cmp expect actual
1671 ### series P (gitlinks)
1674 test_expect_success
'P: superproject & submodule mix' '
1675 cat >input <<-INPUT_END &&
1681 reset refs/heads/sub
1682 commit refs/heads/sub
1684 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1697 commit refs/heads/subuse1
1699 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1702 from refs/heads/main
1703 M 100644 :3 .gitmodules
1712 commit refs/heads/sub
1714 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1720 commit refs/heads/subuse1
1722 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1730 git fast-import <input &&
1731 git checkout subuse1 &&
1737 git fetch --update-head-ok .. refs/heads/sub:refs/heads/main &&
1740 git submodule init &&
1741 git submodule update
1744 test_expect_success
'P: verbatim SHA gitlinks' '
1745 SUBLAST=$(git rev-parse --verify sub) &&
1746 SUBPREV=$(git rev-parse --verify sub^) &&
1748 cat >input <<-INPUT_END &&
1757 commit refs/heads/subuse2
1759 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1762 from refs/heads/main
1763 M 100644 :1 .gitmodules
1764 M 160000 $SUBPREV sub
1766 commit refs/heads/subuse2
1768 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1772 M 160000 $SUBLAST sub
1776 git branch -D sub &&
1777 git gc --prune=now &&
1778 git fast-import <input &&
1779 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)
1782 test_expect_success
'P: fail on inline gitlink' '
1784 cat >input <<-INPUT_END &&
1785 commit refs/heads/subuse3
1787 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1792 from refs/heads/subuse2
1800 test_must_fail git fast-import <input
1803 test_expect_success
'P: fail on blob mark in gitlink' '
1805 cat >input <<-INPUT_END &&
1812 commit refs/heads/subuse3
1814 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1819 from refs/heads/subuse2
1824 test_must_fail git fast-import <input
1828 ### series Q (notes)
1831 test_expect_success
'Q: commit notes' '
1832 note1_data="The first note for the first commit" &&
1833 note2_data="The first note for the second commit" &&
1834 note3_data="The first note for the third commit" &&
1835 note1b_data="The second note for the first commit" &&
1836 note1c_data="The third note for the first commit" &&
1837 note2b_data="The second note for the second commit" &&
1840 cat >input <<-INPUT_END &&
1847 commit refs/heads/notes-test
1849 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1860 commit refs/heads/notes-test
1862 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1869 commit refs/heads/notes-test
1871 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1898 commit refs/notes/foobar
1900 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1912 commit refs/notes/foobar
1914 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1924 commit refs/notes/foobar2
1926 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1936 commit refs/notes/foobar
1938 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1951 git fast-import <input &&
1952 git whatchanged notes-test
1955 test_expect_success
'Q: verify pack' '
1959 test_expect_success
'Q: verify first commit' '
1960 commit1=$(git rev-parse notes-test~2) &&
1961 commit2=$(git rev-parse notes-test^) &&
1962 commit3=$(git rev-parse notes-test) &&
1964 cat >expect <<-EOF &&
1965 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1966 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1970 git cat-file commit notes-test~2 | sed 1d >actual &&
1971 test_cmp expect actual
1974 test_expect_success
'Q: verify second commit' '
1975 cat >expect <<-EOF &&
1977 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1978 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1982 git cat-file commit notes-test^ | sed 1d >actual &&
1983 test_cmp expect actual
1986 test_expect_success
'Q: verify third commit' '
1987 cat >expect <<-EOF &&
1989 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1990 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1994 git cat-file commit notes-test | sed 1d >actual &&
1995 test_cmp expect actual
1998 test_expect_success
'Q: verify first notes commit' '
1999 cat >expect <<-EOF &&
2000 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2001 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2005 git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
2006 test_cmp expect actual
2009 test_expect_success
'Q: verify first notes tree' '
2010 cat >expect.unsorted <<-EOF &&
2011 100644 blob $commit1
2012 100644 blob $commit2
2013 100644 blob $commit3
2015 cat expect.unsorted | sort >expect &&
2016 git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2017 test_cmp expect actual
2020 test_expect_success
'Q: verify first note for first commit' '
2021 echo "$note1_data" >expect &&
2022 git cat-file blob refs/notes/foobar~2:$commit1 >actual &&
2023 test_cmp expect actual
2026 test_expect_success
'Q: verify first note for second commit' '
2027 echo "$note2_data" >expect &&
2028 git cat-file blob refs/notes/foobar~2:$commit2 >actual &&
2029 test_cmp expect actual
2032 test_expect_success
'Q: verify first note for third commit' '
2033 echo "$note3_data" >expect &&
2034 git cat-file blob refs/notes/foobar~2:$commit3 >actual &&
2035 test_cmp expect actual
2038 test_expect_success
'Q: verify second notes commit' '
2039 cat >expect <<-EOF &&
2040 parent $(git rev-parse --verify refs/notes/foobar~2)
2041 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2042 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2046 git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
2047 test_cmp expect actual
2050 test_expect_success
'Q: verify second notes tree' '
2051 cat >expect.unsorted <<-EOF &&
2052 100644 blob $commit1
2053 100644 blob $commit2
2054 100644 blob $commit3
2056 cat expect.unsorted | sort >expect &&
2057 git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2058 test_cmp expect actual
2061 test_expect_success
'Q: verify second note for first commit' '
2062 echo "$note1b_data" >expect &&
2063 git cat-file blob refs/notes/foobar^:$commit1 >actual &&
2064 test_cmp expect actual
2067 test_expect_success
'Q: verify first note for second commit' '
2068 echo "$note2_data" >expect &&
2069 git cat-file blob refs/notes/foobar^:$commit2 >actual &&
2070 test_cmp expect actual
2073 test_expect_success
'Q: verify first note for third commit' '
2074 echo "$note3_data" >expect &&
2075 git cat-file blob refs/notes/foobar^:$commit3 >actual &&
2076 test_cmp expect actual
2079 test_expect_success
'Q: verify third notes commit' '
2080 cat >expect <<-EOF &&
2081 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2082 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2086 git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
2087 test_cmp expect actual
2090 test_expect_success
'Q: verify third notes tree' '
2091 cat >expect.unsorted <<-EOF &&
2092 100644 blob $commit1
2094 cat expect.unsorted | sort >expect &&
2095 git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2096 test_cmp expect actual
2099 test_expect_success
'Q: verify third note for first commit' '
2100 echo "$note1c_data" >expect &&
2101 git cat-file blob refs/notes/foobar2:$commit1 >actual &&
2102 test_cmp expect actual
2105 test_expect_success
'Q: verify fourth notes commit' '
2106 cat >expect <<-EOF &&
2107 parent $(git rev-parse --verify refs/notes/foobar^)
2108 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2109 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2113 git cat-file commit refs/notes/foobar | sed 1d >actual &&
2114 test_cmp expect actual
2117 test_expect_success
'Q: verify fourth notes tree' '
2118 cat >expect.unsorted <<-EOF &&
2119 100644 blob $commit2
2121 cat expect.unsorted | sort >expect &&
2122 git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2123 test_cmp expect actual
2126 test_expect_success
'Q: verify second note for second commit' '
2127 echo "$note2b_data" >expect &&
2128 git cat-file blob refs/notes/foobar:$commit2 >actual &&
2129 test_cmp expect actual
2132 test_expect_success
'Q: deny note on empty branch' '
2133 cat >input <<-EOF &&
2136 commit refs/heads/note-Q0
2137 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2139 Note for an empty branch.
2142 N inline refs/heads/Q0
2147 test_must_fail git fast-import <input
2150 ### series R (feature and option)
2153 test_expect_success
'R: abort on unsupported feature' '
2154 cat >input <<-EOF &&
2155 feature no-such-feature-exists
2158 test_must_fail git fast-import <input
2161 test_expect_success
'R: supported feature is accepted' '
2162 cat >input <<-EOF &&
2163 feature date-format=now
2166 git fast-import <input
2169 test_expect_success
'R: abort on receiving feature after data command' '
2170 cat >input <<-EOF &&
2174 feature date-format=now
2177 test_must_fail git fast-import <input
2180 test_expect_success
'R: import-marks features forbidden by default' '
2182 echo "feature import-marks=git.marks" >input &&
2183 test_must_fail git fast-import <input &&
2184 echo "feature import-marks-if-exists=git.marks" >input &&
2185 test_must_fail git fast-import <input
2188 test_expect_success
'R: only one import-marks feature allowed per stream' '
2191 cat >input <<-EOF &&
2192 feature import-marks=git.marks
2193 feature import-marks=git2.marks
2196 test_must_fail git fast-import --allow-unsafe-features <input
2199 test_expect_success
'R: export-marks feature forbidden by default' '
2200 echo "feature export-marks=git.marks" >input &&
2201 test_must_fail git fast-import <input
2204 test_expect_success
'R: export-marks feature results in a marks file being created' '
2205 cat >input <<-EOF &&
2206 feature export-marks=git.marks
2214 git fast-import --allow-unsafe-features <input &&
2218 test_expect_success
'R: export-marks options can be overridden by commandline options' '
2219 cat >input <<-\EOF &&
2220 feature export-marks=feature-sub/git.marks
2227 git fast-import --allow-unsafe-features \
2228 --export-marks=cmdline-sub/other.marks <input &&
2229 grep :1 cmdline-sub/other.marks &&
2230 test_path_is_missing feature-sub
2233 test_expect_success
'R: catch typo in marks file name' '
2234 test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2235 echo "feature import-marks=nonexistent.marks" |
2236 test_must_fail git fast-import --allow-unsafe-features
2239 test_expect_success
'R: import and output marks can be the same file' '
2241 blob=$(echo hi | git hash-object --stdin) &&
2242 cat >expect <<-EOF &&
2246 git fast-import --export-marks=io.marks <<-\EOF &&
2253 git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2260 test_cmp expect io.marks
2263 test_expect_success
'R: --import-marks=foo --output-marks=foo to create foo fails' '
2265 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2274 test_expect_success
'R: --import-marks-if-exists' '
2276 blob=$(echo hi | git hash-object --stdin) &&
2277 echo ":1 $blob" >expect &&
2278 git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2285 test_cmp expect io.marks
2288 test_expect_success
'R: feature import-marks-if-exists' '
2291 git fast-import --export-marks=io.marks \
2292 --allow-unsafe-features <<-\EOF &&
2293 feature import-marks-if-exists=not_io.marks
2295 test_must_be_empty io.marks &&
2297 blob=$(echo hi | git hash-object --stdin) &&
2299 echo ":1 $blob" >io.marks &&
2300 echo ":1 $blob" >expect &&
2301 echo ":2 $blob" >>expect &&
2303 git fast-import --export-marks=io.marks \
2304 --allow-unsafe-features <<-\EOF &&
2305 feature import-marks-if-exists=io.marks
2312 test_cmp expect io.marks &&
2314 echo ":3 $blob" >>expect &&
2316 git fast-import --import-marks=io.marks \
2317 --export-marks=io.marks \
2318 --allow-unsafe-features <<-\EOF &&
2319 feature import-marks-if-exists=not_io.marks
2326 test_cmp expect io.marks &&
2328 git fast-import --import-marks-if-exists=not_io.marks \
2329 --export-marks=io.marks \
2330 --allow-unsafe-features <<-\EOF &&
2331 feature import-marks-if-exists=io.marks
2333 test_must_be_empty io.marks
2336 test_expect_success
'R: import to output marks works without any content' '
2337 cat >input <<-EOF &&
2338 feature import-marks=marks.out
2339 feature export-marks=marks.new
2342 git fast-import --allow-unsafe-features <input &&
2343 test_cmp marks.out marks.new
2346 test_expect_success
'R: import marks prefers commandline marks file over the stream' '
2347 cat >input <<-EOF &&
2348 feature import-marks=nonexistent.marks
2349 feature export-marks=marks.new
2352 git fast-import --import-marks=marks.out --allow-unsafe-features <input &&
2353 test_cmp marks.out marks.new
2357 test_expect_success
'R: multiple --import-marks= should be honoured' '
2358 cat >input <<-EOF &&
2359 feature import-marks=nonexistent.marks
2360 feature export-marks=combined.marks
2363 head -n2 marks.out > one.marks &&
2364 tail -n +3 marks.out > two.marks &&
2365 git fast-import --import-marks=one.marks --import-marks=two.marks \
2366 --allow-unsafe-features <input &&
2367 test_cmp marks.out combined.marks
2370 test_expect_success
'R: feature relative-marks should be honoured' '
2371 cat >input <<-EOF &&
2372 feature relative-marks
2373 feature import-marks=relative.in
2374 feature export-marks=relative.out
2377 mkdir -p .git/info/fast-import/ &&
2378 cp marks.new .git/info/fast-import/relative.in &&
2379 git fast-import --allow-unsafe-features <input &&
2380 test_cmp marks.new .git/info/fast-import/relative.out
2383 test_expect_success
'R: feature no-relative-marks should be honoured' '
2384 cat >input <<-EOF &&
2385 feature relative-marks
2386 feature import-marks=relative.in
2387 feature no-relative-marks
2388 feature export-marks=non-relative.out
2391 git fast-import --allow-unsafe-features <input &&
2392 test_cmp marks.new non-relative.out
2395 test_expect_success
'R: feature ls supported' '
2400 test_expect_success
'R: feature cat-blob supported' '
2401 echo "feature cat-blob" |
2405 test_expect_success
'R: cat-blob-fd must be a nonnegative integer' '
2406 test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2409 test_expect_success
!MINGW
'R: print old blob' '
2410 blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2411 cat >expect <<-EOF &&
2416 echo "cat-blob $blob" |
2417 git fast-import --cat-blob-fd=6 6>actual &&
2418 test_cmp expect actual
2421 test_expect_success
!MINGW
'R: in-stream cat-blob-fd not respected' '
2422 echo hello >greeting &&
2423 blob=$(git hash-object -w greeting) &&
2424 cat >expect <<-EOF &&
2429 git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2432 test_cmp expect actual.3 &&
2433 test_must_be_empty actual.1 &&
2434 git fast-import 3>actual.3 >actual.1 <<-EOF &&
2435 option cat-blob-fd=3
2438 test_must_be_empty actual.3 &&
2439 test_cmp expect actual.1
2442 test_expect_success
!MINGW
'R: print mark for new blob' '
2443 echo "effluentish" | git hash-object --stdin >expect &&
2444 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2452 test_cmp expect actual
2455 test_expect_success
!MINGW
'R: print new blob' '
2456 blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2457 cat >expect <<-EOF &&
2462 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2470 test_cmp expect actual
2473 test_expect_success
!MINGW
'R: print new blob by sha1' '
2474 blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2475 cat >expect <<-EOF &&
2477 a new blob named by sha1
2480 git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2483 a new blob named by sha1
2487 test_cmp expect actual
2490 test_expect_success
'setup: big file' '
2492 echo "the quick brown fox jumps over the lazy dog" >big &&
2495 cat big big big big >bigger &&
2496 cat bigger bigger bigger bigger >big ||
2502 test_expect_success
'R: print two blobs to stdout' '
2503 blob1=$(git hash-object big) &&
2504 blob1_len=$(wc -c <big) &&
2505 blob2=$(echo hello | git hash-object --stdin) &&
2507 echo ${blob1} blob $blob1_len &&
2517 cat <<-\END_PART1 &&
2534 git fast-import >actual &&
2535 test_cmp expect actual
2538 test_expect_success PIPE
'R: copy using cat-file' '
2539 expect_id=$(git hash-object big) &&
2540 expect_len=$(wc -c <big) &&
2541 echo $expect_id blob $expect_len >expect.response &&
2547 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2560 read blob_id type size <&3 &&
2561 echo "$blob_id $type $size" >response &&
2562 test_copy_bytes $size >blob <&3 &&
2566 commit refs/heads/copied
2567 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2569 copy big file as file3
2577 git fast-import --cat-blob-fd=3 3>blobs &&
2578 git show copied:file3 >actual &&
2579 test_cmp expect.response response &&
2583 test_expect_success PIPE
'R: print blob mid-commit' '
2585 echo "A blob from _before_ the commit." >expect &&
2594 A blob from _before_ the commit.
2596 commit refs/heads/temporary
2597 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2604 read blob_id type size <&3 &&
2605 test_copy_bytes $size >actual <&3 &&
2610 git fast-import --cat-blob-fd=3 3>blobs &&
2611 test_cmp expect actual
2614 test_expect_success PIPE
'R: print staged blob within commit' '
2616 echo "A blob from _within_ the commit." >expect &&
2622 commit refs/heads/within
2623 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2629 A blob from _within_ the commit.
2634 echo "A blob from _within_ the commit." |
2635 git hash-object --stdin
2637 echo "cat-blob $to_get" &&
2639 read blob_id type size <&3 &&
2640 test_copy_bytes $size >actual <&3 &&
2645 git fast-import --cat-blob-fd=3 3>blobs &&
2646 test_cmp expect actual
2649 test_expect_success
'R: quiet option results in no stats being output' '
2650 cat >input <<-EOF &&
2658 git fast-import 2>output <input &&
2659 test_must_be_empty output
2662 test_expect_success
'R: feature done means terminating "done" is mandatory' '
2663 echo feature done | test_must_fail git fast-import &&
2664 test_must_fail git fast-import --done </dev/null
2667 test_expect_success
'R: terminating "done" with trailing gibberish is ok' '
2668 git fast-import <<-\EOF &&
2673 git fast-import <<-\EOF
2675 more trailing gibberish
2679 test_expect_success
'R: terminating "done" within commit' '
2680 cat >expect <<-\EOF &&
2682 :000000 100644 OBJID OBJID A hello.c
2683 :000000 100644 OBJID OBJID A hello2.c
2685 git fast-import <<-EOF &&
2686 commit refs/heads/done-ends
2687 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2689 Commit terminated by "done" command
2691 M 100644 inline hello.c
2698 git rev-list done-ends |
2699 git diff-tree -r --stdin --root --always |
2700 sed -e "s/$OID_REGEX/OBJID/g" >actual &&
2701 test_cmp expect actual
2704 test_expect_success
'R: die on unknown option' '
2705 cat >input <<-EOF &&
2706 option git non-existing-option
2709 test_must_fail git fast-import <input
2712 test_expect_success
'R: unknown commandline options are rejected' '\
2713 test_must_fail git fast-import --non-existing-option < /dev/null
2716 test_expect_success
'R: die on invalid option argument' '
2717 echo "option git active-branches=-5" |
2718 test_must_fail git fast-import &&
2719 echo "option git depth=" |
2720 test_must_fail git fast-import &&
2721 test_must_fail git fast-import --depth="5 elephants" </dev/null
2724 test_expect_success
'R: ignore non-git options' '
2725 cat >input <<-EOF &&
2726 option non-existing-vcs non-existing-option
2729 git fast-import <input
2732 test_expect_success
'R: corrupt lines do not mess marks file' '
2734 blob=$(echo hi | git hash-object --stdin) &&
2735 cat >expect <<-EOF &&
2740 cp expect io.marks &&
2741 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2744 test_cmp expect io.marks
2748 ## R: very large blobs
2750 test_expect_success
'R: blob bigger than threshold' '
2751 blobsize=$((2*1024*1024 + 53)) &&
2752 test-tool genrandom bar $blobsize >expect &&
2753 cat >input <<-INPUT_END &&
2754 commit refs/heads/big-file
2755 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2763 cat expect >>input &&
2764 cat >>input <<-INPUT_END &&
2768 cat expect >>input &&
2771 test_create_repo R &&
2772 git --git-dir=R/.git config fastimport.unpackLimit 0 &&
2773 git --git-dir=R/.git fast-import --big-file-threshold=1 <input
2776 test_expect_success
'R: verify created pack' '
2779 verify_packs -v > ../verify
2783 test_expect_success
'R: verify written objects' '
2784 git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2785 test_cmp_bin expect actual &&
2786 a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2787 b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2791 test_expect_success
'R: blob appears only once' '
2792 n=$(grep $a verify | wc -l) &&
2800 # Make sure missing spaces and EOLs after mark references
2809 # commit marks: 301, 302, 303, 304
2810 # blob marks: 403, 404, resp.
2813 # The error message when a space is missing not at the
2814 # end of the line is:
2816 # Missing space after ..
2818 # or when extra characters come after the mark at the end
2823 # or when the dataref is neither "inline " or a known SHA1,
2825 # Invalid dataref ..
2827 test_expect_success
'S: initialize for S tests' '
2830 cat >input <<-INPUT_END &&
2833 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2837 M 100644 inline hello.c
2844 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2849 M 100644 inline hello.c
2867 git fast-import --export-marks=marks <input
2871 # filemodify, three datarefs
2873 test_expect_success
'S: filemodify with garbage after mark must fail' '
2874 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2876 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2880 M 100644 :403x hello.c
2882 test_grep "space after mark" err
2885 # inline is misspelled; fast-import thinks it is some unknown dataref
2886 test_expect_success
'S: filemodify with garbage after inline must fail' '
2887 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2889 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2893 M 100644 inlineX hello.c
2898 test_grep "nvalid dataref" err
2901 test_expect_success
'S: filemodify with garbage after sha1 must fail' '
2902 sha1=$(grep :403 marks | cut -d\ -f2) &&
2903 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2905 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2909 M 100644 ${sha1}x hello.c
2911 test_grep "space after SHA1" err
2915 # notemodify, three ways to say dataref
2917 test_expect_success
'S: notemodify with garbage after mark dataref must fail' '
2918 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2920 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2922 commit S note dataref markref
2926 test_grep "space after mark" err
2929 test_expect_success
'S: notemodify with garbage after inline dataref must fail' '
2930 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2932 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2934 commit S note dataref inline
2941 test_grep "nvalid dataref" err
2944 test_expect_success
'S: notemodify with garbage after sha1 dataref must fail' '
2945 sha1=$(grep :202 marks | cut -d\ -f2) &&
2946 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2948 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2950 commit S note dataref sha1
2954 test_grep "space after SHA1" err
2958 # notemodify, mark in commit-ish
2960 test_expect_success
'S: notemodify with garbage after mark commit-ish must fail' '
2961 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2962 commit refs/heads/Snotes
2963 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2965 commit S note commit-ish
2969 test_grep "after mark" err
2975 test_expect_success
'S: from with garbage after mark must fail' '
2977 git fast-import --import-marks=marks --export-marks=marks <<-EOF 2>err &&
2978 commit refs/heads/S2
2980 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2985 M 100644 :403 hello.c
2989 # go create the commit, need it for merge test
2990 git fast-import --import-marks=marks --export-marks=marks <<-EOF &&
2991 commit refs/heads/S2
2993 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2998 M 100644 :403 hello.c
3001 # now evaluate the error
3002 test_grep "after mark" err
3009 test_expect_success
'S: merge with garbage after mark must fail' '
3010 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3013 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3019 M 100644 :403 hello.c
3021 test_grep "after mark" err
3027 test_expect_success
'S: tag with garbage after mark must fail' '
3028 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3031 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3036 test_grep "after mark" err
3042 test_expect_success
'S: cat-blob with garbage after mark must fail' '
3043 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3046 test_grep "after mark" err
3052 test_expect_success
'S: ls with garbage after mark must fail' '
3053 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3056 test_grep "space after mark" err
3059 test_expect_success
'S: ls with garbage after sha1 must fail' '
3060 sha1=$(grep :302 marks | cut -d\ -f2) &&
3061 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3064 test_grep "space after tree-ish" err
3070 # Setup is carried over from series S.
3072 test_expect_success
'T: ls root tree' '
3073 sed -e "s/Z\$//" >expect <<-EOF &&
3074 040000 tree $(git rev-parse S^{tree}) Z
3076 sha1=$(git rev-parse --verify S) &&
3077 git fast-import --import-marks=marks <<-EOF >actual &&
3080 test_cmp expect actual
3083 test_expect_success
'T: delete branch' '
3084 git branch to-delete &&
3085 git fast-import <<-EOF &&
3086 reset refs/heads/to-delete
3089 test_must_fail git rev-parse --verify refs/heads/to-delete
3092 test_expect_success
'T: empty reset doesnt delete branch' '
3093 git branch not-to-delete &&
3094 git fast-import <<-EOF &&
3095 reset refs/heads/not-to-delete
3098 git rev-parse --verify refs/heads/not-to-delete
3102 ### series U (filedelete)
3105 test_expect_success
'U: initialize for U tests' '
3106 cat >input <<-INPUT_END &&
3108 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3112 M 100644 inline hello.c
3116 M 100644 inline good/night.txt
3120 M 100644 inline good/bye.txt
3127 f7id=$(echo "blob 1" | git hash-object --stdin) &&
3128 f8id=$(echo "sleep well" | git hash-object --stdin) &&
3129 f9id=$(echo "au revoir" | git hash-object --stdin) &&
3130 git fast-import <input
3133 test_expect_success
'U: filedelete file succeeds' '
3134 cat >input <<-INPUT_END &&
3136 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3138 delete good/night.txt
3145 git fast-import <input
3148 test_expect_success
'U: validate file delete result' '
3149 cat >expect <<-EOF &&
3150 :100644 000000 $f8id $ZERO_OID D good/night.txt
3153 git diff-tree -M -r U^1 U >actual &&
3155 compare_diff_raw expect actual
3158 test_expect_success
'U: filedelete directory succeeds' '
3159 cat >input <<-INPUT_END &&
3161 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3170 git fast-import <input
3173 test_expect_success
'U: validate directory delete result' '
3174 cat >expect <<-EOF &&
3175 :100644 000000 $f9id $ZERO_OID D good/bye.txt
3178 git diff-tree -M -r U^1 U >actual &&
3180 compare_diff_raw expect actual
3183 test_expect_success
'U: filedelete root succeeds' '
3184 cat >input <<-INPUT_END &&
3186 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3195 git fast-import <input
3198 test_expect_success
'U: validate root delete result' '
3199 cat >expect <<-EOF &&
3200 :100644 000000 $f7id $ZERO_OID D hello.c
3203 git diff-tree -M -r U^1 U >actual &&
3205 compare_diff_raw expect actual
3209 ### series V (checkpoint)
3212 # The commands in input_file should not produce any output on the file
3213 # descriptor set with --cat-blob-fd (or stdout if unspecified).
3215 # To make sure you're observing the side effects of checkpoint *before*
3216 # fast-import terminates (and thus writes out its state), check that the
3217 # fast-import process is still running using background_import_still_running
3218 # *after* evaluating the test conditions.
3219 background_import_then_checkpoint
() {
3232 git fast-import
$options <&8 >&9 &
3235 echo >&2 "background fast-import terminated too early with exit code $?"
3236 # Un-block the read loop in the main shell process.
3241 # We don't mind if fast-import has already died by the time the test
3243 test_when_finished
"
3244 exec 8>&-; exec 9>&-;
3245 kill $sh_pid && wait $sh_pid
3246 kill $fi_pid && wait $fi_pid
3249 # Start in the background to ensure we adhere strictly to (blocking)
3250 # pipes writing sequence. We want to assume that the write below could
3251 # block, e.g. if fast-import blocks writing its own output to &9
3252 # because there is no reader on &9 yet.
3256 echo "progress checkpoint"
3259 error
=1 ;# assume the worst
3260 while read output
<&9
3262 if test "$output" = "progress checkpoint"
3266 elif test "$output" = "UNEXPECTED"
3270 # otherwise ignore cruft
3271 echo >&2 "cruft: $output"
3274 if test $error -eq 1
3280 background_import_still_running
() {
3281 if ! kill -0 "$fi_pid"
3283 echo >&2 "background fast-import terminated too early"
3288 test_expect_success PIPE
'V: checkpoint helper does not get stuck with extra output' '
3289 cat >input <<-INPUT_END &&
3295 background_import_then_checkpoint "" input &&
3296 background_import_still_running
3299 test_expect_success PIPE
'V: checkpoint updates refs after reset' '
3300 cat >input <<-\INPUT_END &&
3306 background_import_then_checkpoint "" input &&
3307 test "$(git rev-parse --verify V)" = "$(git rev-parse --verify U)" &&
3308 background_import_still_running
3311 test_expect_success PIPE
'V: checkpoint updates refs and marks after commit' '
3312 cat >input <<-INPUT_END &&
3315 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3321 background_import_then_checkpoint "--export-marks=marks.actual" input &&
3323 echo ":1 $(git rev-parse --verify V)" >marks.expected &&
3325 test "$(git rev-parse --verify V^)" = "$(git rev-parse --verify U)" &&
3326 test_cmp marks.expected marks.actual &&
3327 background_import_still_running
3330 # Re-create the exact same commit, but on a different branch: no new object is
3331 # created in the database, but the refs and marks still need to be updated.
3332 test_expect_success PIPE
'V: checkpoint updates refs and marks after commit (no new objects)' '
3333 cat >input <<-INPUT_END &&
3334 commit refs/heads/V2
3336 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3342 background_import_then_checkpoint "--export-marks=marks.actual" input &&
3344 echo ":2 $(git rev-parse --verify V2)" >marks.expected &&
3346 test "$(git rev-parse --verify V2)" = "$(git rev-parse --verify V)" &&
3347 test_cmp marks.expected marks.actual &&
3348 background_import_still_running
3351 test_expect_success PIPE
'V: checkpoint updates tags after tag' '
3352 cat >input <<-INPUT_END &&
3355 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3360 background_import_then_checkpoint "" input &&
3361 git show-ref -d Vtag &&
3362 background_import_still_running
3366 ### series W (get-mark and empty orphan commits)
3369 cat >>W-input
<<-W_INPUT_END
3370 commit refs/heads/W-branch
3372 author Full Name <user@company.tld> 1000000000 +0100
3373 committer Full Name <user@company.tld> 1000000000 +0100
3375 Intentionally empty commit
3379 test_expect_success
!MINGW
'W: get-mark & empty orphan commit with no newlines' '
3380 sed -e s/LFs// W-input | tr L "\n" | git fast-import
3383 test_expect_success
!MINGW
'W: get-mark & empty orphan commit with one newline' '
3384 sed -e s/LFs/L/ W-input | tr L "\n" | git fast-import
3387 test_expect_success
!MINGW
'W: get-mark & empty orphan commit with ugly second newline' '
3388 # Technically, this should fail as it has too many linefeeds
3389 # according to the grammar in fast-import.txt. But, for whatever
3390 # reason, it works. Since using the correct number of newlines
3391 # does not work with older (pre-2.22) versions of git, allow apps
3392 # that used this second-newline workaround to keep working by
3393 # checking it with this test...
3394 sed -e s/LFs/LL/ W-input | tr L "\n" | git fast-import
3397 test_expect_success
!MINGW
'W: get-mark & empty orphan commit with erroneous third newline' '
3398 # ...but do NOT allow more empty lines than that (see previous test).
3399 sed -e s/LFs/LLL/ W-input | tr L "\n" | test_must_fail git fast-import
3403 ### series X (other new features)
3406 test_expect_success
'X: handling encoding' '
3408 cat >input <<-INPUT_END &&
3409 commit refs/heads/encoding
3410 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3415 printf "Pi: \360\nCOMMIT\n" >>input &&
3417 git fast-import <input &&
3418 git cat-file -p encoding | grep $(printf "\360") &&
3419 git log -1 --format=%B encoding | grep $(printf "\317\200")
3423 ### series Y (submodules and hash algorithms)
3426 cat >Y-sub-input
<<\Y_INPUT_END
3432 reset refs
/heads
/main
3433 commit refs
/heads
/main
3435 author Full Name
<user@company.tld
> 1000000000 +0100
3436 committer Full Name
<user@company.tld
> 1000000000 +0100
3438 Test submodule commit
1
3447 commit refs
/heads
/main
3449 author Full Name
<user@company.tld
> 1000000001 +0100
3450 committer Full Name
<user@company.tld
> 1000000001 +0100
3452 Test submodule commit
2
3457 # Note that the submodule object IDs are intentionally not translated.
3458 cat >Y-main-input
<<\Y_INPUT_END
3464 reset refs
/heads
/main
3465 commit refs
/heads
/main
3467 author Full Name
<user@company.tld
> 2000000000 +0100
3468 committer Full Name
<user@company.tld
> 2000000000 +0100
3478 url
= https
://void.example.com
/main.git
3480 commit refs
/heads
/main
3482 author Full Name
<user@company.tld
> 2000000001 +0100
3483 committer Full Name
<user@company.tld
> 2000000001 +0100
3487 M
100644 :3 .gitmodules
3488 M
160000 0712c5be7cf681388e355ef47525aaf23aee1a6d sub1
3496 commit refs
/heads
/main
3498 author Full Name
<user@company.tld
> 2000000002 +0100
3499 committer Full Name
<user@company.tld
> 2000000002 +0100
3504 M
160000 ff729f5e62f72c0c3978207d9a80e5f3a65f14d7 sub1
3507 cat >Y-marks
<<\Y_INPUT_END
3508 :2 0712c5be7cf681388e355ef47525aaf23aee1a6d
3509 :4 ff729f5e62f72c0c3978207d9a80e5f3a65f14d7
3512 test_expect_success
'Y: setup' '
3513 test_oid_cache <<-EOF
3514 Ymain sha1:9afed2f9161ddf416c0a1863b8b0725b00070504
3515 Ymain sha256:c0a1010da1df187b2e287654793df01b464bd6f8e3f17fc1481a7dadf84caee3
3519 test_expect_success
'Y: rewrite submodules' '
3524 git -C sub2 fast-import --export-marks=../sub2-marks <../Y-sub-input &&
3525 git fast-import --rewrite-submodules-from=sub:../Y-marks \
3526 --rewrite-submodules-to=sub:sub2-marks <../Y-main-input &&
3527 test "$(git rev-parse main)" = "$(test_oid Ymain)"