interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t9300-fast-import.sh

4038 lines · 92479 bytes Raw Blame History
1#!/bin/sh
2#
3# Copyright (c) 2007 Shawn Pearce
4#
5
6test_description='test git fast-import utility'
7GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
8export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
10. ./test-lib.sh
11. "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash
12
13verify_packs () {
14 for p in .git/objects/pack/*.pack
15 do
16 git verify-pack "$@" "$p" || return
17 done
18}
19
20file2_data='file2
21second line of EOF'
22
23file3_data='EOF
24in 3rd file
25 END'
26
27file4_data=abcd
28file4_len=4
29
30file5_data='an inline file.
31 we should see it later.'
32
33file6_data='#!/bin/sh
34echo "$@"'
35
36###
37### series A
38###
39
40test_expect_success 'empty stream succeeds' '
41 git config fastimport.unpackLimit 0 &&
42 git fast-import </dev/null
43'
44
45test_expect_success 'truncated stream complains' '
46 echo "tag foo" | test_must_fail git fast-import
47'
48
49test_expect_success 'A: create pack from stdin' '
50 test_tick &&
51 cat >input <<-INPUT_END &&
52 blob
53 mark :2
54 data <<EOF
55 $file2_data
56 EOF
57
58 blob
59 mark :3
60 data <<END
61 $file3_data
62 END
63
64 blob
65 mark :4
66 data $file4_len
67 $file4_data
68 commit refs/heads/main
69 mark :5
70 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
71 data <<COMMIT
72 initial
73 COMMIT
74
75 M 644 :2 file2
76 M 644 :3 file3
77 M 755 :4 file4
78
79 tag series-A
80 from :5
81 data <<EOF
82 An annotated tag without a tagger
83 EOF
84
85 tag series-A-blob
86 from :3
87 data <<EOF
88 An annotated tag that annotates a blob.
89 EOF
90
91 tag to-be-deleted
92 from :3
93 data <<EOF
94 Another annotated tag that annotates a blob.
95 EOF
96
97 reset refs/tags/to-be-deleted
98 from $ZERO_OID
99
100 tag nested
101 mark :6
102 from :4
103 data <<EOF
104 Tag of our lovely commit
105 EOF
106
107 reset refs/tags/nested
108 from $ZERO_OID
109
110 tag nested
111 mark :7
112 from :6
113 data <<EOF
114 Tag of tag of our lovely commit
115 EOF
116
117 alias
118 mark :8
119 to :5
120
121 INPUT_END
122 git fast-import --export-marks=marks.out <input &&
123 git log --raw main
124'
125
126test_expect_success 'A: verify pack' '
127 verify_packs
128'
129
130test_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
134
135 initial
136 EOF
137 git cat-file commit main | sed 1d >actual &&
138 test_cmp expect actual
139'
140
141test_expect_success 'A: verify tree' '
142 cat >expect <<-EOF &&
143 100644 blob file2
144 100644 blob file3
145 100755 blob file4
146 EOF
147 git cat-file -p main^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
148 test_cmp expect actual
149'
150
151test_expect_success 'A: verify file2' '
152 echo "$file2_data" >expect &&
153 git cat-file blob main:file2 >actual &&
154 test_cmp expect actual
155'
156
157test_expect_success 'A: verify file3' '
158 echo "$file3_data" >expect &&
159 git cat-file blob main:file3 >actual &&
160 test_cmp expect actual
161'
162
163test_expect_success 'A: verify file4' '
164 printf "$file4_data" >expect &&
165 git cat-file blob main:file4 >actual &&
166 test_cmp expect actual
167'
168
169test_expect_success 'A: verify tag/series-A' '
170 cat >expect <<-EOF &&
171 object $(git rev-parse refs/heads/main)
172 type commit
173 tag series-A
174
175 An annotated tag without a tagger
176 EOF
177 git cat-file tag tags/series-A >actual &&
178 test_cmp expect actual
179'
180
181test_expect_success 'A: verify tag/series-A-blob' '
182 cat >expect <<-EOF &&
183 object $(git rev-parse refs/heads/main:file3)
184 type blob
185 tag series-A-blob
186
187 An annotated tag that annotates a blob.
188 EOF
189 git cat-file tag tags/series-A-blob >actual &&
190 test_cmp expect actual
191'
192
193test_expect_success 'A: verify tag deletion is successful' '
194 test_must_fail git rev-parse --verify refs/tags/to-be-deleted
195'
196
197test_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)
206 EOF
207 test_cmp expect marks.out
208'
209
210test_expect_success 'A: verify marks import' '
211 git fast-import \
212 --import-marks=marks.out \
213 --export-marks=marks.new \
214 </dev/null &&
215 test_cmp expect marks.new
216'
217
218test_expect_success 'A: tag blob by sha1' '
219 test_tick &&
220 new_blob=$(echo testing | git hash-object --stdin) &&
221 cat >input <<-INPUT_END &&
222 tag series-A-blob-2
223 from $(git rev-parse refs/heads/main:file3)
224 data <<EOF
225 Tag blob by sha1.
226 EOF
227
228 blob
229 mark :6
230 data <<EOF
231 testing
232 EOF
233
234 commit refs/heads/new_blob
235 committer <> 0 +0000
236 data 0
237 M 644 :6 new_blob
238 #pretend we got sha1 from fast-import
239 ls "new_blob"
240
241 tag series-A-blob-3
242 from $new_blob
243 data <<EOF
244 Tag new_blob.
245 EOF
246 INPUT_END
247
248 cat >expect <<-EOF &&
249 object $(git rev-parse refs/heads/main:file3)
250 type blob
251 tag series-A-blob-2
252
253 Tag blob by sha1.
254 object $new_blob
255 type blob
256 tag series-A-blob-3
257
258 Tag new_blob.
259 EOF
260
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
265'
266
267test_expect_success 'A: verify marks import does not crash' '
268 test_tick &&
269 cat >input <<-INPUT_END &&
270 commit refs/heads/verify--import-marks
271 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
272 data <<COMMIT
273 recreate from :5
274 COMMIT
275
276 from :5
277 M 755 :2 copy-of-file2
278
279 INPUT_END
280
281 git fast-import --import-marks=marks.out <input &&
282 git log --raw verify--import-marks
283'
284
285test_expect_success 'A: verify pack' '
286 verify_packs
287'
288
289test_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
293 EOF
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)
298'
299
300test_expect_success 'A: export marks with large values' '
301 test_tick &&
302 mt=$(git hash-object --stdin < /dev/null) &&
303 >input.blob &&
304 >marks.exp &&
305 >tree.exp &&
306
307 cat >input.commit <<-EOF &&
308 commit refs/heads/verify--dump-marks
309 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
310 data <<COMMIT
311 test the sparse array dumping routines with exponentially growing marks
312 COMMIT
313 EOF
314
315 i=0 l=4 m=6 n=7 &&
316 while test "$i" -lt 27
317 do
318 cat >>input.blob <<-EOF &&
319 blob
320 mark :$l
321 data 0
322 blob
323 mark :$m
324 data 0
325 blob
326 mark :$n
327 data 0
328 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 &&
332
333 echo ":$l $mt" >>marks.exp &&
334 echo ":$m $mt" >>marks.exp &&
335 echo ":$n $mt" >>marks.exp &&
336
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 &&
340
341 l=$(($l + $l)) &&
342 m=$(($m + $m)) &&
343 n=$(($l + $n)) &&
344
345 i=$((1 + $i)) || return 1
346 done &&
347
348 sort tree.exp > tree.exp_s &&
349
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
354'
355
356###
357### series B
358###
359
360test_expect_success 'B: fail on invalid blob sha1' '
361 test_tick &&
362 cat >input <<-INPUT_END &&
363 commit refs/heads/branch
364 mark :1
365 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
366 data <<COMMIT
367 corrupt
368 COMMIT
369
370 from refs/heads/main
371 M 755 $(echo $ZERO_OID | sed -e "s/0$/1/") zero1
372
373 INPUT_END
374
375 test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" &&
376 test_must_fail git fast-import <input
377'
378
379test_expect_success 'B: accept branch name "TEMP_TAG"' '
380 cat >input <<-INPUT_END &&
381 commit TEMP_TAG
382 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
383 data <<COMMIT
384 tag base
385 COMMIT
386
387 from refs/heads/main
388
389 INPUT_END
390
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^)
395'
396
397test_expect_success 'B: accept empty committer' '
398 cat >input <<-INPUT_END &&
399 commit refs/heads/empty-committer-1
400 committer <> $GIT_COMMITTER_DATE
401 data <<COMMIT
402 empty commit
403 COMMIT
404 INPUT_END
405
406 test_when_finished "git update-ref -d refs/heads/empty-committer-1
407 git gc --prune=now" &&
408 git fast-import <input &&
409 out=$(git fsck) &&
410 echo "$out" &&
411 test -z "$out"
412'
413
414test_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
418 data <<COMMIT
419 empty commit
420 COMMIT
421 INPUT_END
422
423 test_when_finished "git update-ref -d refs/heads/invalid-timezone" &&
424 test_must_fail git fast-import <input
425'
426
427test_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
431 data <<COMMIT
432 empty commit
433 COMMIT
434 INPUT_END
435
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 test_grep "1234567890 [+]051800" out
440'
441
442test_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
446 data <<COMMIT
447 empty commit
448 COMMIT
449 INPUT_END
450
451 test_when_finished "git update-ref -d refs/heads/empty-committer-2
452 git gc --prune=now" &&
453 git fast-import <input &&
454 out=$(git fsck) &&
455 echo "$out" &&
456 test -z "$out"
457'
458
459test_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
463 data <<COMMIT
464 empty commit
465 COMMIT
466 INPUT_END
467
468 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
469 test_must_fail git fast-import <input
470'
471
472test_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
476 data <<COMMIT
477 empty commit
478 COMMIT
479 INPUT_END
480
481 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
482 test_must_fail git fast-import <input
483'
484
485test_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
489 data <<COMMIT
490 empty commit
491 COMMIT
492 INPUT_END
493
494 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
495 test_must_fail git fast-import <input
496'
497
498test_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
502 data <<COMMIT
503 empty commit
504 COMMIT
505 INPUT_END
506
507 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
508 test_must_fail git fast-import <input
509'
510
511test_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
515 data <<COMMIT
516 empty commit
517 COMMIT
518 INPUT_END
519
520 test_when_finished "git update-ref -d refs/heads/invalid-committer" &&
521 test_must_fail git fast-import <input
522'
523
524test_expect_success 'B: fail on invalid file path of ..' '
525 cat >input <<-INPUT_END &&
526 blob
527 mark :1
528 data <<EOF
529 File contents
530 EOF
531
532 commit refs/heads/badpath
533 committer Name <email> $GIT_COMMITTER_DATE
534 data <<COMMIT
535 Commit Message
536 COMMIT
537 M 100644 :1 ../invalid-path
538 INPUT_END
539
540 test_when_finished "git update-ref -d refs/heads/badpath" &&
541 test_must_fail git fast-import <input
542'
543
544test_expect_success 'B: fail on invalid file path of .' '
545 cat >input <<-INPUT_END &&
546 blob
547 mark :1
548 data <<EOF
549 File contents
550 EOF
551
552 commit refs/heads/badpath
553 committer Name <email> $GIT_COMMITTER_DATE
554 data <<COMMIT
555 Good path
556 COMMIT
557 M 100644 :1 ok-path
558
559 commit refs/heads/badpath
560 committer Name <email> $GIT_COMMITTER_DATE
561 data <<COMMIT
562 Bad path
563 COMMIT
564 R ok-path ./invalid-path
565 INPUT_END
566
567 test_when_finished "git update-ref -d refs/heads/badpath" &&
568 test_must_fail git fast-import <input
569'
570
571test_expect_success WINDOWS 'B: fail on invalid file path of C:' '
572 cat >input <<-INPUT_END &&
573 blob
574 mark :1
575 data <<EOF
576 File contents
577 EOF
578
579 commit refs/heads/badpath
580 committer Name <email> $GIT_COMMITTER_DATE
581 data <<COMMIT
582 Commit Message
583 COMMIT
584 M 100644 :1 C:/invalid-path
585 INPUT_END
586
587 test_when_finished "git update-ref -d refs/heads/badpath" &&
588 test_must_fail git fast-import <input
589'
590
591test_expect_success 'B: fail on invalid file path of .git' '
592 cat >input <<-INPUT_END &&
593 blob
594 mark :1
595 data <<EOF
596 File contents
597 EOF
598
599 commit refs/heads/badpath
600 committer Name <email> $GIT_COMMITTER_DATE
601 data <<COMMIT
602 Commit Message
603 COMMIT
604 M 100644 :1 .git/invalid-path
605 INPUT_END
606
607 test_when_finished "git update-ref -d refs/heads/badpath" &&
608 test_must_fail git fast-import <input
609'
610
611test_expect_success 'B: fail on invalid file path of .gitmodules' '
612 cat >input <<-INPUT_END &&
613 blob
614 mark :1
615 data <<EOF
616 File contents
617 EOF
618
619 commit refs/heads/badpath
620 committer Name <email> $GIT_COMMITTER_DATE
621 data <<COMMIT
622 Commit Message
623 COMMIT
624 M 120000 :1 .gitmodules
625 INPUT_END
626
627 test_when_finished "git update-ref -d refs/heads/badpath" &&
628 test_must_fail git fast-import <input
629'
630
631###
632### series C
633###
634
635test_expect_success 'C: incremental import create pack from stdin' '
636 newf=$(echo hi newf | git hash-object -w --stdin) &&
637 oldf=$(git rev-parse --verify main:file2) &&
638 thrf=$(git rev-parse --verify main:file3) &&
639 test_tick &&
640 cat >input <<-INPUT_END &&
641 commit refs/heads/branch
642 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
643 data <<COMMIT
644 second
645 COMMIT
646
647 from refs/heads/main
648 M 644 $oldf file2/oldf
649 M 755 $newf file2/newf
650 D file3
651
652 INPUT_END
653
654 git fast-import <input &&
655 git log --raw branch
656'
657
658test_expect_success 'C: verify pack' '
659 verify_packs
660'
661
662test_expect_success 'C: validate reuse existing blob' '
663 test $newf = $(git rev-parse --verify branch:file2/newf) &&
664 test $oldf = $(git rev-parse --verify branch:file2/oldf)
665'
666
667test_expect_success 'C: verify commit' '
668 cat >expect <<-EOF &&
669 parent $(git rev-parse --verify main^0)
670 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
671 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
672
673 second
674 EOF
675
676 git cat-file commit branch | sed 1d >actual &&
677 test_cmp expect actual
678'
679
680test_expect_success 'C: validate rename result' '
681 zero=$ZERO_OID &&
682 cat >expect <<-EOF &&
683 :000000 100755 $zero $newf A file2/newf
684 :100644 100644 $oldf $oldf R100 file2 file2/oldf
685 :100644 000000 $thrf $zero D file3
686 EOF
687 git diff-tree -M -r main branch >actual &&
688 compare_diff_raw expect actual
689'
690
691###
692### series D
693###
694
695test_expect_success 'D: inline data in commit' '
696 test_tick &&
697 cat >input <<-INPUT_END &&
698 commit refs/heads/branch
699 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
700 data <<COMMIT
701 third
702 COMMIT
703
704 from refs/heads/branch^0
705 M 644 inline newdir/interesting
706 data <<EOF
707 $file5_data
708 EOF
709
710 M 755 inline newdir/exec.sh
711 data <<EOF
712 $file6_data
713 EOF
714
715 INPUT_END
716
717 git fast-import <input &&
718 git log --raw branch
719'
720
721test_expect_success 'D: verify pack' '
722 verify_packs
723'
724
725test_expect_success 'D: validate new files added' '
726 f5id=$(echo "$file5_data" | git hash-object --stdin) &&
727 f6id=$(echo "$file6_data" | git hash-object --stdin) &&
728 cat >expect <<-EOF &&
729 :000000 100755 $ZERO_OID $f6id A newdir/exec.sh
730 :000000 100644 $ZERO_OID $f5id A newdir/interesting
731 EOF
732 git diff-tree -M -r branch^ branch >actual &&
733 compare_diff_raw expect actual
734'
735
736test_expect_success 'D: verify file5' '
737 echo "$file5_data" >expect &&
738 git cat-file blob branch:newdir/interesting >actual &&
739 test_cmp expect actual
740'
741
742test_expect_success 'D: verify file6' '
743 echo "$file6_data" >expect &&
744 git cat-file blob branch:newdir/exec.sh >actual &&
745 test_cmp expect actual
746'
747
748###
749### series E
750###
751
752test_expect_success 'E: rfc2822 date, --date-format=raw' '
753 cat >input <<-INPUT_END &&
754 commit refs/heads/branch
755 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
756 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
757 data <<COMMIT
758 RFC 2822 type date
759 COMMIT
760
761 from refs/heads/branch^0
762
763 INPUT_END
764
765 test_must_fail git fast-import --date-format=raw <input
766'
767test_expect_success 'E: rfc2822 date, --date-format=rfc2822' '
768 git fast-import --date-format=rfc2822 <input
769'
770
771test_expect_success 'E: verify pack' '
772 verify_packs
773'
774
775test_expect_success 'E: verify commit' '
776 cat >expect <<-EOF &&
777 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
778 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
779
780 RFC 2822 type date
781 EOF
782 git cat-file commit branch | sed 1,2d >actual &&
783 test_cmp expect actual
784'
785
786###
787### series F
788###
789
790test_expect_success 'F: non-fast-forward update skips' '
791 old_branch=$(git rev-parse --verify branch^0) &&
792 test_tick &&
793 cat >input <<-INPUT_END &&
794 commit refs/heads/branch
795 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
796 data <<COMMIT
797 losing things already?
798 COMMIT
799
800 from refs/heads/branch~1
801
802 reset refs/heads/other
803 from refs/heads/branch
804
805 INPUT_END
806
807 test_must_fail git fast-import <input &&
808 # branch must remain unaffected
809 test $old_branch = $(git rev-parse --verify branch^0)
810'
811
812test_expect_success 'F: verify pack' '
813 verify_packs
814'
815
816test_expect_success 'F: verify other commit' '
817 cat >expect <<-EOF &&
818 tree $(git rev-parse branch~1^{tree})
819 parent $(git rev-parse branch~1)
820 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
821 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
822
823 losing things already?
824 EOF
825 git cat-file commit other >actual &&
826 test_cmp expect actual
827'
828
829###
830### series G
831###
832
833test_expect_success 'G: non-fast-forward update forced' '
834 old_branch=$(git rev-parse --verify branch^0) &&
835 test_tick &&
836 cat >input <<-INPUT_END &&
837 commit refs/heads/branch
838 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
839 data <<COMMIT
840 losing things already?
841 COMMIT
842
843 from refs/heads/branch~1
844
845 INPUT_END
846 git fast-import --force <input
847'
848
849test_expect_success 'G: verify pack' '
850 verify_packs
851'
852
853test_expect_success 'G: branch changed, but logged' '
854 test $old_branch != $(git rev-parse --verify branch^0) &&
855 test $old_branch = $(git rev-parse --verify branch@{1})
856'
857
858###
859### series H
860###
861
862test_expect_success 'H: deletall, add 1' '
863 test_tick &&
864 cat >input <<-INPUT_END &&
865 commit refs/heads/H
866 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
867 data <<COMMIT
868 third
869 COMMIT
870
871 from refs/heads/branch^0
872 M 644 inline i-will-die
873 data <<EOF
874 this file will never exist.
875 EOF
876
877 deleteall
878 M 644 inline h/e/l/lo
879 data <<EOF
880 $file5_data
881 EOF
882
883 INPUT_END
884 git fast-import <input &&
885 git log --raw H
886'
887
888test_expect_success 'H: verify pack' '
889 verify_packs
890'
891
892test_expect_success 'H: validate old files removed, new files added' '
893 f4id=$(git rev-parse HEAD:file4) &&
894 cat >expect <<-EOF &&
895 :100755 000000 $newf $zero D file2/newf
896 :100644 000000 $oldf $zero D file2/oldf
897 :100755 000000 $f4id $zero D file4
898 :100644 100644 $f5id $f5id R100 newdir/interesting h/e/l/lo
899 :100755 000000 $f6id $zero D newdir/exec.sh
900 EOF
901 git diff-tree -M -r H^ H >actual &&
902 compare_diff_raw expect actual
903'
904
905test_expect_success 'H: verify file' '
906 echo "$file5_data" >expect &&
907 git cat-file blob H:h/e/l/lo >actual &&
908 test_cmp expect actual
909'
910
911###
912### series I
913###
914
915test_expect_success 'I: export-pack-edges option forbidden by default' '
916 echo "option git export-pack-edges=edges.list" >input &&
917 test_must_fail git fast-import <input 2>err &&
918 test_grep "option ${SQ}export-pack-edges${SQ} forbidden in input without --allow-unsafe-features" err
919'
920
921test_expect_success 'I: export-pack-edges' '
922 test_when_finished "rm edges.list" &&
923 cat >input <<-INPUT_END &&
924 commit refs/heads/export-boundary
925 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
926 data <<COMMIT
927 we have a border. its only 40 characters wide.
928 COMMIT
929
930 from refs/heads/branch
931
932 INPUT_END
933 git fast-import --export-pack-edges=edges.list <input &&
934 cat >expect <<-EOF &&
935 .git/objects/pack/pack-.pack: $(git rev-parse --verify export-boundary)
936 EOF
937 sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
938 test_cmp expect actual
939'
940
941test_expect_success 'I: export-pack-edges via stdin' '
942 test_when_finished "rm edges.list" &&
943 cat >input <<-INPUT_END &&
944 option git export-pack-edges=edges.list
945 commit refs/heads/export-boundary-2
946 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
947 data <<COMMIT
948 one more similar commit
949 COMMIT
950
951 from refs/heads/branch
952
953 INPUT_END
954 git fast-import --allow-unsafe-features <input &&
955 cat >expect <<-EOF &&
956 .git/objects/pack/pack-.pack: $(git rev-parse --verify export-boundary-2)
957 EOF
958 sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
959 test_cmp expect actual
960'
961
962###
963### series J
964###
965
966test_expect_success 'J: reset existing branch creates empty commit' '
967 cat >input <<-INPUT_END &&
968 commit refs/heads/J
969 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
970 data <<COMMIT
971 create J
972 COMMIT
973
974 from refs/heads/branch
975
976 reset refs/heads/J
977
978 commit refs/heads/J
979 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
980 data <<COMMIT
981 initialize J
982 COMMIT
983
984 INPUT_END
985 git fast-import <input
986'
987test_expect_success 'J: branch has 1 commit, empty tree' '
988 test 1 = $(git rev-list J | wc -l) &&
989 test 0 = $(git ls-tree J | wc -l)
990'
991
992test_expect_success 'J: tag must fail on empty branch' '
993 cat >input <<-INPUT_END &&
994 reset refs/heads/J2
995
996 tag wrong_tag
997 from refs/heads/J2
998 data <<EOF
999 Tag branch that was reset.
1000 EOF
1001 INPUT_END
1002 test_must_fail git fast-import <input
1003'
1004
1005###
1006### series K
1007###
1008
1009test_expect_success 'K: reinit branch with from' '
1010 cat >input <<-INPUT_END &&
1011 commit refs/heads/K
1012 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1013 data <<COMMIT
1014 create K
1015 COMMIT
1016
1017 from refs/heads/branch
1018
1019 commit refs/heads/K
1020 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1021 data <<COMMIT
1022 redo K
1023 COMMIT
1024
1025 from refs/heads/branch^1
1026
1027 INPUT_END
1028 git fast-import <input
1029'
1030test_expect_success 'K: verify K^1 = branch^1' '
1031 test $(git rev-parse --verify branch^1) \
1032 = $(git rev-parse --verify K^1)
1033'
1034
1035###
1036### series L
1037###
1038
1039test_expect_success 'L: verify internal tree sorting' '
1040 cat >input <<-INPUT_END &&
1041 blob
1042 mark :1
1043 data <<EOF
1044 some data
1045 EOF
1046
1047 blob
1048 mark :2
1049 data <<EOF
1050 other data
1051 EOF
1052
1053 commit refs/heads/L
1054 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1055 data <<COMMIT
1056 create L
1057 COMMIT
1058
1059 M 644 :1 b.
1060 M 644 :1 b/other
1061 M 644 :1 ba
1062
1063 commit refs/heads/L
1064 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1065 data <<COMMIT
1066 update L
1067 COMMIT
1068
1069 M 644 :2 b.
1070 M 644 :2 b/other
1071 M 644 :2 ba
1072 INPUT_END
1073
1074 cat >expect <<-EXPECT_END &&
1075 :100644 100644 M b.
1076 :040000 040000 M b
1077 :100644 100644 M ba
1078 EXPECT_END
1079
1080 git -c core.protectNTFS=false fast-import <input &&
1081 GIT_PRINT_SHA1_ELLIPSIS="yes" git diff-tree --abbrev --raw L^ L >output &&
1082 cut -d" " -f1,2,5 output >actual &&
1083 test_cmp expect actual
1084'
1085
1086test_expect_success 'L: nested tree copy does not corrupt deltas' '
1087 cat >input <<-INPUT_END &&
1088 blob
1089 mark :1
1090 data <<EOF
1091 the data
1092 EOF
1093
1094 commit refs/heads/L2
1095 committer C O Mitter <committer@example.com> 1112912473 -0700
1096 data <<COMMIT
1097 init L2
1098 COMMIT
1099 M 644 :1 a/b/c
1100 M 644 :1 a/b/d
1101 M 644 :1 a/e/f
1102
1103 commit refs/heads/L2
1104 committer C O Mitter <committer@example.com> 1112912473 -0700
1105 data <<COMMIT
1106 update L2
1107 COMMIT
1108 C a g
1109 C a/e g/b
1110 M 644 :1 g/b/h
1111 INPUT_END
1112
1113 cat >expect <<-\EOF &&
1114 g/b/f
1115 g/b/h
1116 EOF
1117
1118 test_when_finished "git update-ref -d refs/heads/L2" &&
1119 git fast-import <input &&
1120 git ls-tree L2 g/b/ >tmp &&
1121 cut -f 2 <tmp >actual &&
1122 test_cmp expect actual &&
1123 git fsck $(git rev-parse L2)
1124'
1125
1126###
1127### series M
1128###
1129
1130test_expect_success 'M: rename file in same subdirectory' '
1131 test_tick &&
1132 cat >input <<-INPUT_END &&
1133 commit refs/heads/M1
1134 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1135 data <<COMMIT
1136 file rename
1137 COMMIT
1138
1139 from refs/heads/branch^0
1140 R file2/newf file2/n.e.w.f
1141
1142 INPUT_END
1143
1144 cat >expect <<-EOF &&
1145 :100755 100755 $newf $newf R100 file2/newf file2/n.e.w.f
1146 EOF
1147 git fast-import <input &&
1148 git diff-tree -M -r M1^ M1 >actual &&
1149 compare_diff_raw expect actual
1150'
1151
1152test_expect_success 'M: rename file to new subdirectory' '
1153 cat >input <<-INPUT_END &&
1154 commit refs/heads/M2
1155 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1156 data <<COMMIT
1157 file rename
1158 COMMIT
1159
1160 from refs/heads/branch^0
1161 R file2/newf i/am/new/to/you
1162
1163 INPUT_END
1164
1165 cat >expect <<-EOF &&
1166 :100755 100755 $newf $newf R100 file2/newf i/am/new/to/you
1167 EOF
1168 git fast-import <input &&
1169 git diff-tree -M -r M2^ M2 >actual &&
1170 compare_diff_raw expect actual
1171'
1172
1173test_expect_success 'M: rename subdirectory to new subdirectory' '
1174 cat >input <<-INPUT_END &&
1175 commit refs/heads/M3
1176 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1177 data <<COMMIT
1178 file rename
1179 COMMIT
1180
1181 from refs/heads/M2^0
1182 R i other/sub
1183
1184 INPUT_END
1185
1186 cat >expect <<-EOF &&
1187 :100755 100755 $newf $newf R100 i/am/new/to/you other/sub/am/new/to/you
1188 EOF
1189 git fast-import <input &&
1190 git diff-tree -M -r M3^ M3 >actual &&
1191 compare_diff_raw expect actual
1192'
1193
1194for root in '""' ''
1195do
1196 test_expect_success "M: rename root ($root) to subdirectory" '
1197 cat >input <<-INPUT_END &&
1198 commit refs/heads/M4
1199 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1200 data <<COMMIT
1201 rename root
1202 COMMIT
1203
1204 from refs/heads/M2^0
1205 R $root sub
1206
1207 INPUT_END
1208
1209 cat >expect <<-EOF &&
1210 :100644 100644 $oldf $oldf R100 file2/oldf sub/file2/oldf
1211 :100755 100755 $f4id $f4id R100 file4 sub/file4
1212 :100755 100755 $newf $newf R100 i/am/new/to/you sub/i/am/new/to/you
1213 :100755 100755 $f6id $f6id R100 newdir/exec.sh sub/newdir/exec.sh
1214 :100644 100644 $f5id $f5id R100 newdir/interesting sub/newdir/interesting
1215 EOF
1216 git fast-import <input &&
1217 git diff-tree -M -r M4^ M4 >actual &&
1218 compare_diff_raw expect actual
1219 '
1220done
1221
1222###
1223### series N
1224###
1225
1226test_expect_success 'N: copy file in same subdirectory' '
1227 test_tick &&
1228 cat >input <<-INPUT_END &&
1229 commit refs/heads/N1
1230 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1231 data <<COMMIT
1232 file copy
1233 COMMIT
1234
1235 from refs/heads/branch^0
1236 C file2/newf file2/n.e.w.f
1237
1238 INPUT_END
1239
1240 cat >expect <<-EOF &&
1241 :100755 100755 $newf $newf C100 file2/newf file2/n.e.w.f
1242 EOF
1243 git fast-import <input &&
1244 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1245 compare_diff_raw expect actual
1246'
1247
1248test_expect_success 'N: copy then modify subdirectory' '
1249 cat >input <<-INPUT_END &&
1250 commit refs/heads/N2
1251 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1252 data <<COMMIT
1253 clean directory copy
1254 COMMIT
1255
1256 from refs/heads/branch^0
1257 C file2 file3
1258
1259 commit refs/heads/N2
1260 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1261 data <<COMMIT
1262 modify directory copy
1263 COMMIT
1264
1265 M 644 inline file3/file5
1266 data <<EOF
1267 $file5_data
1268 EOF
1269
1270 INPUT_END
1271
1272 cat >expect <<-EOF &&
1273 :100644 100644 $f5id $f5id C100 newdir/interesting file3/file5
1274 :100755 100755 $newf $newf C100 file2/newf file3/newf
1275 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
1276 EOF
1277 git fast-import <input &&
1278 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1279 compare_diff_raw expect actual
1280'
1281
1282test_expect_success 'N: copy dirty subdirectory' '
1283 cat >input <<-INPUT_END &&
1284 commit refs/heads/N3
1285 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1286 data <<COMMIT
1287 dirty directory copy
1288 COMMIT
1289
1290 from refs/heads/branch^0
1291 M 644 inline file2/file5
1292 data <<EOF
1293 $file5_data
1294 EOF
1295
1296 C file2 file3
1297 D file2/file5
1298
1299 INPUT_END
1300
1301 git fast-import <input &&
1302 test $(git rev-parse N2^{tree}) = $(git rev-parse N3^{tree})
1303'
1304
1305test_expect_success 'N: copy directory by id' '
1306 cat >expect <<-EOF &&
1307 :100755 100755 $newf $newf C100 file2/newf file3/newf
1308 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
1309 EOF
1310 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1311 cat >input <<-INPUT_END &&
1312 commit refs/heads/N4
1313 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1314 data <<COMMIT
1315 copy by tree hash
1316 COMMIT
1317
1318 from refs/heads/branch^0
1319 M 040000 $subdir file3
1320 INPUT_END
1321 git fast-import <input &&
1322 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1323 compare_diff_raw expect actual
1324'
1325
1326test_expect_success PIPE 'N: read and copy directory' '
1327 cat >expect <<-EOF &&
1328 :100755 100755 $newf $newf C100 file2/newf file3/newf
1329 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
1330 EOF
1331 git update-ref -d refs/heads/N4 &&
1332 rm -f backflow &&
1333 mkfifo backflow &&
1334 (
1335 exec <backflow &&
1336 cat <<-EOF &&
1337 commit refs/heads/N4
1338 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1339 data <<COMMIT
1340 copy by tree hash, part 2
1341 COMMIT
1342
1343 from refs/heads/branch^0
1344 ls "file2"
1345 EOF
1346 read mode type tree filename &&
1347 echo "M 040000 $tree file3"
1348 ) |
1349 git fast-import --cat-blob-fd=3 3>backflow &&
1350 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1351 compare_diff_raw expect actual
1352'
1353
1354test_expect_success PIPE 'N: empty directory reads as missing' '
1355 cat <<-\EOF >expect &&
1356 OBJNAME
1357 :000000 100644 OBJNAME OBJNAME A unrelated
1358 EOF
1359 echo "missing src" >expect.response &&
1360 git update-ref -d refs/heads/read-empty &&
1361 rm -f backflow &&
1362 mkfifo backflow &&
1363 (
1364 exec <backflow &&
1365 cat <<-EOF &&
1366 commit refs/heads/read-empty
1367 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1368 data <<COMMIT
1369 read "empty" (missing) directory
1370 COMMIT
1371
1372 M 100644 inline src/greeting
1373 data <<BLOB
1374 hello
1375 BLOB
1376 C src/greeting dst1/non-greeting
1377 C src/greeting unrelated
1378 # leave behind "empty" src directory
1379 D src/greeting
1380 ls "src"
1381 EOF
1382 read -r line &&
1383 printf "%s\n" "$line" >response &&
1384 cat <<-\EOF
1385 D dst1
1386 D dst2
1387 EOF
1388 ) |
1389 git fast-import --cat-blob-fd=3 3>backflow &&
1390 test_cmp expect.response response &&
1391 git rev-list read-empty |
1392 git diff-tree -r --root --stdin |
1393 sed "s/$OID_REGEX/OBJNAME/g" >actual &&
1394 test_cmp expect actual
1395'
1396
1397for root in '""' ''
1398do
1399 test_expect_success "N: copy root ($root) by tree hash" '
1400 cat >expect <<-EOF &&
1401 :100755 000000 $newf $zero D file3/newf
1402 :100644 000000 $oldf $zero D file3/oldf
1403 EOF
1404 root_tree=$(git rev-parse refs/heads/branch^0^{tree}) &&
1405 cat >input <<-INPUT_END &&
1406 commit refs/heads/N6
1407 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1408 data <<COMMIT
1409 copy root directory by tree hash
1410 COMMIT
1411
1412 from refs/heads/branch^0
1413 M 040000 $root_tree $root
1414 INPUT_END
1415 git fast-import <input &&
1416 git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1417 compare_diff_raw expect actual
1418 '
1419
1420 test_expect_success "N: copy root ($root) by path" '
1421 cat >expect <<-EOF &&
1422 :100755 100755 $newf $newf C100 file2/newf oldroot/file2/newf
1423 :100644 100644 $oldf $oldf C100 file2/oldf oldroot/file2/oldf
1424 :100755 100755 $f4id $f4id C100 file4 oldroot/file4
1425 :100755 100755 $f6id $f6id C100 newdir/exec.sh oldroot/newdir/exec.sh
1426 :100644 100644 $f5id $f5id C100 newdir/interesting oldroot/newdir/interesting
1427 EOF
1428 cat >input <<-INPUT_END &&
1429 commit refs/heads/N-copy-root-path
1430 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1431 data <<COMMIT
1432 copy root directory by (empty) path
1433 COMMIT
1434
1435 from refs/heads/branch^0
1436 C $root oldroot
1437 INPUT_END
1438 git fast-import <input &&
1439 git diff-tree -C --find-copies-harder -r branch N-copy-root-path >actual &&
1440 compare_diff_raw expect actual
1441 '
1442done
1443
1444test_expect_success 'N: delete directory by copying' '
1445 cat >expect <<-\EOF &&
1446 OBJID
1447 :100644 000000 OBJID OBJID D foo/bar/qux
1448 OBJID
1449 :000000 100644 OBJID OBJID A foo/bar/baz
1450 :000000 100644 OBJID OBJID A foo/bar/qux
1451 EOF
1452 empty_tree=$(git mktree </dev/null) &&
1453 cat >input <<-INPUT_END &&
1454 commit refs/heads/N-delete
1455 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1456 data <<COMMIT
1457 collect data to be deleted
1458 COMMIT
1459
1460 deleteall
1461 M 100644 inline foo/bar/baz
1462 data <<DATA_END
1463 hello
1464 DATA_END
1465 C "foo/bar/baz" "foo/bar/qux"
1466 C "foo/bar/baz" "foo/bar/quux/1"
1467 C "foo/bar/baz" "foo/bar/quuux"
1468 M 040000 $empty_tree foo/bar/quux
1469 M 040000 $empty_tree foo/bar/quuux
1470
1471 commit refs/heads/N-delete
1472 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1473 data <<COMMIT
1474 delete subdirectory
1475 COMMIT
1476
1477 M 040000 $empty_tree foo/bar/qux
1478 INPUT_END
1479 git fast-import <input &&
1480 git rev-list N-delete |
1481 git diff-tree -r --stdin --root --always |
1482 sed -e "s/$OID_REGEX/OBJID/g" >actual &&
1483 test_cmp expect actual
1484'
1485
1486test_expect_success 'N: modify copied tree' '
1487 cat >expect <<-EOF &&
1488 :100644 100644 $f5id $f5id C100 newdir/interesting file3/file5
1489 :100755 100755 $newf $newf C100 file2/newf file3/newf
1490 :100644 100644 $oldf $oldf C100 file2/oldf file3/oldf
1491 EOF
1492 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1493 cat >input <<-INPUT_END &&
1494 commit refs/heads/N5
1495 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1496 data <<COMMIT
1497 copy by tree hash
1498 COMMIT
1499
1500 from refs/heads/branch^0
1501 M 040000 $subdir file3
1502
1503 commit refs/heads/N5
1504 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1505 data <<COMMIT
1506 modify directory copy
1507 COMMIT
1508
1509 M 644 inline file3/file5
1510 data <<EOF
1511 $file5_data
1512 EOF
1513 INPUT_END
1514 git fast-import <input &&
1515 git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1516 compare_diff_raw expect actual
1517'
1518
1519test_expect_success 'N: reject foo/ syntax' '
1520 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1521 test_must_fail git fast-import <<-INPUT_END
1522 commit refs/heads/N5B
1523 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1524 data <<COMMIT
1525 copy with invalid syntax
1526 COMMIT
1527
1528 from refs/heads/branch^0
1529 M 040000 $subdir file3/
1530 INPUT_END
1531'
1532
1533test_expect_success 'N: reject foo/ syntax in copy source' '
1534 test_must_fail git fast-import <<-INPUT_END
1535 commit refs/heads/N5C
1536 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1537 data <<COMMIT
1538 copy with invalid syntax
1539 COMMIT
1540
1541 from refs/heads/branch^0
1542 C file2/ file3
1543 INPUT_END
1544'
1545
1546test_expect_success 'N: reject foo/ syntax in rename source' '
1547 test_must_fail git fast-import <<-INPUT_END
1548 commit refs/heads/N5D
1549 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1550 data <<COMMIT
1551 rename with invalid syntax
1552 COMMIT
1553
1554 from refs/heads/branch^0
1555 R file2/ file3
1556 INPUT_END
1557'
1558
1559test_expect_success 'N: reject foo/ syntax in ls argument' '
1560 test_must_fail git fast-import <<-INPUT_END
1561 commit refs/heads/N5E
1562 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1563 data <<COMMIT
1564 copy with invalid syntax
1565 COMMIT
1566
1567 from refs/heads/branch^0
1568 ls "file2/"
1569 INPUT_END
1570'
1571
1572for root in '""' ''
1573do
1574 test_expect_success "N: copy to root ($root) by id and modify" '
1575 echo "hello, world" >expect.foo &&
1576 echo hello >expect.bar &&
1577 git fast-import <<-SETUP_END &&
1578 commit refs/heads/N7
1579 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1580 data <<COMMIT
1581 hello, tree
1582 COMMIT
1583
1584 deleteall
1585 M 644 inline foo/bar
1586 data <<EOF
1587 hello
1588 EOF
1589 SETUP_END
1590
1591 tree=$(git rev-parse --verify N7:) &&
1592 git fast-import <<-INPUT_END &&
1593 commit refs/heads/N8
1594 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1595 data <<COMMIT
1596 copy to root by id and modify
1597 COMMIT
1598
1599 M 040000 $tree $root
1600 M 644 inline foo/foo
1601 data <<EOF
1602 hello, world
1603 EOF
1604 INPUT_END
1605 git show N8:foo/foo >actual.foo &&
1606 git show N8:foo/bar >actual.bar &&
1607 test_cmp expect.foo actual.foo &&
1608 test_cmp expect.bar actual.bar
1609 '
1610
1611 test_expect_success "N: extract subtree to the root ($root)" '
1612 branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1613 cat >input <<-INPUT_END &&
1614 commit refs/heads/N9
1615 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1616 data <<COMMIT
1617 extract subtree branch:newdir
1618 COMMIT
1619
1620 M 040000 $branch $root
1621 C "newdir" $root
1622 INPUT_END
1623 git fast-import <input &&
1624 git diff --exit-code branch:newdir N9
1625 '
1626
1627 test_expect_success "N: modify subtree, extract it to the root ($root), and modify again" '
1628 echo hello >expect.baz &&
1629 echo hello, world >expect.qux &&
1630 git fast-import <<-SETUP_END &&
1631 commit refs/heads/N10
1632 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1633 data <<COMMIT
1634 hello, tree
1635 COMMIT
1636
1637 deleteall
1638 M 644 inline foo/bar/baz
1639 data <<EOF
1640 hello
1641 EOF
1642 SETUP_END
1643
1644 tree=$(git rev-parse --verify N10:) &&
1645 git fast-import <<-INPUT_END &&
1646 commit refs/heads/N11
1647 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1648 data <<COMMIT
1649 copy to root by id and modify
1650 COMMIT
1651
1652 M 040000 $tree $root
1653 M 100644 inline foo/bar/qux
1654 data <<EOF
1655 hello, world
1656 EOF
1657 R "foo" $root
1658 C "bar/qux" "bar/quux"
1659 INPUT_END
1660 git show N11:bar/baz >actual.baz &&
1661 git show N11:bar/qux >actual.qux &&
1662 git show N11:bar/quux >actual.quux &&
1663 test_cmp expect.baz actual.baz &&
1664 test_cmp expect.qux actual.qux &&
1665 test_cmp expect.qux actual.quux
1666 '
1667done
1668
1669###
1670### series O
1671###
1672
1673test_expect_success 'O: comments are all skipped' '
1674 cat >input <<-INPUT_END &&
1675 #we will
1676 commit refs/heads/O1
1677 # -- ignore all of this text
1678 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1679 data <<COMMIT
1680 dirty directory copy
1681 COMMIT
1682
1683 # do not forget the import blank line!
1684 #
1685 # yes, we started from our usual base of branch^0.
1686 # i like branch^0.
1687 from refs/heads/branch^0
1688 # and we need to reuse file2/file5 from N3 above.
1689 M 644 inline file2/file5
1690 # otherwise the tree will be different
1691 data <<EOF
1692 $file5_data
1693 EOF
1694
1695 # do not forget to copy file2 to file3
1696 C file2 file3
1697 #
1698 # or to delete file5 from file2.
1699 D file2/file5
1700 # are we done yet?
1701
1702 INPUT_END
1703
1704 git fast-import <input &&
1705 test $(git rev-parse N3) = $(git rev-parse O1)
1706'
1707
1708test_expect_success 'O: blank lines not necessary after data commands' '
1709 cat >input <<-INPUT_END &&
1710 commit refs/heads/O2
1711 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1712 data <<COMMIT
1713 dirty directory copy
1714 COMMIT
1715 from refs/heads/branch^0
1716 M 644 inline file2/file5
1717 data <<EOF
1718 $file5_data
1719 EOF
1720 C file2 file3
1721 D file2/file5
1722
1723 INPUT_END
1724
1725 git fast-import <input &&
1726 test $(git rev-parse N3) = $(git rev-parse O2)
1727'
1728
1729test_expect_success 'O: repack before next test' '
1730 git repack -a -d
1731'
1732
1733test_expect_success 'O: blank lines not necessary after other commands' '
1734 cat >input <<-INPUT_END &&
1735 commit refs/heads/O3
1736 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1737 data <<COMMIT
1738 zstring
1739 COMMIT
1740 commit refs/heads/O3
1741 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1742 data <<COMMIT
1743 zof
1744 COMMIT
1745 checkpoint
1746 commit refs/heads/O3
1747 mark :5
1748 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1749 data <<COMMIT
1750 zempty
1751 COMMIT
1752 checkpoint
1753 commit refs/heads/O3
1754 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1755 data <<COMMIT
1756 zcommits
1757 COMMIT
1758 reset refs/tags/O3-2nd
1759 from :5
1760 reset refs/tags/O3-3rd
1761 from :5
1762 INPUT_END
1763
1764 cat >expect <<-INPUT_END &&
1765 string
1766 of
1767 empty
1768 commits
1769 INPUT_END
1770
1771 git fast-import <input &&
1772 ls -la .git/objects/pack/pack-*.pack >packlist &&
1773 ls -la .git/objects/pack/pack-*.pack >idxlist &&
1774 test_line_count = 4 idxlist &&
1775 test_line_count = 4 packlist &&
1776 test $(git rev-parse refs/tags/O3-2nd) = $(git rev-parse O3^) &&
1777 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1778 test_cmp expect actual
1779'
1780
1781test_expect_success 'O: progress outputs as requested by input' '
1782 cat >input <<-INPUT_END &&
1783 commit refs/heads/O4
1784 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1785 data <<COMMIT
1786 zstring
1787 COMMIT
1788 commit refs/heads/O4
1789 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1790 data <<COMMIT
1791 zof
1792 COMMIT
1793 progress Two commits down, 2 to go!
1794 commit refs/heads/O4
1795 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1796 data <<COMMIT
1797 zempty
1798 COMMIT
1799 progress Three commits down, 1 to go!
1800 commit refs/heads/O4
1801 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1802 data <<COMMIT
1803 zcommits
1804 COMMIT
1805 progress done!
1806 INPUT_END
1807 git fast-import <input >actual &&
1808 grep "progress " <input >expect &&
1809 test_cmp expect actual
1810'
1811
1812###
1813### series P (gitlinks)
1814###
1815
1816test_expect_success 'P: superproject & submodule mix' '
1817 cat >input <<-INPUT_END &&
1818 blob
1819 mark :1
1820 data 10
1821 test file
1822
1823 reset refs/heads/sub
1824 commit refs/heads/sub
1825 mark :2
1826 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1827 data 12
1828 sub_initial
1829 M 100644 :1 file
1830
1831 blob
1832 mark :3
1833 data <<DATAEND
1834 [submodule "sub"]
1835 path = sub
1836 url = "$(pwd)/sub"
1837 DATAEND
1838
1839 commit refs/heads/subuse1
1840 mark :4
1841 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1842 data 8
1843 initial
1844 from refs/heads/main
1845 M 100644 :3 .gitmodules
1846 M 160000 :2 sub
1847
1848 blob
1849 mark :5
1850 data 20
1851 test file
1852 more data
1853
1854 commit refs/heads/sub
1855 mark :6
1856 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1857 data 11
1858 sub_second
1859 from :2
1860 M 100644 :5 file
1861
1862 commit refs/heads/subuse1
1863 mark :7
1864 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1865 data 7
1866 second
1867 from :4
1868 M 160000 :6 sub
1869
1870 INPUT_END
1871
1872 git fast-import <input &&
1873 git checkout subuse1 &&
1874 rm -rf sub &&
1875 mkdir sub &&
1876 (
1877 cd sub &&
1878 git init &&
1879 git fetch --update-head-ok .. refs/heads/sub:refs/heads/main &&
1880 git checkout main
1881 ) &&
1882 git submodule init &&
1883 git submodule update
1884'
1885
1886test_expect_success 'P: verbatim SHA gitlinks' '
1887 SUBLAST=$(git rev-parse --verify sub) &&
1888 SUBPREV=$(git rev-parse --verify sub^) &&
1889
1890 cat >input <<-INPUT_END &&
1891 blob
1892 mark :1
1893 data <<DATAEND
1894 [submodule "sub"]
1895 path = sub
1896 url = "$(pwd)/sub"
1897 DATAEND
1898
1899 commit refs/heads/subuse2
1900 mark :2
1901 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1902 data 8
1903 initial
1904 from refs/heads/main
1905 M 100644 :1 .gitmodules
1906 M 160000 $SUBPREV sub
1907
1908 commit refs/heads/subuse2
1909 mark :3
1910 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1911 data 7
1912 second
1913 from :2
1914 M 160000 $SUBLAST sub
1915
1916 INPUT_END
1917
1918 git branch -D sub &&
1919 git gc --prune=now &&
1920 git fast-import <input &&
1921 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)
1922'
1923
1924test_expect_success 'P: fail on inline gitlink' '
1925 test_tick &&
1926 cat >input <<-INPUT_END &&
1927 commit refs/heads/subuse3
1928 mark :1
1929 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1930 data <<COMMIT
1931 corrupt
1932 COMMIT
1933
1934 from refs/heads/subuse2
1935 M 160000 inline sub
1936 data <<DATA
1937 $SUBPREV
1938 DATA
1939
1940 INPUT_END
1941
1942 test_must_fail git fast-import <input
1943'
1944
1945test_expect_success 'P: fail on blob mark in gitlink' '
1946 test_tick &&
1947 cat >input <<-INPUT_END &&
1948 blob
1949 mark :1
1950 data <<DATA
1951 $SUBPREV
1952 DATA
1953
1954 commit refs/heads/subuse3
1955 mark :2
1956 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1957 data <<COMMIT
1958 corrupt
1959 COMMIT
1960
1961 from refs/heads/subuse2
1962 M 160000 :1 sub
1963
1964 INPUT_END
1965
1966 test_must_fail git fast-import <input
1967'
1968
1969###
1970### series Q (notes)
1971###
1972
1973test_expect_success 'Q: commit notes' '
1974 note1_data="The first note for the first commit" &&
1975 note2_data="The first note for the second commit" &&
1976 note3_data="The first note for the third commit" &&
1977 note1b_data="The second note for the first commit" &&
1978 note1c_data="The third note for the first commit" &&
1979 note2b_data="The second note for the second commit" &&
1980
1981 test_tick &&
1982 cat >input <<-INPUT_END &&
1983 blob
1984 mark :2
1985 data <<EOF
1986 $file2_data
1987 EOF
1988
1989 commit refs/heads/notes-test
1990 mark :3
1991 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1992 data <<COMMIT
1993 first (:3)
1994 COMMIT
1995
1996 M 644 :2 file2
1997
1998 blob
1999 mark :4
2000 data $file4_len
2001 $file4_data
2002 commit refs/heads/notes-test
2003 mark :5
2004 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2005 data <<COMMIT
2006 second (:5)
2007 COMMIT
2008
2009 M 644 :4 file4
2010
2011 commit refs/heads/notes-test
2012 mark :6
2013 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2014 data <<COMMIT
2015 third (:6)
2016 COMMIT
2017
2018 M 644 inline file5
2019 data <<EOF
2020 $file5_data
2021 EOF
2022
2023 M 755 inline file6
2024 data <<EOF
2025 $file6_data
2026 EOF
2027
2028 blob
2029 mark :7
2030 data <<EOF
2031 $note1_data
2032 EOF
2033
2034 blob
2035 mark :8
2036 data <<EOF
2037 $note2_data
2038 EOF
2039
2040 commit refs/notes/foobar
2041 mark :9
2042 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2043 data <<COMMIT
2044 notes (:9)
2045 COMMIT
2046
2047 N :7 :3
2048 N :8 :5
2049 N inline :6
2050 data <<EOF
2051 $note3_data
2052 EOF
2053
2054 commit refs/notes/foobar
2055 mark :10
2056 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2057 data <<COMMIT
2058 notes (:10)
2059 COMMIT
2060
2061 N inline :3
2062 data <<EOF
2063 $note1b_data
2064 EOF
2065
2066 commit refs/notes/foobar2
2067 mark :11
2068 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2069 data <<COMMIT
2070 notes (:11)
2071 COMMIT
2072
2073 N inline :3
2074 data <<EOF
2075 $note1c_data
2076 EOF
2077
2078 commit refs/notes/foobar
2079 mark :12
2080 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2081 data <<COMMIT
2082 notes (:12)
2083 COMMIT
2084
2085 deleteall
2086 N inline :5
2087 data <<EOF
2088 $note2b_data
2089 EOF
2090
2091 INPUT_END
2092
2093 git fast-import <input &&
2094 git log --raw notes-test
2095'
2096
2097test_expect_success 'Q: verify pack' '
2098 verify_packs
2099'
2100
2101test_expect_success 'Q: verify first commit' '
2102 commit1=$(git rev-parse notes-test~2) &&
2103 commit2=$(git rev-parse notes-test^) &&
2104 commit3=$(git rev-parse notes-test) &&
2105
2106 cat >expect <<-EOF &&
2107 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2108 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2109
2110 first (:3)
2111 EOF
2112 git cat-file commit notes-test~2 | sed 1d >actual &&
2113 test_cmp expect actual
2114'
2115
2116test_expect_success 'Q: verify second commit' '
2117 cat >expect <<-EOF &&
2118 parent $commit1
2119 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2120 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2121
2122 second (:5)
2123 EOF
2124 git cat-file commit notes-test^ | sed 1d >actual &&
2125 test_cmp expect actual
2126'
2127
2128test_expect_success 'Q: verify third commit' '
2129 cat >expect <<-EOF &&
2130 parent $commit2
2131 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2132 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2133
2134 third (:6)
2135 EOF
2136 git cat-file commit notes-test | sed 1d >actual &&
2137 test_cmp expect actual
2138'
2139
2140test_expect_success 'Q: verify first notes commit' '
2141 cat >expect <<-EOF &&
2142 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2143 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2144
2145 notes (:9)
2146 EOF
2147 git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
2148 test_cmp expect actual
2149'
2150
2151test_expect_success 'Q: verify first notes tree' '
2152 sort >expect <<-EOF &&
2153 100644 blob $commit1
2154 100644 blob $commit2
2155 100644 blob $commit3
2156 EOF
2157 git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2158 test_cmp expect actual
2159'
2160
2161test_expect_success 'Q: verify first note for first commit' '
2162 echo "$note1_data" >expect &&
2163 git cat-file blob refs/notes/foobar~2:$commit1 >actual &&
2164 test_cmp expect actual
2165'
2166
2167test_expect_success 'Q: verify first note for second commit' '
2168 echo "$note2_data" >expect &&
2169 git cat-file blob refs/notes/foobar~2:$commit2 >actual &&
2170 test_cmp expect actual
2171'
2172
2173test_expect_success 'Q: verify first note for third commit' '
2174 echo "$note3_data" >expect &&
2175 git cat-file blob refs/notes/foobar~2:$commit3 >actual &&
2176 test_cmp expect actual
2177'
2178
2179test_expect_success 'Q: verify second notes commit' '
2180 cat >expect <<-EOF &&
2181 parent $(git rev-parse --verify refs/notes/foobar~2)
2182 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2183 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2184
2185 notes (:10)
2186 EOF
2187 git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
2188 test_cmp expect actual
2189'
2190
2191test_expect_success 'Q: verify second notes tree' '
2192 sort >expect <<-EOF &&
2193 100644 blob $commit1
2194 100644 blob $commit2
2195 100644 blob $commit3
2196 EOF
2197 git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2198 test_cmp expect actual
2199'
2200
2201test_expect_success 'Q: verify second note for first commit' '
2202 echo "$note1b_data" >expect &&
2203 git cat-file blob refs/notes/foobar^:$commit1 >actual &&
2204 test_cmp expect actual
2205'
2206
2207test_expect_success 'Q: verify first note for second commit' '
2208 echo "$note2_data" >expect &&
2209 git cat-file blob refs/notes/foobar^:$commit2 >actual &&
2210 test_cmp expect actual
2211'
2212
2213test_expect_success 'Q: verify first note for third commit' '
2214 echo "$note3_data" >expect &&
2215 git cat-file blob refs/notes/foobar^:$commit3 >actual &&
2216 test_cmp expect actual
2217'
2218
2219test_expect_success 'Q: verify third notes commit' '
2220 cat >expect <<-EOF &&
2221 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2222 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2223
2224 notes (:11)
2225 EOF
2226 git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
2227 test_cmp expect actual
2228'
2229
2230test_expect_success 'Q: verify third notes tree' '
2231 sort >expect <<-EOF &&
2232 100644 blob $commit1
2233 EOF
2234 git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2235 test_cmp expect actual
2236'
2237
2238test_expect_success 'Q: verify third note for first commit' '
2239 echo "$note1c_data" >expect &&
2240 git cat-file blob refs/notes/foobar2:$commit1 >actual &&
2241 test_cmp expect actual
2242'
2243
2244test_expect_success 'Q: verify fourth notes commit' '
2245 cat >expect <<-EOF &&
2246 parent $(git rev-parse --verify refs/notes/foobar^)
2247 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2248 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2249
2250 notes (:12)
2251 EOF
2252 git cat-file commit refs/notes/foobar | sed 1d >actual &&
2253 test_cmp expect actual
2254'
2255
2256test_expect_success 'Q: verify fourth notes tree' '
2257 sort >expect <<-EOF &&
2258 100644 blob $commit2
2259 EOF
2260 git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2261 test_cmp expect actual
2262'
2263
2264test_expect_success 'Q: verify second note for second commit' '
2265 echo "$note2b_data" >expect &&
2266 git cat-file blob refs/notes/foobar:$commit2 >actual &&
2267 test_cmp expect actual
2268'
2269
2270test_expect_success 'Q: deny note on empty branch' '
2271 cat >input <<-EOF &&
2272 reset refs/heads/Q0
2273
2274 commit refs/heads/note-Q0
2275 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2276 data <<COMMIT
2277 Note for an empty branch.
2278 COMMIT
2279
2280 N inline refs/heads/Q0
2281 data <<NOTE
2282 some note
2283 NOTE
2284 EOF
2285 test_must_fail git fast-import <input
2286'
2287
2288###
2289### series R (feature and option)
2290###
2291
2292test_expect_success 'R: abort on unsupported feature' '
2293 cat >input <<-EOF &&
2294 feature no-such-feature-exists
2295 EOF
2296
2297 test_must_fail git fast-import <input
2298'
2299
2300test_expect_success 'R: supported feature is accepted' '
2301 cat >input <<-EOF &&
2302 feature date-format=now
2303 EOF
2304
2305 git fast-import <input
2306'
2307
2308test_expect_success 'R: abort on receiving feature after data command' '
2309 cat >input <<-EOF &&
2310 blob
2311 data 3
2312 hi
2313 feature date-format=now
2314 EOF
2315
2316 test_must_fail git fast-import <input
2317'
2318
2319test_expect_success 'R: import-marks features forbidden by default' '
2320 >git.marks &&
2321 echo "feature import-marks=git.marks" >input &&
2322 test_must_fail git fast-import <input &&
2323 echo "feature import-marks-if-exists=git.marks" >input &&
2324 test_must_fail git fast-import <input
2325'
2326
2327test_expect_success 'R: only one import-marks feature allowed per stream' '
2328 >git.marks &&
2329 >git2.marks &&
2330 cat >input <<-EOF &&
2331 feature import-marks=git.marks
2332 feature import-marks=git2.marks
2333 EOF
2334
2335 test_must_fail git fast-import --allow-unsafe-features <input
2336'
2337
2338test_expect_success 'R: export-marks feature forbidden by default' '
2339 echo "feature export-marks=git.marks" >input &&
2340 test_must_fail git fast-import <input
2341'
2342
2343test_expect_success 'R: export-marks feature results in a marks file being created' '
2344 cat >input <<-EOF &&
2345 feature export-marks=git.marks
2346 blob
2347 mark :1
2348 data 3
2349 hi
2350
2351 EOF
2352
2353 git fast-import --allow-unsafe-features <input &&
2354 test_grep :1 git.marks
2355'
2356
2357test_expect_success 'R: export-marks options can be overridden by commandline options' '
2358 cat >input <<-\EOF &&
2359 feature export-marks=feature-sub/git.marks
2360 blob
2361 mark :1
2362 data 3
2363 hi
2364
2365 EOF
2366 git fast-import --allow-unsafe-features \
2367 --export-marks=cmdline-sub/other.marks <input &&
2368 test_grep :1 cmdline-sub/other.marks &&
2369 test_path_is_missing feature-sub
2370'
2371
2372test_expect_success 'R: catch typo in marks file name' '
2373 test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2374 echo "feature import-marks=nonexistent.marks" |
2375 test_must_fail git fast-import --allow-unsafe-features
2376'
2377
2378test_expect_success 'R: import and output marks can be the same file' '
2379 rm -f io.marks &&
2380 blob=$(echo hi | git hash-object --stdin) &&
2381 cat >expect <<-EOF &&
2382 :1 $blob
2383 :2 $blob
2384 EOF
2385 git fast-import --export-marks=io.marks <<-\EOF &&
2386 blob
2387 mark :1
2388 data 3
2389 hi
2390
2391 EOF
2392 git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2393 blob
2394 mark :2
2395 data 3
2396 hi
2397
2398 EOF
2399 test_cmp expect io.marks
2400'
2401
2402test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
2403 rm -f io.marks &&
2404 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2405 blob
2406 mark :1
2407 data 3
2408 hi
2409
2410 EOF
2411'
2412
2413test_expect_success 'R: --import-marks-if-exists' '
2414 rm -f io.marks &&
2415 blob=$(echo hi | git hash-object --stdin) &&
2416 echo ":1 $blob" >expect &&
2417 git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2418 blob
2419 mark :1
2420 data 3
2421 hi
2422
2423 EOF
2424 test_cmp expect io.marks
2425'
2426
2427test_expect_success 'R: feature import-marks-if-exists' '
2428 rm -f io.marks &&
2429
2430 git fast-import --export-marks=io.marks \
2431 --allow-unsafe-features <<-\EOF &&
2432 feature import-marks-if-exists=not_io.marks
2433 EOF
2434 test_must_be_empty io.marks &&
2435
2436 blob=$(echo hi | git hash-object --stdin) &&
2437
2438 echo ":1 $blob" >io.marks &&
2439 echo ":1 $blob" >expect &&
2440 echo ":2 $blob" >>expect &&
2441
2442 git fast-import --export-marks=io.marks \
2443 --allow-unsafe-features <<-\EOF &&
2444 feature import-marks-if-exists=io.marks
2445 blob
2446 mark :2
2447 data 3
2448 hi
2449
2450 EOF
2451 test_cmp expect io.marks &&
2452
2453 echo ":3 $blob" >>expect &&
2454
2455 git fast-import --import-marks=io.marks \
2456 --export-marks=io.marks \
2457 --allow-unsafe-features <<-\EOF &&
2458 feature import-marks-if-exists=not_io.marks
2459 blob
2460 mark :3
2461 data 3
2462 hi
2463
2464 EOF
2465 test_cmp expect io.marks &&
2466
2467 git fast-import --import-marks-if-exists=not_io.marks \
2468 --export-marks=io.marks \
2469 --allow-unsafe-features <<-\EOF &&
2470 feature import-marks-if-exists=io.marks
2471 EOF
2472 test_must_be_empty io.marks
2473'
2474
2475test_expect_success 'R: import to output marks works without any content' '
2476 cat >input <<-EOF &&
2477 feature import-marks=marks.out
2478 feature export-marks=marks.new
2479 EOF
2480
2481 git fast-import --allow-unsafe-features <input &&
2482 test_cmp marks.out marks.new
2483'
2484
2485test_expect_success 'R: import marks prefers commandline marks file over the stream' '
2486 cat >input <<-EOF &&
2487 feature import-marks=nonexistent.marks
2488 feature export-marks=marks.new
2489 EOF
2490
2491 git fast-import --import-marks=marks.out --allow-unsafe-features <input &&
2492 test_cmp marks.out marks.new
2493'
2494
2495
2496test_expect_success 'R: multiple --import-marks= should be honoured' '
2497 cat >input <<-EOF &&
2498 feature import-marks=nonexistent.marks
2499 feature export-marks=combined.marks
2500 EOF
2501
2502 head -n2 marks.out > one.marks &&
2503 tail -n +3 marks.out > two.marks &&
2504 git fast-import --import-marks=one.marks --import-marks=two.marks \
2505 --allow-unsafe-features <input &&
2506 test_cmp marks.out combined.marks
2507'
2508
2509test_expect_success 'R: feature relative-marks should be honoured' '
2510 cat >input <<-EOF &&
2511 feature relative-marks
2512 feature import-marks=relative.in
2513 feature export-marks=relative.out
2514 EOF
2515
2516 mkdir -p .git/info/fast-import/ &&
2517 cp marks.new .git/info/fast-import/relative.in &&
2518 git fast-import --allow-unsafe-features <input &&
2519 test_cmp marks.new .git/info/fast-import/relative.out
2520'
2521
2522test_expect_success 'R: feature no-relative-marks should be honoured' '
2523 cat >input <<-EOF &&
2524 feature relative-marks
2525 feature import-marks=relative.in
2526 feature no-relative-marks
2527 feature export-marks=non-relative.out
2528 EOF
2529
2530 git fast-import --allow-unsafe-features <input &&
2531 test_cmp marks.new non-relative.out
2532'
2533
2534test_expect_success 'R: feature ls supported' '
2535 echo "feature ls" |
2536 git fast-import
2537'
2538
2539test_expect_success 'R: feature cat-blob supported' '
2540 echo "feature cat-blob" |
2541 git fast-import
2542'
2543
2544test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
2545 test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2546'
2547
2548test_expect_success !MINGW 'R: print old blob' '
2549 blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2550 cat >expect <<-EOF &&
2551 ${blob} blob 11
2552 yes it can
2553
2554 EOF
2555 echo "cat-blob $blob" |
2556 git fast-import --cat-blob-fd=6 6>actual &&
2557 test_cmp expect actual
2558'
2559
2560test_expect_success !MINGW 'R: in-stream cat-blob-fd not respected' '
2561 echo hello >greeting &&
2562 blob=$(git hash-object -w greeting) &&
2563 cat >expect <<-EOF &&
2564 ${blob} blob 6
2565 hello
2566
2567 EOF
2568 git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2569 cat-blob $blob
2570 EOF
2571 test_cmp expect actual.3 &&
2572 test_must_be_empty actual.1 &&
2573 git fast-import 3>actual.3 >actual.1 <<-EOF &&
2574 option cat-blob-fd=3
2575 cat-blob $blob
2576 EOF
2577 test_must_be_empty actual.3 &&
2578 test_cmp expect actual.1
2579'
2580
2581test_expect_success !MINGW 'R: print mark for new blob' '
2582 echo "effluentish" | git hash-object --stdin >expect &&
2583 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2584 blob
2585 mark :1
2586 data <<BLOB_END
2587 effluentish
2588 BLOB_END
2589 get-mark :1
2590 EOF
2591 test_cmp expect actual
2592'
2593
2594test_expect_success !MINGW 'R: print new blob' '
2595 blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2596 cat >expect <<-EOF &&
2597 ${blob} blob 12
2598 yep yep yep
2599
2600 EOF
2601 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2602 blob
2603 mark :1
2604 data <<BLOB_END
2605 yep yep yep
2606 BLOB_END
2607 cat-blob :1
2608 EOF
2609 test_cmp expect actual
2610'
2611
2612test_expect_success !MINGW 'R: print new blob by sha1' '
2613 blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2614 cat >expect <<-EOF &&
2615 ${blob} blob 25
2616 a new blob named by sha1
2617
2618 EOF
2619 git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2620 blob
2621 data <<BLOB_END
2622 a new blob named by sha1
2623 BLOB_END
2624 cat-blob $blob
2625 EOF
2626 test_cmp expect actual
2627'
2628
2629test_expect_success 'setup: big file' '
2630 (
2631 echo "the quick brown fox jumps over the lazy dog" >big &&
2632 for i in 1 2 3
2633 do
2634 cat big big big big >bigger &&
2635 cat bigger bigger bigger bigger >big ||
2636 exit
2637 done
2638 )
2639'
2640
2641test_expect_success 'R: print two blobs to stdout' '
2642 blob1=$(git hash-object big) &&
2643 blob1_len=$(wc -c <big) &&
2644 blob2=$(echo hello | git hash-object --stdin) &&
2645 {
2646 echo ${blob1} blob $blob1_len &&
2647 cat big &&
2648 cat <<-EOF
2649
2650 ${blob2} blob 6
2651 hello
2652
2653 EOF
2654 } >expect &&
2655 {
2656 cat <<-\END_PART1 &&
2657 blob
2658 mark :1
2659 data <<data_end
2660 END_PART1
2661 cat big &&
2662 cat <<-\EOF
2663 data_end
2664 blob
2665 mark :2
2666 data <<data_end
2667 hello
2668 data_end
2669 cat-blob :1
2670 cat-blob :2
2671 EOF
2672 } |
2673 git fast-import >actual &&
2674 test_cmp expect actual
2675'
2676
2677test_expect_success PIPE 'R: copy using cat-file' '
2678 expect_id=$(git hash-object big) &&
2679 expect_len=$(wc -c <big) &&
2680 echo $expect_id blob $expect_len >expect.response &&
2681
2682 rm -f blobs &&
2683
2684 mkfifo blobs &&
2685 (
2686 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2687 cat <<-\EOF &&
2688 feature cat-blob
2689 blob
2690 mark :1
2691 data <<BLOB
2692 EOF
2693 cat big &&
2694 cat <<-\EOF &&
2695 BLOB
2696 cat-blob :1
2697 EOF
2698
2699 read blob_id type size <&3 &&
2700 echo "$blob_id $type $size" >response &&
2701 test_copy_bytes $size >blob <&3 &&
2702 read newline <&3 &&
2703
2704 cat <<-EOF &&
2705 commit refs/heads/copied
2706 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2707 data <<COMMIT
2708 copy big file as file3
2709 COMMIT
2710 M 644 inline file3
2711 data <<BLOB
2712 EOF
2713 cat blob &&
2714 echo BLOB
2715 ) 3<blobs |
2716 git fast-import --cat-blob-fd=3 3>blobs &&
2717 git show copied:file3 >actual &&
2718 test_cmp expect.response response &&
2719 test_cmp big actual
2720'
2721
2722test_expect_success PIPE 'R: print blob mid-commit' '
2723 rm -f blobs &&
2724 echo "A blob from _before_ the commit." >expect &&
2725 mkfifo blobs &&
2726 (
2727 exec 3<blobs &&
2728 cat <<-EOF &&
2729 feature cat-blob
2730 blob
2731 mark :1
2732 data <<BLOB
2733 A blob from _before_ the commit.
2734 BLOB
2735 commit refs/heads/temporary
2736 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2737 data <<COMMIT
2738 Empty commit
2739 COMMIT
2740 cat-blob :1
2741 EOF
2742
2743 read blob_id type size <&3 &&
2744 test_copy_bytes $size >actual <&3 &&
2745 read newline <&3 &&
2746
2747 echo
2748 ) |
2749 git fast-import --cat-blob-fd=3 3>blobs &&
2750 test_cmp expect actual
2751'
2752
2753test_expect_success PIPE 'R: print staged blob within commit' '
2754 rm -f blobs &&
2755 echo "A blob from _within_ the commit." >expect &&
2756 mkfifo blobs &&
2757 (
2758 exec 3<blobs &&
2759 cat <<-EOF &&
2760 feature cat-blob
2761 commit refs/heads/within
2762 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2763 data <<COMMIT
2764 Empty commit
2765 COMMIT
2766 M 644 inline within
2767 data <<BLOB
2768 A blob from _within_ the commit.
2769 BLOB
2770 EOF
2771
2772 to_get=$(
2773 echo "A blob from _within_ the commit." |
2774 git hash-object --stdin
2775 ) &&
2776 echo "cat-blob $to_get" &&
2777
2778 read blob_id type size <&3 &&
2779 test_copy_bytes $size >actual <&3 &&
2780 read newline <&3 &&
2781
2782 echo deleteall
2783 ) |
2784 git fast-import --cat-blob-fd=3 3>blobs &&
2785 test_cmp expect actual
2786'
2787
2788test_expect_success 'R: quiet option results in no stats being output' '
2789 cat >input <<-EOF &&
2790 option git quiet
2791 blob
2792 data 3
2793 hi
2794
2795 EOF
2796
2797 git fast-import 2>output <input &&
2798 test_must_be_empty output
2799'
2800
2801test_expect_success 'R: feature done means terminating "done" is mandatory' '
2802 echo feature done | test_must_fail git fast-import &&
2803 test_must_fail git fast-import --done </dev/null
2804'
2805
2806test_expect_success 'R: terminating "done" with trailing gibberish is ok' '
2807 git fast-import <<-\EOF &&
2808 feature done
2809 done
2810 trailing gibberish
2811 EOF
2812 git fast-import <<-\EOF
2813 done
2814 more trailing gibberish
2815 EOF
2816'
2817
2818test_expect_success 'R: terminating "done" within commit' '
2819 cat >expect <<-\EOF &&
2820 OBJID
2821 :000000 100644 OBJID OBJID A hello.c
2822 :000000 100644 OBJID OBJID A hello2.c
2823 EOF
2824 git fast-import <<-EOF &&
2825 commit refs/heads/done-ends
2826 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2827 data <<EOT
2828 Commit terminated by "done" command
2829 EOT
2830 M 100644 inline hello.c
2831 data <<EOT
2832 Hello, world.
2833 EOT
2834 C hello.c hello2.c
2835 done
2836 EOF
2837 git rev-list done-ends |
2838 git diff-tree -r --stdin --root --always |
2839 sed -e "s/$OID_REGEX/OBJID/g" >actual &&
2840 test_cmp expect actual
2841'
2842
2843test_expect_success 'R: die on unknown option' '
2844 cat >input <<-EOF &&
2845 option git non-existing-option
2846 EOF
2847
2848 test_must_fail git fast-import <input
2849'
2850
2851test_expect_success 'R: unknown commandline options are rejected' '\
2852 test_must_fail git fast-import --non-existing-option < /dev/null
2853'
2854
2855test_expect_success 'R: feature-only names are rejected on the command line' '
2856 for opt in --alias --get-mark --ls --notes
2857 do
2858 test_must_fail git fast-import "$opt" </dev/null || return 1
2859 done
2860'
2861
2862test_expect_success 'R: die on invalid option argument' '
2863 echo "option git active-branches=-5" |
2864 test_must_fail git fast-import &&
2865 echo "option git depth=" |
2866 test_must_fail git fast-import &&
2867 test_must_fail git fast-import --depth="5 elephants" </dev/null
2868'
2869
2870test_expect_success 'R: ignore non-git options' '
2871 cat >input <<-EOF &&
2872 option non-existing-vcs non-existing-option
2873 EOF
2874
2875 git fast-import <input
2876'
2877
2878test_expect_success 'R: corrupt lines do not mess marks file' '
2879 rm -f io.marks &&
2880 blob=$(echo hi | git hash-object --stdin) &&
2881 cat >expect <<-EOF &&
2882 :3 $ZERO_OID
2883 :1 $blob
2884 :2 $blob
2885 EOF
2886 cp expect io.marks &&
2887 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2888
2889 EOF
2890 test_cmp expect io.marks
2891'
2892
2893##
2894## R: very large blobs
2895##
2896test_expect_success 'R: blob bigger than threshold' '
2897 blobsize=$((2*1024*1024 + 53)) &&
2898 test-tool genrandom bar $blobsize >expect &&
2899 cat >input <<-INPUT_END &&
2900 commit refs/heads/big-file
2901 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2902 data <<COMMIT
2903 R - big file
2904 COMMIT
2905
2906 M 644 inline big1
2907 data $blobsize
2908 INPUT_END
2909 cat expect >>input &&
2910 cat >>input <<-INPUT_END &&
2911 M 644 inline big2
2912 data $blobsize
2913 INPUT_END
2914 cat expect >>input &&
2915 echo >>input &&
2916
2917 test_create_repo R &&
2918 git --git-dir=R/.git config fastimport.unpackLimit 0 &&
2919 git --git-dir=R/.git fast-import --big-file-threshold=1 <input
2920'
2921
2922test_expect_success 'R: verify created pack' '
2923 (
2924 cd R &&
2925 verify_packs -v > ../verify
2926 )
2927'
2928
2929test_expect_success 'R: verify written objects' '
2930 git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2931 test_cmp_bin expect actual &&
2932 a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2933 b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2934 test $a = $b
2935'
2936
2937test_expect_success 'R: blob appears only once' '
2938 n=$(grep $a verify | wc -l) &&
2939 test 1 = $n
2940'
2941
2942###
2943### series S (mark and path parsing)
2944###
2945#
2946# Make sure missing spaces and EOLs after mark references
2947# cause errors.
2948#
2949# Setup:
2950#
2951# 1--2--4
2952# \ /
2953# -3-
2954#
2955# commit marks: 301, 302, 303, 304
2956# blob marks: 403, 404, resp.
2957# note mark: 202
2958#
2959# The error message when a space is missing not at the
2960# end of the line is:
2961#
2962# missing space after ..
2963#
2964# or when extra characters come after the mark at the end
2965# of the line:
2966#
2967# garbage after ..
2968#
2969# or when the dataref is neither "inline " or a known SHA1,
2970#
2971# invalid dataref ..
2972#
2973test_expect_success 'S: initialize for S tests' '
2974 test_tick &&
2975
2976 cat >input <<-INPUT_END &&
2977 commit refs/heads/S
2978 mark :301
2979 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2980 data <<COMMIT
2981 commit 1
2982 COMMIT
2983 M 100644 inline hello.c
2984 data <<BLOB
2985 blob 1
2986 BLOB
2987
2988 commit refs/heads/S
2989 mark :302
2990 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2991 data <<COMMIT
2992 commit 2
2993 COMMIT
2994 from :301
2995 M 100644 inline hello.c
2996 data <<BLOB
2997 blob 2
2998 BLOB
2999
3000 blob
3001 mark :403
3002 data <<BLOB
3003 blob 3
3004 BLOB
3005
3006 blob
3007 mark :202
3008 data <<BLOB
3009 note 2
3010 BLOB
3011 INPUT_END
3012
3013 git fast-import --export-marks=marks <input
3014'
3015
3016#
3017# filemodify, three datarefs
3018#
3019test_expect_success 'S: filemodify with garbage after mark must fail' '
3020 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3021 commit refs/heads/S
3022 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3023 data <<COMMIT
3024 commit N
3025 COMMIT
3026 M 100644 :403x hello.c
3027 EOF
3028 test_grep "space after mark" err
3029'
3030
3031# inline is misspelled; fast-import thinks it is some unknown dataref
3032test_expect_success 'S: filemodify with garbage after inline must fail' '
3033 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3034 commit refs/heads/S
3035 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3036 data <<COMMIT
3037 commit N
3038 COMMIT
3039 M 100644 inlineX hello.c
3040 data <<BLOB
3041 inline
3042 BLOB
3043 EOF
3044 test_grep "nvalid dataref" err
3045'
3046
3047test_expect_success 'S: filemodify with garbage after sha1 must fail' '
3048 sha1=$(grep :403 marks | cut -d\ -f2) &&
3049 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3050 commit refs/heads/S
3051 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3052 data <<COMMIT
3053 commit N
3054 COMMIT
3055 M 100644 ${sha1}x hello.c
3056 EOF
3057 test_grep "space after SHA1" err
3058'
3059
3060#
3061# notemodify, three ways to say dataref
3062#
3063test_expect_success 'S: notemodify with garbage after mark dataref must fail' '
3064 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3065 commit refs/heads/S
3066 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3067 data <<COMMIT
3068 commit S note dataref markref
3069 COMMIT
3070 N :202x :302
3071 EOF
3072 test_grep "space after mark" err
3073'
3074
3075test_expect_success 'S: notemodify with garbage after inline dataref must fail' '
3076 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3077 commit refs/heads/S
3078 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3079 data <<COMMIT
3080 commit S note dataref inline
3081 COMMIT
3082 N inlineX :302
3083 data <<BLOB
3084 note blob
3085 BLOB
3086 EOF
3087 test_grep "nvalid dataref" err
3088'
3089
3090test_expect_success 'S: notemodify with garbage after sha1 dataref must fail' '
3091 sha1=$(grep :202 marks | cut -d\ -f2) &&
3092 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3093 commit refs/heads/S
3094 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3095 data <<COMMIT
3096 commit S note dataref sha1
3097 COMMIT
3098 N ${sha1}x :302
3099 EOF
3100 test_grep "space after SHA1" err
3101'
3102
3103#
3104# notemodify, mark in commit-ish
3105#
3106test_expect_success 'S: notemodify with garbage after mark commit-ish must fail' '
3107 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3108 commit refs/heads/Snotes
3109 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3110 data <<COMMIT
3111 commit S note commit-ish
3112 COMMIT
3113 N :202 :302x
3114 EOF
3115 test_grep "after mark" err
3116'
3117
3118#
3119# from
3120#
3121test_expect_success 'S: from with garbage after mark must fail' '
3122 test_must_fail \
3123 git fast-import --import-marks=marks --export-marks=marks <<-EOF 2>err &&
3124 commit refs/heads/S2
3125 mark :303
3126 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3127 data <<COMMIT
3128 commit 3
3129 COMMIT
3130 from :301x
3131 M 100644 :403 hello.c
3132 EOF
3133
3134
3135 # go create the commit, need it for merge test
3136 git fast-import --import-marks=marks --export-marks=marks <<-EOF &&
3137 commit refs/heads/S2
3138 mark :303
3139 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3140 data <<COMMIT
3141 commit 3
3142 COMMIT
3143 from :301
3144 M 100644 :403 hello.c
3145 EOF
3146
3147 # now evaluate the error
3148 test_grep "after mark" err
3149'
3150
3151
3152#
3153# merge
3154#
3155test_expect_success 'S: merge with garbage after mark must fail' '
3156 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3157 commit refs/heads/S
3158 mark :304
3159 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3160 data <<COMMIT
3161 merge 4
3162 COMMIT
3163 from :302
3164 merge :303x
3165 M 100644 :403 hello.c
3166 EOF
3167 test_grep "after mark" err
3168'
3169
3170#
3171# tag, from markref
3172#
3173test_expect_success 'S: tag with garbage after mark must fail' '
3174 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3175 tag refs/tags/Stag
3176 from :302x
3177 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3178 data <<TAG
3179 tag S
3180 TAG
3181 EOF
3182 test_grep "after mark" err
3183'
3184
3185#
3186# cat-blob markref
3187#
3188test_expect_success 'S: cat-blob with garbage after mark must fail' '
3189 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3190 cat-blob :403x
3191 EOF
3192 test_grep "after mark" err
3193'
3194
3195#
3196# ls markref
3197#
3198test_expect_success 'S: ls with garbage after mark must fail' '
3199 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3200 ls :302x hello.c
3201 EOF
3202 test_grep "space after mark" err
3203'
3204
3205test_expect_success 'S: ls with garbage after sha1 must fail' '
3206 sha1=$(grep :302 marks | cut -d\ -f2) &&
3207 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
3208 ls ${sha1}x hello.c
3209 EOF
3210 test_grep "space after tree-ish" err
3211'
3212
3213#
3214# Path parsing
3215#
3216# There are two sorts of ways a path can be parsed, depending on whether it is
3217# the last field on the line. Additionally, ls without a <dataref> has a special
3218# case. Test every occurrence of <path> in the grammar against every error case.
3219# Paths for the root (empty strings) are tested elsewhere.
3220#
3221
3222#
3223# Valid paths at the end of a line: filemodify, filedelete, filecopy (dest),
3224# filerename (dest), and ls.
3225#
3226# commit :301 from root -- modify hello.c (for setup)
3227# commit :302 from :301 -- modify $path
3228# commit :303 from :302 -- delete $path
3229# commit :304 from :301 -- copy hello.c $path
3230# commit :305 from :301 -- rename hello.c $path
3231# ls :305 $path
3232#
3233test_path_eol_success () {
3234 local test="$1" path="$2" unquoted_path="$3"
3235 test_expect_success "S: paths at EOL with $test must work" '
3236 test_when_finished "git branch -D S-path-eol" &&
3237
3238 git -c core.protectNTFS=false fast-import --export-marks=marks.out <<-EOF >out 2>err &&
3239 blob
3240 mark :401
3241 data <<BLOB
3242 hello world
3243 BLOB
3244
3245 blob
3246 mark :402
3247 data <<BLOB
3248 hallo welt
3249 BLOB
3250
3251 commit refs/heads/S-path-eol
3252 mark :301
3253 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3254 data <<COMMIT
3255 initial commit
3256 COMMIT
3257 M 100644 :401 hello.c
3258
3259 commit refs/heads/S-path-eol
3260 mark :302
3261 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3262 data <<COMMIT
3263 commit filemodify
3264 COMMIT
3265 from :301
3266 M 100644 :402 $path
3267
3268 commit refs/heads/S-path-eol
3269 mark :303
3270 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3271 data <<COMMIT
3272 commit filedelete
3273 COMMIT
3274 from :302
3275 D $path
3276
3277 commit refs/heads/S-path-eol
3278 mark :304
3279 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3280 data <<COMMIT
3281 commit filecopy dest
3282 COMMIT
3283 from :301
3284 C hello.c $path
3285
3286 commit refs/heads/S-path-eol
3287 mark :305
3288 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3289 data <<COMMIT
3290 commit filerename dest
3291 COMMIT
3292 from :301
3293 R hello.c $path
3294
3295 ls :305 $path
3296 EOF
3297
3298 commit_m=$(grep :302 marks.out | cut -d\ -f2) &&
3299 commit_d=$(grep :303 marks.out | cut -d\ -f2) &&
3300 commit_c=$(grep :304 marks.out | cut -d\ -f2) &&
3301 commit_r=$(grep :305 marks.out | cut -d\ -f2) &&
3302 blob1=$(grep :401 marks.out | cut -d\ -f2) &&
3303 blob2=$(grep :402 marks.out | cut -d\ -f2) &&
3304
3305 (
3306 printf "100644 blob $blob2\t$unquoted_path\n" &&
3307 printf "100644 blob $blob1\thello.c\n"
3308 ) | sort >tree_m.exp &&
3309 git ls-tree $commit_m | sort >tree_m.out &&
3310 test_cmp tree_m.exp tree_m.out &&
3311
3312 printf "100644 blob $blob1\thello.c\n" >tree_d.exp &&
3313 git ls-tree $commit_d >tree_d.out &&
3314 test_cmp tree_d.exp tree_d.out &&
3315
3316 (
3317 printf "100644 blob $blob1\t$unquoted_path\n" &&
3318 printf "100644 blob $blob1\thello.c\n"
3319 ) | sort >tree_c.exp &&
3320 git ls-tree $commit_c | sort >tree_c.out &&
3321 test_cmp tree_c.exp tree_c.out &&
3322
3323 printf "100644 blob $blob1\t$unquoted_path\n" >tree_r.exp &&
3324 git ls-tree $commit_r >tree_r.out &&
3325 test_cmp tree_r.exp tree_r.out &&
3326
3327 test_cmp out tree_r.exp
3328 '
3329}
3330
3331test_path_eol_success 'quoted spaces' '" hello world.c "' ' hello world.c '
3332test_path_eol_success 'unquoted spaces' ' hello world.c ' ' hello world.c '
3333test_path_eol_success 'octal escapes' '"\150\151\056\143"' 'hi.c'
3334
3335#
3336# Valid paths before a space: filecopy (source) and filerename (source).
3337#
3338# commit :301 from root -- modify $path (for setup)
3339# commit :302 from :301 -- copy $path hello2.c
3340# commit :303 from :301 -- rename $path hello2.c
3341#
3342test_path_space_success () {
3343 local test="$1" path="$2" unquoted_path="$3"
3344 test_expect_success "S: paths before space with $test must work" '
3345 test_when_finished "git branch -D S-path-space" &&
3346
3347 git -c core.protectNTFS=false fast-import --export-marks=marks.out <<-EOF 2>err &&
3348 blob
3349 mark :401
3350 data <<BLOB
3351 hello world
3352 BLOB
3353
3354 commit refs/heads/S-path-space
3355 mark :301
3356 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3357 data <<COMMIT
3358 initial commit
3359 COMMIT
3360 M 100644 :401 $path
3361
3362 commit refs/heads/S-path-space
3363 mark :302
3364 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3365 data <<COMMIT
3366 commit filecopy source
3367 COMMIT
3368 from :301
3369 C $path hello2.c
3370
3371 commit refs/heads/S-path-space
3372 mark :303
3373 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3374 data <<COMMIT
3375 commit filerename source
3376 COMMIT
3377 from :301
3378 R $path hello2.c
3379
3380 EOF
3381
3382 commit_c=$(grep :302 marks.out | cut -d\ -f2) &&
3383 commit_r=$(grep :303 marks.out | cut -d\ -f2) &&
3384 blob=$(grep :401 marks.out | cut -d\ -f2) &&
3385
3386 (
3387 printf "100644 blob $blob\t$unquoted_path\n" &&
3388 printf "100644 blob $blob\thello2.c\n"
3389 ) | sort >tree_c.exp &&
3390 git ls-tree $commit_c | sort >tree_c.out &&
3391 test_cmp tree_c.exp tree_c.out &&
3392
3393 printf "100644 blob $blob\thello2.c\n" >tree_r.exp &&
3394 git ls-tree $commit_r >tree_r.out &&
3395 test_cmp tree_r.exp tree_r.out
3396 '
3397}
3398
3399test_path_space_success 'quoted spaces' '" hello world.c "' ' hello world.c '
3400test_path_space_success 'no unquoted spaces' 'hello_world.c' 'hello_world.c'
3401test_path_space_success 'octal escapes' '"\150\151\056\143"' 'hi.c'
3402
3403#
3404# Test a single commit change with an invalid path. Run it with all occurrences
3405# of <path> in the grammar against all error kinds.
3406#
3407test_path_fail () {
3408 local change="$1" what="$2" prefix="$3" path="$4" suffix="$5" err_grep="$6"
3409 test_expect_success "S: $change with $what must fail" '
3410 test_must_fail git fast-import <<-EOF 2>err &&
3411 blob
3412 mark :1
3413 data <<BLOB
3414 hello world
3415 BLOB
3416
3417 commit refs/heads/S-path-fail
3418 mark :2
3419 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3420 data <<COMMIT
3421 commit setup
3422 COMMIT
3423 M 100644 :1 hello.c
3424
3425 commit refs/heads/S-path-fail
3426 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3427 data <<COMMIT
3428 commit with bad path
3429 COMMIT
3430 from :2
3431 $prefix$path$suffix
3432 EOF
3433
3434 test_grep "$err_grep" err
3435 '
3436}
3437
3438test_path_base_fail () {
3439 local change="$1" prefix="$2" field="$3" suffix="$4"
3440 test_path_fail "$change" 'unclosed " in '"$field" "$prefix" '"hello.c' "$suffix" "invalid $field"
3441 test_path_fail "$change" "invalid escape in quoted $field" "$prefix" '"hello\xff"' "$suffix" "invalid $field"
3442 test_path_fail "$change" "escaped NUL in quoted $field" "$prefix" '"hello\000"' "$suffix" "NUL in $field"
3443}
3444test_path_eol_quoted_fail () {
3445 local change="$1" prefix="$2" field="$3"
3446 test_path_base_fail "$change" "$prefix" "$field" ''
3447 test_path_fail "$change" "garbage after quoted $field" "$prefix" '"hello.c"' 'x' "garbage after $field"
3448 test_path_fail "$change" "space after quoted $field" "$prefix" '"hello.c"' ' ' "garbage after $field"
3449}
3450test_path_eol_fail () {
3451 local change="$1" prefix="$2" field="$3"
3452 test_path_eol_quoted_fail "$change" "$prefix" "$field"
3453}
3454test_path_space_fail () {
3455 local change="$1" prefix="$2" field="$3"
3456 test_path_base_fail "$change" "$prefix" "$field" ' world.c'
3457 test_path_fail "$change" "missing space after quoted $field" "$prefix" '"hello.c"' 'x world.c' "missing space after $field"
3458 test_path_fail "$change" "missing space after unquoted $field" "$prefix" 'hello.c' '' "missing space after $field"
3459}
3460
3461test_path_eol_fail filemodify 'M 100644 :1 ' path
3462test_path_eol_fail filedelete 'D ' path
3463test_path_space_fail filecopy 'C ' source
3464test_path_eol_fail filecopy 'C hello.c ' dest
3465test_path_space_fail filerename 'R ' source
3466test_path_eol_fail filerename 'R hello.c ' dest
3467test_path_eol_fail 'ls (in commit)' 'ls :2 ' path
3468
3469# When 'ls' has no <dataref>, the <path> must be quoted.
3470test_path_eol_quoted_fail 'ls (without dataref in commit)' 'ls ' path
3471
3472###
3473### series T (ls)
3474###
3475# Setup is carried over from series S.
3476
3477for root in '""' ''
3478do
3479 test_expect_success "T: ls root ($root) tree" '
3480 sed -e "s/Z\$//" >expect <<-EOF &&
3481 040000 tree $(git rev-parse S^{tree}) Z
3482 EOF
3483 sha1=$(git rev-parse --verify S) &&
3484 git fast-import --import-marks=marks <<-EOF >actual &&
3485 ls $sha1 $root
3486 EOF
3487 test_cmp expect actual
3488 '
3489done
3490
3491test_expect_success 'T: delete branch' '
3492 git branch to-delete &&
3493 git fast-import <<-EOF &&
3494 reset refs/heads/to-delete
3495 from $ZERO_OID
3496 EOF
3497 test_must_fail git rev-parse --verify refs/heads/to-delete
3498'
3499
3500test_expect_success 'T: empty reset doesnt delete branch' '
3501 git branch not-to-delete &&
3502 git fast-import <<-EOF &&
3503 reset refs/heads/not-to-delete
3504 EOF
3505 git show-ref &&
3506 git rev-parse --verify refs/heads/not-to-delete
3507'
3508
3509###
3510### series U (filedelete)
3511###
3512
3513test_expect_success 'U: initialize for U tests' '
3514 cat >input <<-INPUT_END &&
3515 commit refs/heads/U
3516 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3517 data <<COMMIT
3518 test setup
3519 COMMIT
3520 M 100644 inline hello.c
3521 data <<BLOB
3522 blob 1
3523 BLOB
3524 M 100644 inline good/night.txt
3525 data <<BLOB
3526 sleep well
3527 BLOB
3528 M 100644 inline good/bye.txt
3529 data <<BLOB
3530 au revoir
3531 BLOB
3532
3533 INPUT_END
3534
3535 f7id=$(echo "blob 1" | git hash-object --stdin) &&
3536 f8id=$(echo "sleep well" | git hash-object --stdin) &&
3537 f9id=$(echo "au revoir" | git hash-object --stdin) &&
3538 git fast-import <input
3539'
3540
3541test_expect_success 'U: filedelete file succeeds' '
3542 cat >input <<-INPUT_END &&
3543 commit refs/heads/U
3544 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3545 data <<COMMIT
3546 delete good/night.txt
3547 COMMIT
3548 from refs/heads/U^0
3549 D good/night.txt
3550
3551 INPUT_END
3552
3553 git fast-import <input
3554'
3555
3556test_expect_success 'U: validate file delete result' '
3557 cat >expect <<-EOF &&
3558 :100644 000000 $f8id $ZERO_OID D good/night.txt
3559 EOF
3560
3561 git diff-tree -M -r U^1 U >actual &&
3562
3563 compare_diff_raw expect actual
3564'
3565
3566test_expect_success 'U: filedelete directory succeeds' '
3567 cat >input <<-INPUT_END &&
3568 commit refs/heads/U
3569 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3570 data <<COMMIT
3571 delete good dir
3572 COMMIT
3573 from refs/heads/U^0
3574 D good
3575
3576 INPUT_END
3577
3578 git fast-import <input
3579'
3580
3581test_expect_success 'U: validate directory delete result' '
3582 cat >expect <<-EOF &&
3583 :100644 000000 $f9id $ZERO_OID D good/bye.txt
3584 EOF
3585
3586 git diff-tree -M -r U^1 U >actual &&
3587
3588 compare_diff_raw expect actual
3589'
3590
3591for root in '""' ''
3592do
3593 test_expect_success "U: filedelete root ($root) succeeds" '
3594 cat >input <<-INPUT_END &&
3595 commit refs/heads/U-delete-root
3596 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3597 data <<COMMIT
3598 must succeed
3599 COMMIT
3600 from refs/heads/U^0
3601 D $root
3602
3603 INPUT_END
3604
3605 git fast-import <input
3606 '
3607
3608 test_expect_success "U: validate root ($root) delete result" '
3609 cat >expect <<-EOF &&
3610 :100644 000000 $f7id $ZERO_OID D hello.c
3611 EOF
3612
3613 git diff-tree -M -r U U-delete-root >actual &&
3614
3615 compare_diff_raw expect actual
3616 '
3617done
3618
3619###
3620### series V (checkpoint)
3621###
3622
3623# The commands in input_file should not produce any output on the file
3624# descriptor set with --cat-blob-fd (or stdout if unspecified).
3625#
3626# To make sure you're observing the side effects of checkpoint *before*
3627# fast-import terminates (and thus writes out its state), check that the
3628# fast-import process is still running using background_import_still_running
3629# *after* evaluating the test conditions.
3630background_import_then_checkpoint () {
3631 options=$1
3632 input_file=$2
3633
3634 mkfifo V.input
3635 exec 8<>V.input
3636 rm V.input
3637
3638 mkfifo V.output
3639 exec 9<>V.output
3640 rm V.output
3641
3642 (
3643 git fast-import $options <&8 >&9 &
3644 echo $! >&9
3645 wait $!
3646 echo >&2 "background fast-import terminated too early with exit code $?"
3647 # Un-block the read loop in the main shell process.
3648 echo >&9 UNEXPECTED
3649 ) &
3650 sh_pid=$!
3651 read fi_pid <&9
3652 # We don't mind if fast-import has already died by the time the test
3653 # ends.
3654 test_when_finished "
3655 exec 8>&-; exec 9>&-;
3656 kill $sh_pid && wait $sh_pid
3657 kill $fi_pid && wait $fi_pid
3658 true"
3659
3660 # Start in the background to ensure we adhere strictly to (blocking)
3661 # pipes writing sequence. We want to assume that the write below could
3662 # block, e.g. if fast-import blocks writing its own output to &9
3663 # because there is no reader on &9 yet.
3664 (
3665 cat "$input_file"
3666 echo "checkpoint"
3667 echo "progress checkpoint"
3668 ) >&8 &
3669
3670 last=$(
3671 while read output <&9
3672 do
3673 if test "$output" = "progress checkpoint" || test "$output" = "UNEXPECTED"
3674 then
3675 echo "$output"
3676 break
3677 else
3678 # otherwise ignore cruft
3679 echo >&2 "cruft: $output"
3680 fi
3681 done
3682 )
3683
3684 test "$last" = "progress checkpoint"
3685}
3686
3687background_import_still_running () {
3688 if ! kill -0 "$fi_pid"
3689 then
3690 echo >&2 "background fast-import terminated too early"
3691 false
3692 fi
3693}
3694
3695test_expect_success PIPE 'V: checkpoint helper does not get stuck with extra output' '
3696 cat >input <<-INPUT_END &&
3697 progress foo
3698 progress bar
3699
3700 INPUT_END
3701
3702 background_import_then_checkpoint "" input &&
3703 background_import_still_running
3704'
3705
3706test_expect_success PIPE 'V: checkpoint updates refs after reset' '
3707 cat >input <<-\INPUT_END &&
3708 reset refs/heads/V
3709 from refs/heads/U
3710
3711 INPUT_END
3712
3713 background_import_then_checkpoint "" input &&
3714 test "$(git rev-parse --verify V)" = "$(git rev-parse --verify U)" &&
3715 background_import_still_running
3716'
3717
3718test_expect_success PIPE 'V: checkpoint updates refs and marks after commit' '
3719 cat >input <<-INPUT_END &&
3720 commit refs/heads/V
3721 mark :1
3722 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3723 data 0
3724 from refs/heads/U
3725
3726 INPUT_END
3727
3728 background_import_then_checkpoint "--export-marks=marks.actual" input &&
3729
3730 echo ":1 $(git rev-parse --verify V)" >marks.expected &&
3731
3732 test "$(git rev-parse --verify V^)" = "$(git rev-parse --verify U)" &&
3733 test_cmp marks.expected marks.actual &&
3734 background_import_still_running
3735'
3736
3737# Re-create the exact same commit, but on a different branch: no new object is
3738# created in the database, but the refs and marks still need to be updated.
3739test_expect_success PIPE 'V: checkpoint updates refs and marks after commit (no new objects)' '
3740 cat >input <<-INPUT_END &&
3741 commit refs/heads/V2
3742 mark :2
3743 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3744 data 0
3745 from refs/heads/U
3746
3747 INPUT_END
3748
3749 background_import_then_checkpoint "--export-marks=marks.actual" input &&
3750
3751 echo ":2 $(git rev-parse --verify V2)" >marks.expected &&
3752
3753 test "$(git rev-parse --verify V2)" = "$(git rev-parse --verify V)" &&
3754 test_cmp marks.expected marks.actual &&
3755 background_import_still_running
3756'
3757
3758test_expect_success PIPE 'V: checkpoint updates tags after tag' '
3759 cat >input <<-INPUT_END &&
3760 tag Vtag
3761 from refs/heads/V
3762 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3763 data 0
3764
3765 INPUT_END
3766
3767 background_import_then_checkpoint "" input &&
3768 git show-ref -d Vtag &&
3769 background_import_still_running
3770'
3771
3772###
3773### series W (get-mark and empty orphan commits)
3774###
3775
3776cat >>W-input <<-W_INPUT_END
3777 commit refs/heads/W-branch
3778 mark :1
3779 author Full Name <user@company.tld> 1000000000 +0100
3780 committer Full Name <user@company.tld> 1000000000 +0100
3781 data 27
3782 Intentionally empty commit
3783 LFsget-mark :1
3784 W_INPUT_END
3785
3786test_expect_success !MINGW 'W: get-mark & empty orphan commit with no newlines' '
3787 sed -e s/LFs// W-input | tr L "\n" | git fast-import
3788'
3789
3790test_expect_success !MINGW 'W: get-mark & empty orphan commit with one newline' '
3791 sed -e s/LFs/L/ W-input | tr L "\n" | git fast-import
3792'
3793
3794test_expect_success !MINGW 'W: get-mark & empty orphan commit with ugly second newline' '
3795 # Technically, this should fail as it has too many linefeeds
3796 # according to the grammar in fast-import.txt. But, for whatever
3797 # reason, it works. Since using the correct number of newlines
3798 # does not work with older (pre-2.22) versions of git, allow apps
3799 # that used this second-newline workaround to keep working by
3800 # checking it with this test...
3801 sed -e s/LFs/LL/ W-input | tr L "\n" | git fast-import
3802'
3803
3804test_expect_success !MINGW 'W: get-mark & empty orphan commit with erroneous third newline' '
3805 # ...but do NOT allow more empty lines than that (see previous test).
3806 sed -e s/LFs/LLL/ W-input | tr L "\n" | test_must_fail git fast-import
3807'
3808
3809###
3810### series X (other new features)
3811###
3812
3813test_expect_success ICONV 'X: handling encoding' '
3814 test_tick &&
3815 cat >input <<-INPUT_END &&
3816 commit refs/heads/encoding
3817 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3818 encoding iso-8859-7
3819 data <<COMMIT
3820 INPUT_END
3821
3822 printf "Pi: \360\nCOMMIT\n" >>input &&
3823
3824 git fast-import <input &&
3825 git cat-file -p encoding | grep $(printf "\360") &&
3826 git log -1 --format=%B encoding | grep $(printf "\317\200")
3827'
3828
3829test_expect_success 'X: replace ref that becomes useless is removed' '
3830 git init -qb main testrepo &&
3831 cd testrepo &&
3832 (
3833 test_commit test &&
3834
3835 test_commit msg somename content &&
3836
3837 git mv somename othername &&
3838 NEW_TREE=$(git write-tree) &&
3839 MSG="$(git log -1 --format=%B HEAD)" &&
3840 NEW_COMMIT=$(git commit-tree -p HEAD^1 -m "$MSG" $NEW_TREE) &&
3841 git replace main $NEW_COMMIT &&
3842
3843 echo more >>othername &&
3844 git add othername &&
3845 git commit -qm more &&
3846
3847 git fast-export --all >tmp &&
3848 sed -e s/othername/somename/ tmp >tmp2 &&
3849 git fast-import --force <tmp2 2>msgs &&
3850
3851 test_grep "dropping.*since it would point to itself" msgs &&
3852 git show-ref >refs &&
3853 test_grep ! refs/replace refs
3854 )
3855'
3856
3857###
3858### series Y (submodules and hash algorithms)
3859###
3860
3861cat >Y-sub-input <<\Y_INPUT_END
3862blob
3863mark :1
3864data 4
3865foo
3866
3867reset refs/heads/main
3868commit refs/heads/main
3869mark :2
3870author Full Name <user@company.tld> 1000000000 +0100
3871committer Full Name <user@company.tld> 1000000000 +0100
3872data 24
3873Test submodule commit 1
3874M 100644 :1 file
3875
3876blob
3877mark :3
3878data 8
3879foo
3880bar
3881
3882commit refs/heads/main
3883mark :4
3884author Full Name <user@company.tld> 1000000001 +0100
3885committer Full Name <user@company.tld> 1000000001 +0100
3886data 24
3887Test submodule commit 2
3888from :2
3889M 100644 :3 file
3890Y_INPUT_END
3891
3892# Note that the submodule object IDs are intentionally not translated.
3893cat >Y-main-input <<\Y_INPUT_END
3894blob
3895mark :1
3896data 4
3897foo
3898
3899reset refs/heads/main
3900commit refs/heads/main
3901mark :2
3902author Full Name <user@company.tld> 2000000000 +0100
3903committer Full Name <user@company.tld> 2000000000 +0100
3904data 14
3905Test commit 1
3906M 100644 :1 file
3907
3908blob
3909mark :3
3910data 73
3911[submodule "sub1"]
3912 path = sub1
3913 url = https://void.example.com/main.git
3914
3915commit refs/heads/main
3916mark :4
3917author Full Name <user@company.tld> 2000000001 +0100
3918committer Full Name <user@company.tld> 2000000001 +0100
3919data 14
3920Test commit 2
3921from :2
3922M 100644 :3 .gitmodules
3923M 160000 0712c5be7cf681388e355ef47525aaf23aee1a6d sub1
3924
3925blob
3926mark :5
3927data 8
3928foo
3929bar
3930
3931commit refs/heads/main
3932mark :6
3933author Full Name <user@company.tld> 2000000002 +0100
3934committer Full Name <user@company.tld> 2000000002 +0100
3935data 14
3936Test commit 3
3937from :4
3938M 100644 :5 file
3939M 160000 ff729f5e62f72c0c3978207d9a80e5f3a65f14d7 sub1
3940Y_INPUT_END
3941
3942cat >Y-marks <<\Y_INPUT_END
3943:2 0712c5be7cf681388e355ef47525aaf23aee1a6d
3944:4 ff729f5e62f72c0c3978207d9a80e5f3a65f14d7
3945Y_INPUT_END
3946
3947test_expect_success 'Y: setup' '
3948 test_oid_cache <<-EOF
3949 Ymain sha1:9afed2f9161ddf416c0a1863b8b0725b00070504
3950 Ymain sha256:c0a1010da1df187b2e287654793df01b464bd6f8e3f17fc1481a7dadf84caee3
3951 EOF
3952'
3953
3954test_expect_success 'Y: rewrite-submodules-to feature forbidden by default' '
3955 echo "feature rewrite-submodules-to=sub:sub2-marks" >input &&
3956 test_must_fail git fast-import <input 2>err &&
3957 test_grep "feature ${SQ}rewrite-submodules-to${SQ} forbidden in input without --allow-unsafe-features" err
3958'
3959
3960test_expect_success 'Y: rewrite-submodules-from feature forbidden by default' '
3961 echo "feature rewrite-submodules-from=sub:../Y-marks" >input &&
3962 test_must_fail git fast-import <input 2>err &&
3963 test_grep "feature ${SQ}rewrite-submodules-from${SQ} forbidden in input without --allow-unsafe-features" err
3964'
3965
3966test_expect_success 'Y: rewrite submodules' '
3967 test_when_finished "rm -rf main1" &&
3968 git init main1 &&
3969 (
3970 cd main1 &&
3971 git init sub2 &&
3972 git -C sub2 fast-import --export-marks=../sub2-marks <../Y-sub-input &&
3973 git fast-import --rewrite-submodules-from=sub:../Y-marks \
3974 --rewrite-submodules-to=sub:sub2-marks <../Y-main-input &&
3975 test "$(git rev-parse main)" = "$(test_oid Ymain)"
3976 )
3977'
3978
3979test_expect_success 'Y: reference pending tag or commit' '
3980 test_oid_cache <<-EOF &&
3981 pending_commit sha1:85b46dd918355ff17b4109ec738723d42f235a04
3982 pending_commit sha256:17e650f097a4db6fe069c96935360d3ccc9b35c4018728c5f311a4217c2ced3d
3983 pending_tag sha1:ec6c4db71feb5f66615214dad2324ce030e777a7
3984 pending_tag sha256:85edc5eac315bc680677b2fc71622bd77476f057eb8dc8ed6a497803a24f1f46
3985 EOF
3986
3987 git init reference-pending &&
3988 (
3989 cd reference-pending &&
3990 git fast-import <<-EOF
3991 commit refs/heads/main
3992 committer A U Thor <author@example.com> 1712563200 +0000
3993 data 14
3994 commit message
3995 M 644 inline test file
3996 data 14
3997 dummy content
3998
3999 tag newtag
4000 from $(test_oid pending_commit)
4001 tagger A U Thor <author@example.com> 1712563300 +0000
4002 data 11
4003 tag message
4004 # no emty line after tag data!
4005 reset refs/heads/other
4006 from $(test_oid pending_tag)
4007
4008 commit refs/heads/further
4009 committer A U Thor <author@example.com> 1712563400 +0000
4010 data 21
4011 what about 2nd commit
4012 from $(test_oid pending_commit)
4013 M 644 inline other test file
4014 data 19
4015 more dummy content
4016
4017 done
4018 EOF
4019 )
4020'
4021
4022test_expect_success 'Y: rewrite submodules via stdin' '
4023 test_when_finished "rm -rf main1" &&
4024 git init main1 &&
4025 (
4026 cd main1 &&
4027 git init sub2 &&
4028 git -C sub2 fast-import --export-marks=../sub2-marks <../Y-sub-input &&
4029 {
4030 echo "feature rewrite-submodules-to=sub:sub2-marks" &&
4031 echo "feature rewrite-submodules-from=sub:../Y-marks" &&
4032 cat ../Y-main-input
4033 } | git fast-import --allow-unsafe-features &&
4034 test "$(git rev-parse main)" = "$(test_oid Ymain)"
4035 )
4036'
4037
4038test_done