fast-import: add tests for tagging blobs
[git/mingw.git] / t / t9300-fast-import.sh
blob80b06f0714cb56610502556669190b1475c4dbe1
1 #!/bin/sh
3 # Copyright (c) 2007 Shawn Pearce
6 test_description='test git fast-import utility'
7 . ./test-lib.sh
8 . "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
10 # Print $1 bytes from stdin to stdout.
12 # This could be written as "head -c $1", but IRIX "head" does not
13 # support the -c option.
14 head_c () {
15 perl -e '
16 my $len = $ARGV[1];
17 while ($len > 0) {
18 my $s;
19 my $nread = sysread(STDIN, $s, $len);
20 die "cannot read: $!" unless defined($nread);
21 print $s;
22 $len -= $nread;
24 ' - "$1"
27 file2_data='file2
28 second line of EOF'
30 file3_data='EOF
31 in 3rd file
32 END'
34 file4_data=abcd
35 file4_len=4
37 file5_data='an inline file.
38 we should see it later.'
40 file6_data='#!/bin/sh
41 echo "$@"'
43 >empty
45 test_expect_success 'setup: have pipes?' '
46 rm -f frob &&
47 if mkfifo frob
48 then
49 test_set_prereq PIPE
53 ###
54 ### series A
55 ###
57 test_tick
59 test_expect_success 'empty stream succeeds' '
60 git fast-import </dev/null
63 cat >input <<INPUT_END
64 blob
65 mark :2
66 data <<EOF
67 $file2_data
68 EOF
70 blob
71 mark :3
72 data <<END
73 $file3_data
74 END
76 blob
77 mark :4
78 data $file4_len
79 $file4_data
80 commit refs/heads/master
81 mark :5
82 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
83 data <<COMMIT
84 initial
85 COMMIT
87 M 644 :2 file2
88 M 644 :3 file3
89 M 755 :4 file4
91 tag series-A
92 from :5
93 data <<EOF
94 An annotated tag without a tagger
95 EOF
97 tag series-A-blob
98 from :3
99 data <<EOF
100 An annotated tag that annotates a blob.
103 INPUT_END
104 test_expect_success \
105 'A: create pack from stdin' \
106 'git fast-import --export-marks=marks.out <input &&
107 git whatchanged master'
108 test_expect_success \
109 'A: verify pack' \
110 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
112 cat >expect <<EOF
113 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
114 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
116 initial
118 test_expect_success \
119 'A: verify commit' \
120 'git cat-file commit master | sed 1d >actual &&
121 test_cmp expect actual'
123 cat >expect <<EOF
124 100644 blob file2
125 100644 blob file3
126 100755 blob file4
128 test_expect_success \
129 'A: verify tree' \
130 'git cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
131 test_cmp expect actual'
133 echo "$file2_data" >expect
134 test_expect_success \
135 'A: verify file2' \
136 'git cat-file blob master:file2 >actual && test_cmp expect actual'
138 echo "$file3_data" >expect
139 test_expect_success \
140 'A: verify file3' \
141 'git cat-file blob master:file3 >actual && test_cmp expect actual'
143 printf "$file4_data" >expect
144 test_expect_success \
145 'A: verify file4' \
146 'git cat-file blob master:file4 >actual && test_cmp expect actual'
148 cat >expect <<EOF
149 object $(git rev-parse refs/heads/master)
150 type commit
151 tag series-A
153 An annotated tag without a tagger
155 test_expect_success 'A: verify tag/series-A' '
156 git cat-file tag tags/series-A >actual &&
157 test_cmp expect actual
160 cat >expect <<EOF
161 object $(git rev-parse refs/heads/master:file3)
162 type blob
163 tag series-A-blob
165 An annotated tag that annotates a blob.
167 test_expect_success 'A: verify tag/series-A-blob' '
168 git cat-file tag tags/series-A-blob >actual &&
169 test_cmp expect actual
172 cat >expect <<EOF
173 :2 `git rev-parse --verify master:file2`
174 :3 `git rev-parse --verify master:file3`
175 :4 `git rev-parse --verify master:file4`
176 :5 `git rev-parse --verify master^0`
178 test_expect_success \
179 'A: verify marks output' \
180 'test_cmp expect marks.out'
182 test_expect_success \
183 'A: verify marks import' \
184 'git fast-import \
185 --import-marks=marks.out \
186 --export-marks=marks.new \
187 </dev/null &&
188 test_cmp expect marks.new'
190 test_tick
191 cat >input <<INPUT_END
192 tag series-A-blob-2
193 from $(git rev-parse refs/heads/master:file3)
194 data <<EOF
195 Tag blob by sha1.
197 INPUT_END
199 cat >expect <<EOF
200 object $(git rev-parse refs/heads/master:file3)
201 type blob
202 tag series-A-blob-2
204 Tag blob by sha1.
207 test_expect_success \
208 'A: tag blob by sha1' \
209 'git fast-import <input &&
210 git cat-file tag tags/series-A-blob-2 >actual &&
211 test_cmp expect actual'
213 test_tick
214 cat >input <<INPUT_END
215 commit refs/heads/verify--import-marks
216 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
217 data <<COMMIT
218 recreate from :5
219 COMMIT
221 from :5
222 M 755 :2 copy-of-file2
224 INPUT_END
225 test_expect_success \
226 'A: verify marks import does not crash' \
227 'git fast-import --import-marks=marks.out <input &&
228 git whatchanged verify--import-marks'
229 test_expect_success \
230 'A: verify pack' \
231 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
232 cat >expect <<EOF
233 :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2
235 git diff-tree -M -r master verify--import-marks >actual
236 test_expect_success \
237 'A: verify diff' \
238 'compare_diff_raw expect actual &&
239 test `git rev-parse --verify master:file2` \
240 = `git rev-parse --verify verify--import-marks:copy-of-file2`'
242 test_tick
243 mt=$(git hash-object --stdin < /dev/null)
244 : >input.blob
245 : >marks.exp
246 : >tree.exp
248 cat >input.commit <<EOF
249 commit refs/heads/verify--dump-marks
250 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
251 data <<COMMIT
252 test the sparse array dumping routines with exponentially growing marks
253 COMMIT
260 while test "$i" -lt 27; do
261 cat >>input.blob <<EOF
262 blob
263 mark :$l
264 data 0
265 blob
266 mark :$m
267 data 0
268 blob
269 mark :$n
270 data 0
272 echo "M 100644 :$l l$i" >>input.commit
273 echo "M 100644 :$m m$i" >>input.commit
274 echo "M 100644 :$n n$i" >>input.commit
276 echo ":$l $mt" >>marks.exp
277 echo ":$m $mt" >>marks.exp
278 echo ":$n $mt" >>marks.exp
280 printf "100644 blob $mt\tl$i\n" >>tree.exp
281 printf "100644 blob $mt\tm$i\n" >>tree.exp
282 printf "100644 blob $mt\tn$i\n" >>tree.exp
284 l=$(($l + $l))
285 m=$(($m + $m))
286 n=$(($l + $n))
288 i=$((1 + $i))
289 done
291 sort tree.exp > tree.exp_s
293 test_expect_success 'A: export marks with large values' '
294 cat input.blob input.commit | git fast-import --export-marks=marks.large &&
295 git ls-tree refs/heads/verify--dump-marks >tree.out &&
296 test_cmp tree.exp_s tree.out &&
297 test_cmp marks.exp marks.large'
300 ### series B
303 test_tick
304 cat >input <<INPUT_END
305 commit refs/heads/branch
306 mark :1
307 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
308 data <<COMMIT
309 corrupt
310 COMMIT
312 from refs/heads/master
313 M 755 0000000000000000000000000000000000000001 zero1
315 INPUT_END
316 test_expect_success 'B: fail on invalid blob sha1' '
317 test_must_fail git fast-import <input
319 rm -f .git/objects/pack_* .git/objects/index_*
321 cat >input <<INPUT_END
322 commit .badbranchname
323 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
324 data <<COMMIT
325 corrupt
326 COMMIT
328 from refs/heads/master
330 INPUT_END
331 test_expect_success 'B: fail on invalid branch name ".badbranchname"' '
332 test_must_fail git fast-import <input
334 rm -f .git/objects/pack_* .git/objects/index_*
336 cat >input <<INPUT_END
337 commit bad[branch]name
338 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
339 data <<COMMIT
340 corrupt
341 COMMIT
343 from refs/heads/master
345 INPUT_END
346 test_expect_success 'B: fail on invalid branch name "bad[branch]name"' '
347 test_must_fail git fast-import <input
349 rm -f .git/objects/pack_* .git/objects/index_*
351 cat >input <<INPUT_END
352 commit TEMP_TAG
353 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
354 data <<COMMIT
355 tag base
356 COMMIT
358 from refs/heads/master
360 INPUT_END
361 test_expect_success \
362 'B: accept branch name "TEMP_TAG"' \
363 'git fast-import <input &&
364 test -f .git/TEMP_TAG &&
365 test `git rev-parse master` = `git rev-parse TEMP_TAG^`'
366 rm -f .git/TEMP_TAG
369 ### series C
372 newf=`echo hi newf | git hash-object -w --stdin`
373 oldf=`git rev-parse --verify master:file2`
374 test_tick
375 cat >input <<INPUT_END
376 commit refs/heads/branch
377 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
378 data <<COMMIT
379 second
380 COMMIT
382 from refs/heads/master
383 M 644 $oldf file2/oldf
384 M 755 $newf file2/newf
385 D file3
387 INPUT_END
388 test_expect_success \
389 'C: incremental import create pack from stdin' \
390 'git fast-import <input &&
391 git whatchanged branch'
392 test_expect_success \
393 'C: verify pack' \
394 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
395 test_expect_success \
396 'C: validate reuse existing blob' \
397 'test $newf = `git rev-parse --verify branch:file2/newf` &&
398 test $oldf = `git rev-parse --verify branch:file2/oldf`'
400 cat >expect <<EOF
401 parent `git rev-parse --verify master^0`
402 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
403 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
405 second
407 test_expect_success \
408 'C: verify commit' \
409 'git cat-file commit branch | sed 1d >actual &&
410 test_cmp expect actual'
412 cat >expect <<EOF
413 :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
414 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
415 :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
417 git diff-tree -M -r master branch >actual
418 test_expect_success \
419 'C: validate rename result' \
420 'compare_diff_raw expect actual'
423 ### series D
426 test_tick
427 cat >input <<INPUT_END
428 commit refs/heads/branch
429 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
430 data <<COMMIT
431 third
432 COMMIT
434 from refs/heads/branch^0
435 M 644 inline newdir/interesting
436 data <<EOF
437 $file5_data
440 M 755 inline newdir/exec.sh
441 data <<EOF
442 $file6_data
445 INPUT_END
446 test_expect_success \
447 'D: inline data in commit' \
448 'git fast-import <input &&
449 git whatchanged branch'
450 test_expect_success \
451 'D: verify pack' \
452 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
454 cat >expect <<EOF
455 :000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A newdir/exec.sh
456 :000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A newdir/interesting
458 git diff-tree -M -r branch^ branch >actual
459 test_expect_success \
460 'D: validate new files added' \
461 'compare_diff_raw expect actual'
463 echo "$file5_data" >expect
464 test_expect_success \
465 'D: verify file5' \
466 'git cat-file blob branch:newdir/interesting >actual &&
467 test_cmp expect actual'
469 echo "$file6_data" >expect
470 test_expect_success \
471 'D: verify file6' \
472 'git cat-file blob branch:newdir/exec.sh >actual &&
473 test_cmp expect actual'
476 ### series E
479 cat >input <<INPUT_END
480 commit refs/heads/branch
481 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
482 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
483 data <<COMMIT
484 RFC 2822 type date
485 COMMIT
487 from refs/heads/branch^0
489 INPUT_END
490 test_expect_success 'E: rfc2822 date, --date-format=raw' '
491 test_must_fail git fast-import --date-format=raw <input
493 test_expect_success \
494 'E: rfc2822 date, --date-format=rfc2822' \
495 'git fast-import --date-format=rfc2822 <input'
496 test_expect_success \
497 'E: verify pack' \
498 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
500 cat >expect <<EOF
501 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
502 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
504 RFC 2822 type date
506 test_expect_success \
507 'E: verify commit' \
508 'git cat-file commit branch | sed 1,2d >actual &&
509 test_cmp expect actual'
512 ### series F
515 old_branch=`git rev-parse --verify branch^0`
516 test_tick
517 cat >input <<INPUT_END
518 commit refs/heads/branch
519 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
520 data <<COMMIT
521 losing things already?
522 COMMIT
524 from refs/heads/branch~1
526 reset refs/heads/other
527 from refs/heads/branch
529 INPUT_END
530 test_expect_success \
531 'F: non-fast-forward update skips' \
532 'if git fast-import <input
533 then
534 echo BAD gfi did not fail
535 return 1
536 else
537 if test $old_branch = `git rev-parse --verify branch^0`
538 then
539 : branch unaffected and failure returned
540 return 0
541 else
542 echo BAD gfi changed branch $old_branch
543 return 1
547 test_expect_success \
548 'F: verify pack' \
549 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
551 cat >expect <<EOF
552 tree `git rev-parse branch~1^{tree}`
553 parent `git rev-parse branch~1`
554 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
555 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
557 losing things already?
559 test_expect_success \
560 'F: verify other commit' \
561 'git cat-file commit other >actual &&
562 test_cmp expect actual'
565 ### series G
568 old_branch=`git rev-parse --verify branch^0`
569 test_tick
570 cat >input <<INPUT_END
571 commit refs/heads/branch
572 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
573 data <<COMMIT
574 losing things already?
575 COMMIT
577 from refs/heads/branch~1
579 INPUT_END
580 test_expect_success \
581 'G: non-fast-forward update forced' \
582 'git fast-import --force <input'
583 test_expect_success \
584 'G: verify pack' \
585 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
586 test_expect_success \
587 'G: branch changed, but logged' \
588 'test $old_branch != `git rev-parse --verify branch^0` &&
589 test $old_branch = `git rev-parse --verify branch@{1}`'
592 ### series H
595 test_tick
596 cat >input <<INPUT_END
597 commit refs/heads/H
598 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
599 data <<COMMIT
600 third
601 COMMIT
603 from refs/heads/branch^0
604 M 644 inline i-will-die
605 data <<EOF
606 this file will never exist.
609 deleteall
610 M 644 inline h/e/l/lo
611 data <<EOF
612 $file5_data
615 INPUT_END
616 test_expect_success \
617 'H: deletall, add 1' \
618 'git fast-import <input &&
619 git whatchanged H'
620 test_expect_success \
621 'H: verify pack' \
622 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
624 cat >expect <<EOF
625 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf
626 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf
627 :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4
628 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo
629 :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh
631 git diff-tree -M -r H^ H >actual
632 test_expect_success \
633 'H: validate old files removed, new files added' \
634 'compare_diff_raw expect actual'
636 echo "$file5_data" >expect
637 test_expect_success \
638 'H: verify file' \
639 'git cat-file blob H:h/e/l/lo >actual &&
640 test_cmp expect actual'
643 ### series I
646 cat >input <<INPUT_END
647 commit refs/heads/export-boundary
648 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
649 data <<COMMIT
650 we have a border. its only 40 characters wide.
651 COMMIT
653 from refs/heads/branch
655 INPUT_END
656 test_expect_success \
657 'I: export-pack-edges' \
658 'git fast-import --export-pack-edges=edges.list <input'
660 cat >expect <<EOF
661 .git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
663 test_expect_success \
664 'I: verify edge list' \
665 'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
666 test_cmp expect actual'
669 ### series J
672 cat >input <<INPUT_END
673 commit refs/heads/J
674 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
675 data <<COMMIT
676 create J
677 COMMIT
679 from refs/heads/branch
681 reset refs/heads/J
683 commit refs/heads/J
684 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
685 data <<COMMIT
686 initialize J
687 COMMIT
689 INPUT_END
690 test_expect_success \
691 'J: reset existing branch creates empty commit' \
692 'git fast-import <input'
693 test_expect_success \
694 'J: branch has 1 commit, empty tree' \
695 'test 1 = `git rev-list J | wc -l` &&
696 test 0 = `git ls-tree J | wc -l`'
699 ### series K
702 cat >input <<INPUT_END
703 commit refs/heads/K
704 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
705 data <<COMMIT
706 create K
707 COMMIT
709 from refs/heads/branch
711 commit refs/heads/K
712 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
713 data <<COMMIT
714 redo K
715 COMMIT
717 from refs/heads/branch^1
719 INPUT_END
720 test_expect_success \
721 'K: reinit branch with from' \
722 'git fast-import <input'
723 test_expect_success \
724 'K: verify K^1 = branch^1' \
725 'test `git rev-parse --verify branch^1` \
726 = `git rev-parse --verify K^1`'
729 ### series L
732 cat >input <<INPUT_END
733 blob
734 mark :1
735 data <<EOF
736 some data
739 blob
740 mark :2
741 data <<EOF
742 other data
745 commit refs/heads/L
746 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
747 data <<COMMIT
748 create L
749 COMMIT
751 M 644 :1 b.
752 M 644 :1 b/other
753 M 644 :1 ba
755 commit refs/heads/L
756 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
757 data <<COMMIT
758 update L
759 COMMIT
761 M 644 :2 b.
762 M 644 :2 b/other
763 M 644 :2 ba
764 INPUT_END
766 cat >expect <<EXPECT_END
767 :100644 100644 4268632... 55d3a52... M b.
768 :040000 040000 0ae5cac... 443c768... M b
769 :100644 100644 4268632... 55d3a52... M ba
770 EXPECT_END
772 test_expect_success \
773 'L: verify internal tree sorting' \
774 'git fast-import <input &&
775 git diff-tree --abbrev --raw L^ L >output &&
776 test_cmp expect output'
779 ### series M
782 test_tick
783 cat >input <<INPUT_END
784 commit refs/heads/M1
785 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
786 data <<COMMIT
787 file rename
788 COMMIT
790 from refs/heads/branch^0
791 R file2/newf file2/n.e.w.f
793 INPUT_END
795 cat >expect <<EOF
796 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f
798 test_expect_success \
799 'M: rename file in same subdirectory' \
800 'git fast-import <input &&
801 git diff-tree -M -r M1^ M1 >actual &&
802 compare_diff_raw expect actual'
804 cat >input <<INPUT_END
805 commit refs/heads/M2
806 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
807 data <<COMMIT
808 file rename
809 COMMIT
811 from refs/heads/branch^0
812 R file2/newf i/am/new/to/you
814 INPUT_END
816 cat >expect <<EOF
817 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you
819 test_expect_success \
820 'M: rename file to new subdirectory' \
821 'git fast-import <input &&
822 git diff-tree -M -r M2^ M2 >actual &&
823 compare_diff_raw expect actual'
825 cat >input <<INPUT_END
826 commit refs/heads/M3
827 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
828 data <<COMMIT
829 file rename
830 COMMIT
832 from refs/heads/M2^0
833 R i other/sub
835 INPUT_END
837 cat >expect <<EOF
838 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you
840 test_expect_success \
841 'M: rename subdirectory to new subdirectory' \
842 'git fast-import <input &&
843 git diff-tree -M -r M3^ M3 >actual &&
844 compare_diff_raw expect actual'
847 ### series N
850 test_tick
851 cat >input <<INPUT_END
852 commit refs/heads/N1
853 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
854 data <<COMMIT
855 file copy
856 COMMIT
858 from refs/heads/branch^0
859 C file2/newf file2/n.e.w.f
861 INPUT_END
863 cat >expect <<EOF
864 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f
866 test_expect_success \
867 'N: copy file in same subdirectory' \
868 'git fast-import <input &&
869 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
870 compare_diff_raw expect actual'
872 cat >input <<INPUT_END
873 commit refs/heads/N2
874 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
875 data <<COMMIT
876 clean directory copy
877 COMMIT
879 from refs/heads/branch^0
880 C file2 file3
882 commit refs/heads/N2
883 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
884 data <<COMMIT
885 modify directory copy
886 COMMIT
888 M 644 inline file3/file5
889 data <<EOF
890 $file5_data
893 INPUT_END
895 cat >expect <<EOF
896 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
897 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
898 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
900 test_expect_success \
901 'N: copy then modify subdirectory' \
902 'git fast-import <input &&
903 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
904 compare_diff_raw expect actual'
906 cat >input <<INPUT_END
907 commit refs/heads/N3
908 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
909 data <<COMMIT
910 dirty directory copy
911 COMMIT
913 from refs/heads/branch^0
914 M 644 inline file2/file5
915 data <<EOF
916 $file5_data
919 C file2 file3
920 D file2/file5
922 INPUT_END
924 test_expect_success \
925 'N: copy dirty subdirectory' \
926 'git fast-import <input &&
927 test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`'
929 test_expect_success \
930 'N: copy directory by id' \
931 'cat >expect <<-\EOF &&
932 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
933 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
935 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
936 cat >input <<-INPUT_END &&
937 commit refs/heads/N4
938 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
939 data <<COMMIT
940 copy by tree hash
941 COMMIT
943 from refs/heads/branch^0
944 M 040000 $subdir file3
945 INPUT_END
946 git fast-import <input &&
947 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
948 compare_diff_raw expect actual'
950 test_expect_success PIPE 'N: read and copy directory' '
951 cat >expect <<-\EOF
952 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
953 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
955 git update-ref -d refs/heads/N4 &&
956 rm -f backflow &&
957 mkfifo backflow &&
959 exec <backflow &&
960 cat <<-EOF &&
961 commit refs/heads/N4
962 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
963 data <<COMMIT
964 copy by tree hash, part 2
965 COMMIT
967 from refs/heads/branch^0
968 ls "file2"
970 read mode type tree filename &&
971 echo "M 040000 $tree file3"
973 git fast-import --cat-blob-fd=3 3>backflow &&
974 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
975 compare_diff_raw expect actual
978 test_expect_success PIPE 'N: empty directory reads as missing' '
979 cat <<-\EOF >expect &&
980 OBJNAME
981 :000000 100644 OBJNAME OBJNAME A unrelated
983 echo "missing src" >expect.response &&
984 git update-ref -d refs/heads/read-empty &&
985 rm -f backflow &&
986 mkfifo backflow &&
988 exec <backflow &&
989 cat <<-EOF &&
990 commit refs/heads/read-empty
991 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
992 data <<COMMIT
993 read "empty" (missing) directory
994 COMMIT
996 M 100644 inline src/greeting
997 data <<BLOB
998 hello
999 BLOB
1000 C src/greeting dst1/non-greeting
1001 C src/greeting unrelated
1002 # leave behind "empty" src directory
1003 D src/greeting
1004 ls "src"
1006 read -r line &&
1007 printf "%s\n" "$line" >response &&
1008 cat <<-\EOF
1009 D dst1
1010 D dst2
1013 git fast-import --cat-blob-fd=3 3>backflow &&
1014 test_cmp expect.response response &&
1015 git rev-list read-empty |
1016 git diff-tree -r --root --stdin |
1017 sed "s/$_x40/OBJNAME/g" >actual &&
1018 test_cmp expect actual
1021 test_expect_success \
1022 'N: copy root directory by tree hash' \
1023 'cat >expect <<-\EOF &&
1024 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file3/newf
1025 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file3/oldf
1027 root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1028 cat >input <<-INPUT_END &&
1029 commit refs/heads/N6
1030 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1031 data <<COMMIT
1032 copy root directory by tree hash
1033 COMMIT
1035 from refs/heads/branch^0
1036 M 040000 $root ""
1037 INPUT_END
1038 git fast-import <input &&
1039 git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1040 compare_diff_raw expect actual'
1042 test_expect_success \
1043 'N: delete directory by copying' \
1044 'cat >expect <<-\EOF &&
1045 OBJID
1046 :100644 000000 OBJID OBJID D foo/bar/qux
1047 OBJID
1048 :000000 100644 OBJID OBJID A foo/bar/baz
1049 :000000 100644 OBJID OBJID A foo/bar/qux
1051 empty_tree=$(git mktree </dev/null) &&
1052 cat >input <<-INPUT_END &&
1053 commit refs/heads/N-delete
1054 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1055 data <<COMMIT
1056 collect data to be deleted
1057 COMMIT
1059 deleteall
1060 M 100644 inline foo/bar/baz
1061 data <<DATA_END
1062 hello
1063 DATA_END
1064 C "foo/bar/baz" "foo/bar/qux"
1065 C "foo/bar/baz" "foo/bar/quux/1"
1066 C "foo/bar/baz" "foo/bar/quuux"
1067 M 040000 $empty_tree foo/bar/quux
1068 M 040000 $empty_tree foo/bar/quuux
1070 commit refs/heads/N-delete
1071 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1072 data <<COMMIT
1073 delete subdirectory
1074 COMMIT
1076 M 040000 $empty_tree foo/bar/qux
1077 INPUT_END
1078 git fast-import <input &&
1079 git rev-list N-delete |
1080 git diff-tree -r --stdin --root --always |
1081 sed -e "s/$_x40/OBJID/g" >actual &&
1082 test_cmp expect actual'
1084 test_expect_success \
1085 'N: modify copied tree' \
1086 'cat >expect <<-\EOF &&
1087 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1088 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1089 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1091 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1092 cat >input <<-INPUT_END &&
1093 commit refs/heads/N5
1094 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1095 data <<COMMIT
1096 copy by tree hash
1097 COMMIT
1099 from refs/heads/branch^0
1100 M 040000 $subdir file3
1102 commit refs/heads/N5
1103 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1104 data <<COMMIT
1105 modify directory copy
1106 COMMIT
1108 M 644 inline file3/file5
1109 data <<EOF
1110 $file5_data
1112 INPUT_END
1113 git fast-import <input &&
1114 git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1115 compare_diff_raw expect actual'
1117 test_expect_success \
1118 'N: reject foo/ syntax' \
1119 'subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1120 test_must_fail git fast-import <<-INPUT_END
1121 commit refs/heads/N5B
1122 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1123 data <<COMMIT
1124 copy with invalid syntax
1125 COMMIT
1127 from refs/heads/branch^0
1128 M 040000 $subdir file3/
1129 INPUT_END'
1131 test_expect_success \
1132 'N: copy to root by id and modify' \
1133 'echo "hello, world" >expect.foo &&
1134 echo hello >expect.bar &&
1135 git fast-import <<-SETUP_END &&
1136 commit refs/heads/N7
1137 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1138 data <<COMMIT
1139 hello, tree
1140 COMMIT
1142 deleteall
1143 M 644 inline foo/bar
1144 data <<EOF
1145 hello
1147 SETUP_END
1149 tree=$(git rev-parse --verify N7:) &&
1150 git fast-import <<-INPUT_END &&
1151 commit refs/heads/N8
1152 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1153 data <<COMMIT
1154 copy to root by id and modify
1155 COMMIT
1157 M 040000 $tree ""
1158 M 644 inline foo/foo
1159 data <<EOF
1160 hello, world
1162 INPUT_END
1163 git show N8:foo/foo >actual.foo &&
1164 git show N8:foo/bar >actual.bar &&
1165 test_cmp expect.foo actual.foo &&
1166 test_cmp expect.bar actual.bar'
1168 test_expect_success \
1169 'N: extract subtree' \
1170 'branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1171 cat >input <<-INPUT_END &&
1172 commit refs/heads/N9
1173 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1174 data <<COMMIT
1175 extract subtree branch:newdir
1176 COMMIT
1178 M 040000 $branch ""
1179 C "newdir" ""
1180 INPUT_END
1181 git fast-import <input &&
1182 git diff --exit-code branch:newdir N9'
1184 test_expect_success \
1185 'N: modify subtree, extract it, and modify again' \
1186 'echo hello >expect.baz &&
1187 echo hello, world >expect.qux &&
1188 git fast-import <<-SETUP_END &&
1189 commit refs/heads/N10
1190 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1191 data <<COMMIT
1192 hello, tree
1193 COMMIT
1195 deleteall
1196 M 644 inline foo/bar/baz
1197 data <<EOF
1198 hello
1200 SETUP_END
1202 tree=$(git rev-parse --verify N10:) &&
1203 git fast-import <<-INPUT_END &&
1204 commit refs/heads/N11
1205 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1206 data <<COMMIT
1207 copy to root by id and modify
1208 COMMIT
1210 M 040000 $tree ""
1211 M 100644 inline foo/bar/qux
1212 data <<EOF
1213 hello, world
1215 R "foo" ""
1216 C "bar/qux" "bar/quux"
1217 INPUT_END
1218 git show N11:bar/baz >actual.baz &&
1219 git show N11:bar/qux >actual.qux &&
1220 git show N11:bar/quux >actual.quux &&
1221 test_cmp expect.baz actual.baz &&
1222 test_cmp expect.qux actual.qux &&
1223 test_cmp expect.qux actual.quux'
1226 ### series O
1229 cat >input <<INPUT_END
1230 #we will
1231 commit refs/heads/O1
1232 # -- ignore all of this text
1233 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1234 # $GIT_COMMITTER_NAME has inserted here for his benefit.
1235 data <<COMMIT
1236 dirty directory copy
1237 COMMIT
1239 # don't forget the import blank line!
1241 # yes, we started from our usual base of branch^0.
1242 # i like branch^0.
1243 from refs/heads/branch^0
1244 # and we need to reuse file2/file5 from N3 above.
1245 M 644 inline file2/file5
1246 # otherwise the tree will be different
1247 data <<EOF
1248 $file5_data
1251 # don't forget to copy file2 to file3
1252 C file2 file3
1254 # or to delete file5 from file2.
1255 D file2/file5
1256 # are we done yet?
1258 INPUT_END
1260 test_expect_success \
1261 'O: comments are all skipped' \
1262 'git fast-import <input &&
1263 test `git rev-parse N3` = `git rev-parse O1`'
1265 cat >input <<INPUT_END
1266 commit refs/heads/O2
1267 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1268 data <<COMMIT
1269 dirty directory copy
1270 COMMIT
1271 from refs/heads/branch^0
1272 M 644 inline file2/file5
1273 data <<EOF
1274 $file5_data
1276 C file2 file3
1277 D file2/file5
1279 INPUT_END
1281 test_expect_success \
1282 'O: blank lines not necessary after data commands' \
1283 'git fast-import <input &&
1284 test `git rev-parse N3` = `git rev-parse O2`'
1286 test_expect_success \
1287 'O: repack before next test' \
1288 'git repack -a -d'
1290 cat >input <<INPUT_END
1291 commit refs/heads/O3
1292 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1293 data <<COMMIT
1294 zstring
1295 COMMIT
1296 commit refs/heads/O3
1297 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1298 data <<COMMIT
1300 COMMIT
1301 checkpoint
1302 commit refs/heads/O3
1303 mark :5
1304 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1305 data <<COMMIT
1306 zempty
1307 COMMIT
1308 checkpoint
1309 commit refs/heads/O3
1310 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1311 data <<COMMIT
1312 zcommits
1313 COMMIT
1314 reset refs/tags/O3-2nd
1315 from :5
1316 reset refs/tags/O3-3rd
1317 from :5
1318 INPUT_END
1320 cat >expect <<INPUT_END
1321 string
1323 empty
1324 commits
1325 INPUT_END
1326 test_expect_success \
1327 'O: blank lines not necessary after other commands' \
1328 'git fast-import <input &&
1329 test 8 = `find .git/objects/pack -type f | wc -l` &&
1330 test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
1331 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1332 test_cmp expect actual'
1334 cat >input <<INPUT_END
1335 commit refs/heads/O4
1336 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1337 data <<COMMIT
1338 zstring
1339 COMMIT
1340 commit refs/heads/O4
1341 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1342 data <<COMMIT
1344 COMMIT
1345 progress Two commits down, 2 to go!
1346 commit refs/heads/O4
1347 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1348 data <<COMMIT
1349 zempty
1350 COMMIT
1351 progress Three commits down, 1 to go!
1352 commit refs/heads/O4
1353 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1354 data <<COMMIT
1355 zcommits
1356 COMMIT
1357 progress I'm done!
1358 INPUT_END
1359 test_expect_success \
1360 'O: progress outputs as requested by input' \
1361 'git fast-import <input >actual &&
1362 grep "progress " <input >expect &&
1363 test_cmp expect actual'
1366 ### series P (gitlinks)
1369 cat >input <<INPUT_END
1370 blob
1371 mark :1
1372 data 10
1373 test file
1375 reset refs/heads/sub
1376 commit refs/heads/sub
1377 mark :2
1378 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1379 data 12
1380 sub_initial
1381 M 100644 :1 file
1383 blob
1384 mark :3
1385 data <<DATAEND
1386 [submodule "sub"]
1387 path = sub
1388 url = "`pwd`/sub"
1389 DATAEND
1391 commit refs/heads/subuse1
1392 mark :4
1393 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1394 data 8
1395 initial
1396 from refs/heads/master
1397 M 100644 :3 .gitmodules
1398 M 160000 :2 sub
1400 blob
1401 mark :5
1402 data 20
1403 test file
1404 more data
1406 commit refs/heads/sub
1407 mark :6
1408 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1409 data 11
1410 sub_second
1411 from :2
1412 M 100644 :5 file
1414 commit refs/heads/subuse1
1415 mark :7
1416 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1417 data 7
1418 second
1419 from :4
1420 M 160000 :6 sub
1422 INPUT_END
1424 test_expect_success \
1425 'P: supermodule & submodule mix' \
1426 'git fast-import <input &&
1427 git checkout subuse1 &&
1428 rm -rf sub && mkdir sub && (cd sub &&
1429 git init &&
1430 git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1431 git checkout master) &&
1432 git submodule init &&
1433 git submodule update'
1435 SUBLAST=$(git rev-parse --verify sub)
1436 SUBPREV=$(git rev-parse --verify sub^)
1438 cat >input <<INPUT_END
1439 blob
1440 mark :1
1441 data <<DATAEND
1442 [submodule "sub"]
1443 path = sub
1444 url = "`pwd`/sub"
1445 DATAEND
1447 commit refs/heads/subuse2
1448 mark :2
1449 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1450 data 8
1451 initial
1452 from refs/heads/master
1453 M 100644 :1 .gitmodules
1454 M 160000 $SUBPREV sub
1456 commit refs/heads/subuse2
1457 mark :3
1458 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1459 data 7
1460 second
1461 from :2
1462 M 160000 $SUBLAST sub
1464 INPUT_END
1466 test_expect_success \
1467 'P: verbatim SHA gitlinks' \
1468 'git branch -D sub &&
1469 git gc && git prune &&
1470 git fast-import <input &&
1471 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)'
1473 test_tick
1474 cat >input <<INPUT_END
1475 commit refs/heads/subuse3
1476 mark :1
1477 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1478 data <<COMMIT
1479 corrupt
1480 COMMIT
1482 from refs/heads/subuse2
1483 M 160000 inline sub
1484 data <<DATA
1485 $SUBPREV
1486 DATA
1488 INPUT_END
1490 test_expect_success 'P: fail on inline gitlink' '
1491 test_must_fail git fast-import <input'
1493 test_tick
1494 cat >input <<INPUT_END
1495 blob
1496 mark :1
1497 data <<DATA
1498 $SUBPREV
1499 DATA
1501 commit refs/heads/subuse3
1502 mark :2
1503 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1504 data <<COMMIT
1505 corrupt
1506 COMMIT
1508 from refs/heads/subuse2
1509 M 160000 :1 sub
1511 INPUT_END
1513 test_expect_success 'P: fail on blob mark in gitlink' '
1514 test_must_fail git fast-import <input'
1517 ### series Q (notes)
1520 note1_data="The first note for the first commit"
1521 note2_data="The first note for the second commit"
1522 note3_data="The first note for the third commit"
1523 note1b_data="The second note for the first commit"
1524 note1c_data="The third note for the first commit"
1525 note2b_data="The second note for the second commit"
1527 test_tick
1528 cat >input <<INPUT_END
1529 blob
1530 mark :2
1531 data <<EOF
1532 $file2_data
1535 commit refs/heads/notes-test
1536 mark :3
1537 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1538 data <<COMMIT
1539 first (:3)
1540 COMMIT
1542 M 644 :2 file2
1544 blob
1545 mark :4
1546 data $file4_len
1547 $file4_data
1548 commit refs/heads/notes-test
1549 mark :5
1550 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1551 data <<COMMIT
1552 second (:5)
1553 COMMIT
1555 M 644 :4 file4
1557 commit refs/heads/notes-test
1558 mark :6
1559 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1560 data <<COMMIT
1561 third (:6)
1562 COMMIT
1564 M 644 inline file5
1565 data <<EOF
1566 $file5_data
1569 M 755 inline file6
1570 data <<EOF
1571 $file6_data
1574 blob
1575 mark :7
1576 data <<EOF
1577 $note1_data
1580 blob
1581 mark :8
1582 data <<EOF
1583 $note2_data
1586 commit refs/notes/foobar
1587 mark :9
1588 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1589 data <<COMMIT
1590 notes (:9)
1591 COMMIT
1593 N :7 :3
1594 N :8 :5
1595 N inline :6
1596 data <<EOF
1597 $note3_data
1600 commit refs/notes/foobar
1601 mark :10
1602 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1603 data <<COMMIT
1604 notes (:10)
1605 COMMIT
1607 N inline :3
1608 data <<EOF
1609 $note1b_data
1612 commit refs/notes/foobar2
1613 mark :11
1614 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1615 data <<COMMIT
1616 notes (:11)
1617 COMMIT
1619 N inline :3
1620 data <<EOF
1621 $note1c_data
1624 commit refs/notes/foobar
1625 mark :12
1626 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1627 data <<COMMIT
1628 notes (:12)
1629 COMMIT
1631 deleteall
1632 N inline :5
1633 data <<EOF
1634 $note2b_data
1637 INPUT_END
1639 test_expect_success \
1640 'Q: commit notes' \
1641 'git fast-import <input &&
1642 git whatchanged notes-test'
1643 test_expect_success \
1644 'Q: verify pack' \
1645 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
1647 commit1=$(git rev-parse notes-test~2)
1648 commit2=$(git rev-parse notes-test^)
1649 commit3=$(git rev-parse notes-test)
1651 cat >expect <<EOF
1652 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1653 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1655 first (:3)
1657 test_expect_success \
1658 'Q: verify first commit' \
1659 'git cat-file commit notes-test~2 | sed 1d >actual &&
1660 test_cmp expect actual'
1662 cat >expect <<EOF
1663 parent $commit1
1664 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1665 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1667 second (:5)
1669 test_expect_success \
1670 'Q: verify second commit' \
1671 'git cat-file commit notes-test^ | sed 1d >actual &&
1672 test_cmp expect actual'
1674 cat >expect <<EOF
1675 parent $commit2
1676 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1677 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1679 third (:6)
1681 test_expect_success \
1682 'Q: verify third commit' \
1683 'git cat-file commit notes-test | sed 1d >actual &&
1684 test_cmp expect actual'
1686 cat >expect <<EOF
1687 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1688 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1690 notes (:9)
1692 test_expect_success \
1693 'Q: verify first notes commit' \
1694 'git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1695 test_cmp expect actual'
1697 cat >expect.unsorted <<EOF
1698 100644 blob $commit1
1699 100644 blob $commit2
1700 100644 blob $commit3
1702 cat expect.unsorted | sort >expect
1703 test_expect_success \
1704 'Q: verify first notes tree' \
1705 'git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1706 test_cmp expect actual'
1708 echo "$note1_data" >expect
1709 test_expect_success \
1710 'Q: verify first note for first commit' \
1711 'git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual'
1713 echo "$note2_data" >expect
1714 test_expect_success \
1715 'Q: verify first note for second commit' \
1716 'git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual'
1718 echo "$note3_data" >expect
1719 test_expect_success \
1720 'Q: verify first note for third commit' \
1721 'git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual'
1723 cat >expect <<EOF
1724 parent `git rev-parse --verify refs/notes/foobar~2`
1725 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1726 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1728 notes (:10)
1730 test_expect_success \
1731 'Q: verify second notes commit' \
1732 'git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
1733 test_cmp expect actual'
1735 cat >expect.unsorted <<EOF
1736 100644 blob $commit1
1737 100644 blob $commit2
1738 100644 blob $commit3
1740 cat expect.unsorted | sort >expect
1741 test_expect_success \
1742 'Q: verify second notes tree' \
1743 'git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1744 test_cmp expect actual'
1746 echo "$note1b_data" >expect
1747 test_expect_success \
1748 'Q: verify second note for first commit' \
1749 'git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual'
1751 echo "$note2_data" >expect
1752 test_expect_success \
1753 'Q: verify first note for second commit' \
1754 'git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual'
1756 echo "$note3_data" >expect
1757 test_expect_success \
1758 'Q: verify first note for third commit' \
1759 'git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual'
1761 cat >expect <<EOF
1762 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1763 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1765 notes (:11)
1767 test_expect_success \
1768 'Q: verify third notes commit' \
1769 'git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
1770 test_cmp expect actual'
1772 cat >expect.unsorted <<EOF
1773 100644 blob $commit1
1775 cat expect.unsorted | sort >expect
1776 test_expect_success \
1777 'Q: verify third notes tree' \
1778 'git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1779 test_cmp expect actual'
1781 echo "$note1c_data" >expect
1782 test_expect_success \
1783 'Q: verify third note for first commit' \
1784 'git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual'
1786 cat >expect <<EOF
1787 parent `git rev-parse --verify refs/notes/foobar^`
1788 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1789 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1791 notes (:12)
1793 test_expect_success \
1794 'Q: verify fourth notes commit' \
1795 'git cat-file commit refs/notes/foobar | sed 1d >actual &&
1796 test_cmp expect actual'
1798 cat >expect.unsorted <<EOF
1799 100644 blob $commit2
1801 cat expect.unsorted | sort >expect
1802 test_expect_success \
1803 'Q: verify fourth notes tree' \
1804 'git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1805 test_cmp expect actual'
1807 echo "$note2b_data" >expect
1808 test_expect_success \
1809 'Q: verify second note for second commit' \
1810 'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual'
1813 ### series R (feature and option)
1816 cat >input <<EOF
1817 feature no-such-feature-exists
1820 test_expect_success 'R: abort on unsupported feature' '
1821 test_must_fail git fast-import <input
1824 cat >input <<EOF
1825 feature date-format=now
1828 test_expect_success 'R: supported feature is accepted' '
1829 git fast-import <input
1832 cat >input << EOF
1833 blob
1834 data 3
1836 feature date-format=now
1839 test_expect_success 'R: abort on receiving feature after data command' '
1840 test_must_fail git fast-import <input
1843 cat >input << EOF
1844 feature import-marks=git.marks
1845 feature import-marks=git2.marks
1848 test_expect_success 'R: only one import-marks feature allowed per stream' '
1849 test_must_fail git fast-import <input
1852 cat >input << EOF
1853 feature export-marks=git.marks
1854 blob
1855 mark :1
1856 data 3
1861 test_expect_success \
1862 'R: export-marks feature results in a marks file being created' \
1863 'cat input | git fast-import &&
1864 grep :1 git.marks'
1866 test_expect_success \
1867 'R: export-marks options can be overriden by commandline options' \
1868 'cat input | git fast-import --export-marks=other.marks &&
1869 grep :1 other.marks'
1871 test_expect_success 'R: catch typo in marks file name' '
1872 test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
1873 echo "feature import-marks=nonexistent.marks" |
1874 test_must_fail git fast-import
1877 test_expect_success 'R: import and output marks can be the same file' '
1878 rm -f io.marks &&
1879 blob=$(echo hi | git hash-object --stdin) &&
1880 cat >expect <<-EOF &&
1881 :1 $blob
1882 :2 $blob
1884 git fast-import --export-marks=io.marks <<-\EOF &&
1885 blob
1886 mark :1
1887 data 3
1891 git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
1892 blob
1893 mark :2
1894 data 3
1898 test_cmp expect io.marks
1901 test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
1902 rm -f io.marks &&
1903 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
1904 blob
1905 mark :1
1906 data 3
1912 test_expect_success 'R: --import-marks-if-exists' '
1913 rm -f io.marks &&
1914 blob=$(echo hi | git hash-object --stdin) &&
1915 echo ":1 $blob" >expect &&
1916 git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
1917 blob
1918 mark :1
1919 data 3
1923 test_cmp expect io.marks
1926 cat >input << EOF
1927 feature import-marks=marks.out
1928 feature export-marks=marks.new
1931 test_expect_success \
1932 'R: import to output marks works without any content' \
1933 'cat input | git fast-import &&
1934 test_cmp marks.out marks.new'
1936 cat >input <<EOF
1937 feature import-marks=nonexistent.marks
1938 feature export-marks=marks.new
1941 test_expect_success \
1942 'R: import marks prefers commandline marks file over the stream' \
1943 'cat input | git fast-import --import-marks=marks.out &&
1944 test_cmp marks.out marks.new'
1947 cat >input <<EOF
1948 feature import-marks=nonexistent.marks
1949 feature export-marks=combined.marks
1952 test_expect_success 'R: multiple --import-marks= should be honoured' '
1953 head -n2 marks.out > one.marks &&
1954 tail -n +3 marks.out > two.marks &&
1955 git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
1956 test_cmp marks.out combined.marks
1959 cat >input <<EOF
1960 feature relative-marks
1961 feature import-marks=relative.in
1962 feature export-marks=relative.out
1965 test_expect_success 'R: feature relative-marks should be honoured' '
1966 mkdir -p .git/info/fast-import/ &&
1967 cp marks.new .git/info/fast-import/relative.in &&
1968 git fast-import <input &&
1969 test_cmp marks.new .git/info/fast-import/relative.out
1972 cat >input <<EOF
1973 feature relative-marks
1974 feature import-marks=relative.in
1975 feature no-relative-marks
1976 feature export-marks=non-relative.out
1979 test_expect_success 'R: feature no-relative-marks should be honoured' '
1980 git fast-import <input &&
1981 test_cmp marks.new non-relative.out
1984 test_expect_success 'R: feature ls supported' '
1985 echo "feature ls" |
1986 git fast-import
1989 test_expect_success 'R: feature cat-blob supported' '
1990 echo "feature cat-blob" |
1991 git fast-import
1994 test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
1995 test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
1998 test_expect_success 'R: print old blob' '
1999 blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2000 cat >expect <<-EOF &&
2001 ${blob} blob 11
2002 yes it can
2005 echo "cat-blob $blob" |
2006 git fast-import --cat-blob-fd=6 6>actual &&
2007 test_cmp expect actual
2010 test_expect_success 'R: in-stream cat-blob-fd not respected' '
2011 echo hello >greeting &&
2012 blob=$(git hash-object -w greeting) &&
2013 cat >expect <<-EOF &&
2014 ${blob} blob 6
2015 hello
2018 git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2019 cat-blob $blob
2021 test_cmp expect actual.3 &&
2022 test_cmp empty actual.1 &&
2023 git fast-import 3>actual.3 >actual.1 <<-EOF &&
2024 option cat-blob-fd=3
2025 cat-blob $blob
2027 test_cmp empty actual.3 &&
2028 test_cmp expect actual.1
2031 test_expect_success 'R: print new blob' '
2032 blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2033 cat >expect <<-EOF &&
2034 ${blob} blob 12
2035 yep yep yep
2038 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2039 blob
2040 mark :1
2041 data <<BLOB_END
2042 yep yep yep
2043 BLOB_END
2044 cat-blob :1
2046 test_cmp expect actual
2049 test_expect_success 'R: print new blob by sha1' '
2050 blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2051 cat >expect <<-EOF &&
2052 ${blob} blob 25
2053 a new blob named by sha1
2056 git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2057 blob
2058 data <<BLOB_END
2059 a new blob named by sha1
2060 BLOB_END
2061 cat-blob $blob
2063 test_cmp expect actual
2066 test_expect_success 'setup: big file' '
2068 echo "the quick brown fox jumps over the lazy dog" >big &&
2069 for i in 1 2 3
2071 cat big big big big >bigger &&
2072 cat bigger bigger bigger bigger >big ||
2073 exit
2074 done
2078 test_expect_success 'R: print two blobs to stdout' '
2079 blob1=$(git hash-object big) &&
2080 blob1_len=$(wc -c <big) &&
2081 blob2=$(echo hello | git hash-object --stdin) &&
2083 echo ${blob1} blob $blob1_len &&
2084 cat big &&
2085 cat <<-EOF
2087 ${blob2} blob 6
2088 hello
2091 } >expect &&
2093 cat <<-\END_PART1 &&
2094 blob
2095 mark :1
2096 data <<data_end
2097 END_PART1
2098 cat big &&
2099 cat <<-\EOF
2100 data_end
2101 blob
2102 mark :2
2103 data <<data_end
2104 hello
2105 data_end
2106 cat-blob :1
2107 cat-blob :2
2110 git fast-import >actual &&
2111 test_cmp expect actual
2114 test_expect_success PIPE 'R: copy using cat-file' '
2115 expect_id=$(git hash-object big) &&
2116 expect_len=$(wc -c <big) &&
2117 echo $expect_id blob $expect_len >expect.response &&
2119 rm -f blobs &&
2120 cat >frontend <<-\FRONTEND_END &&
2121 #!/bin/sh
2122 FRONTEND_END
2124 mkfifo blobs &&
2126 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2127 cat <<-\EOF &&
2128 feature cat-blob
2129 blob
2130 mark :1
2131 data <<BLOB
2133 cat big &&
2134 cat <<-\EOF &&
2135 BLOB
2136 cat-blob :1
2139 read blob_id type size <&3 &&
2140 echo "$blob_id $type $size" >response &&
2141 head_c $size >blob <&3 &&
2142 read newline <&3 &&
2144 cat <<-EOF &&
2145 commit refs/heads/copied
2146 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2147 data <<COMMIT
2148 copy big file as file3
2149 COMMIT
2150 M 644 inline file3
2151 data <<BLOB
2153 cat blob &&
2154 echo BLOB
2155 ) 3<blobs |
2156 git fast-import --cat-blob-fd=3 3>blobs &&
2157 git show copied:file3 >actual &&
2158 test_cmp expect.response response &&
2159 test_cmp big actual
2162 test_expect_success PIPE 'R: print blob mid-commit' '
2163 rm -f blobs &&
2164 echo "A blob from _before_ the commit." >expect &&
2165 mkfifo blobs &&
2167 exec 3<blobs &&
2168 cat <<-EOF &&
2169 feature cat-blob
2170 blob
2171 mark :1
2172 data <<BLOB
2173 A blob from _before_ the commit.
2174 BLOB
2175 commit refs/heads/temporary
2176 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2177 data <<COMMIT
2178 Empty commit
2179 COMMIT
2180 cat-blob :1
2183 read blob_id type size <&3 &&
2184 head_c $size >actual <&3 &&
2185 read newline <&3 &&
2187 echo
2189 git fast-import --cat-blob-fd=3 3>blobs &&
2190 test_cmp expect actual
2193 test_expect_success PIPE 'R: print staged blob within commit' '
2194 rm -f blobs &&
2195 echo "A blob from _within_ the commit." >expect &&
2196 mkfifo blobs &&
2198 exec 3<blobs &&
2199 cat <<-EOF &&
2200 feature cat-blob
2201 commit refs/heads/within
2202 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2203 data <<COMMIT
2204 Empty commit
2205 COMMIT
2206 M 644 inline within
2207 data <<BLOB
2208 A blob from _within_ the commit.
2209 BLOB
2212 to_get=$(
2213 echo "A blob from _within_ the commit." |
2214 git hash-object --stdin
2215 ) &&
2216 echo "cat-blob $to_get" &&
2218 read blob_id type size <&3 &&
2219 head_c $size >actual <&3 &&
2220 read newline <&3 &&
2222 echo deleteall
2224 git fast-import --cat-blob-fd=3 3>blobs &&
2225 test_cmp expect actual
2228 cat >input << EOF
2229 option git quiet
2230 blob
2231 data 3
2236 test_expect_success 'R: quiet option results in no stats being output' '
2237 cat input | git fast-import 2> output &&
2238 test_cmp empty output
2241 cat >input <<EOF
2242 option git non-existing-option
2245 test_expect_success 'R: die on unknown option' '
2246 test_must_fail git fast-import <input
2249 test_expect_success 'R: unknown commandline options are rejected' '\
2250 test_must_fail git fast-import --non-existing-option < /dev/null
2253 test_expect_success 'R: die on invalid option argument' '
2254 echo "option git active-branches=-5" |
2255 test_must_fail git fast-import &&
2256 echo "option git depth=" |
2257 test_must_fail git fast-import &&
2258 test_must_fail git fast-import --depth="5 elephants" </dev/null
2261 cat >input <<EOF
2262 option non-existing-vcs non-existing-option
2265 test_expect_success 'R: ignore non-git options' '
2266 git fast-import <input
2270 ## R: very large blobs
2272 blobsize=$((2*1024*1024 + 53))
2273 test-genrandom bar $blobsize >expect
2274 cat >input <<INPUT_END
2275 commit refs/heads/big-file
2276 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2277 data <<COMMIT
2278 R - big file
2279 COMMIT
2281 M 644 inline big1
2282 data $blobsize
2283 INPUT_END
2284 cat expect >>input
2285 cat >>input <<INPUT_END
2286 M 644 inline big2
2287 data $blobsize
2288 INPUT_END
2289 cat expect >>input
2290 echo >>input
2292 test_expect_success \
2293 'R: blob bigger than threshold' \
2294 'test_create_repo R &&
2295 git --git-dir=R/.git fast-import --big-file-threshold=1 <input'
2296 test_expect_success \
2297 'R: verify created pack' \
2298 ': >verify &&
2299 for p in R/.git/objects/pack/*.pack;
2301 git verify-pack -v $p >>verify || exit;
2302 done'
2303 test_expect_success \
2304 'R: verify written objects' \
2305 'git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2306 test_cmp expect actual &&
2307 a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2308 b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2309 test $a = $b'
2310 test_expect_success \
2311 'R: blob appears only once' \
2312 'n=$(grep $a verify | wc -l) &&
2313 test 1 = $n'
2315 test_done