1#!/bin/sh
2#
3# Copyright (c) 2007 Shawn Pearce
4#
5
6test_description='test git fast-import utility'
7. ./test-lib.sh
8. "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
9
10# Print $1 bytes from stdin to stdout.
11#
12# This could be written as "head -c $1", but IRIX "head" does not
13# support the -c option.
14head_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;
23 }
24 ' - "$1"
25}
26
27verify_packs () {
28 for p in .git/objects/pack/*.pack
29 do
30 git verify-pack "$@" "$p" || return
31 done
32}
33
34file2_data='file2
35second line of EOF'
36
37file3_data='EOF
38in 3rd file
39 END'
40
41file4_data=abcd
42file4_len=4
43
44file5_data='an inline file.
45 we should see it later.'
46
47file6_data='#!/bin/sh
48echo "$@"'
49
50>empty
51
52###
53### series A
54###
55
56test_tick
57
58test_expect_success 'empty stream succeeds' '
59 git fast-import </dev/null
60'
61
62cat >input <<INPUT_END
63blob
64mark :2
65data <<EOF
66$file2_data
67EOF
68
69blob
70mark :3
71data <<END
72$file3_data
73END
74
75blob
76mark :4
77data $file4_len
78$file4_data
79commit refs/heads/master
80mark :5
81committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
82data <<COMMIT
83initial
84COMMIT
85
86M 644 :2 file2
87M 644 :3 file3
88M 755 :4 file4
89
90tag series-A
91from :5
92data <<EOF
93An annotated tag without a tagger
94EOF
95
96tag series-A-blob
97from :3
98data <<EOF
99An annotated tag that annotates a blob.
100EOF
101
102INPUT_END
103test_expect_success \
104 'A: create pack from stdin' \
105 'git fast-import --export-marks=marks.out <input &&
106 git whatchanged master'
107
108test_expect_success 'A: verify pack' '
109 verify_packs
110'
111
112cat >expect <<EOF
113author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
114committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
115
116initial
117EOF
118test_expect_success \
119 'A: verify commit' \
120 'git cat-file commit master | sed 1d >actual &&
121 test_cmp expect actual'
122
123cat >expect <<EOF
124100644 blob file2
125100644 blob file3
126100755 blob file4
127EOF
128test_expect_success \
129 'A: verify tree' \
130 'git cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
131 test_cmp expect actual'
132
133echo "$file2_data" >expect
134test_expect_success \
135 'A: verify file2' \
136 'git cat-file blob master:file2 >actual && test_cmp expect actual'
137
138echo "$file3_data" >expect
139test_expect_success \
140 'A: verify file3' \
141 'git cat-file blob master:file3 >actual && test_cmp expect actual'
142
143printf "$file4_data" >expect
144test_expect_success \
145 'A: verify file4' \
146 'git cat-file blob master:file4 >actual && test_cmp expect actual'
147
148cat >expect <<EOF
149object $(git rev-parse refs/heads/master)
150type commit
151tag series-A
152
153An annotated tag without a tagger
154EOF
155test_expect_success 'A: verify tag/series-A' '
156 git cat-file tag tags/series-A >actual &&
157 test_cmp expect actual
158'
159
160cat >expect <<EOF
161object $(git rev-parse refs/heads/master:file3)
162type blob
163tag series-A-blob
164
165An annotated tag that annotates a blob.
166EOF
167test_expect_success 'A: verify tag/series-A-blob' '
168 git cat-file tag tags/series-A-blob >actual &&
169 test_cmp expect actual
170'
171
172cat >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`
177EOF
178test_expect_success \
179 'A: verify marks output' \
180 'test_cmp expect marks.out'
181
182test_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'
189
190test_tick
191new_blob=$(echo testing | git hash-object --stdin)
192cat >input <<INPUT_END
193tag series-A-blob-2
194from $(git rev-parse refs/heads/master:file3)
195data <<EOF
196Tag blob by sha1.
197EOF
198
199blob
200mark :6
201data <<EOF
202testing
203EOF
204
205commit refs/heads/new_blob
206committer <> 0 +0000
207data 0
208M 644 :6 new_blob
209#pretend we got sha1 from fast-import
210ls "new_blob"
211
212tag series-A-blob-3
213from $new_blob
214data <<EOF
215Tag new_blob.
216EOF
217INPUT_END
218
219cat >expect <<EOF
220object $(git rev-parse refs/heads/master:file3)
221type blob
222tag series-A-blob-2
223
224Tag blob by sha1.
225object $new_blob
226type blob
227tag series-A-blob-3
228
229Tag new_blob.
230EOF
231
232test_expect_success \
233 'A: tag blob by sha1' \
234 'git fast-import <input &&
235 git cat-file tag tags/series-A-blob-2 >actual &&
236 git cat-file tag tags/series-A-blob-3 >>actual &&
237 test_cmp expect actual'
238
239test_tick
240cat >input <<INPUT_END
241commit refs/heads/verify--import-marks
242committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
243data <<COMMIT
244recreate from :5
245COMMIT
246
247from :5
248M 755 :2 copy-of-file2
249
250INPUT_END
251test_expect_success \
252 'A: verify marks import does not crash' \
253 'git fast-import --import-marks=marks.out <input &&
254 git whatchanged verify--import-marks'
255
256test_expect_success 'A: verify pack' '
257 verify_packs
258'
259
260cat >expect <<EOF
261:000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2
262EOF
263git diff-tree -M -r master verify--import-marks >actual
264test_expect_success \
265 'A: verify diff' \
266 'compare_diff_raw expect actual &&
267 test `git rev-parse --verify master:file2` \
268 = `git rev-parse --verify verify--import-marks:copy-of-file2`'
269
270test_tick
271mt=$(git hash-object --stdin < /dev/null)
272: >input.blob
273: >marks.exp
274: >tree.exp
275
276cat >input.commit <<EOF
277commit refs/heads/verify--dump-marks
278committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
279data <<COMMIT
280test the sparse array dumping routines with exponentially growing marks
281COMMIT
282EOF
283
284i=0
285l=4
286m=6
287n=7
288while test "$i" -lt 27; do
289 cat >>input.blob <<EOF
290blob
291mark :$l
292data 0
293blob
294mark :$m
295data 0
296blob
297mark :$n
298data 0
299EOF
300 echo "M 100644 :$l l$i" >>input.commit
301 echo "M 100644 :$m m$i" >>input.commit
302 echo "M 100644 :$n n$i" >>input.commit
303
304 echo ":$l $mt" >>marks.exp
305 echo ":$m $mt" >>marks.exp
306 echo ":$n $mt" >>marks.exp
307
308 printf "100644 blob $mt\tl$i\n" >>tree.exp
309 printf "100644 blob $mt\tm$i\n" >>tree.exp
310 printf "100644 blob $mt\tn$i\n" >>tree.exp
311
312 l=$(($l + $l))
313 m=$(($m + $m))
314 n=$(($l + $n))
315
316 i=$((1 + $i))
317done
318
319sort tree.exp > tree.exp_s
320
321test_expect_success 'A: export marks with large values' '
322 cat input.blob input.commit | git fast-import --export-marks=marks.large &&
323 git ls-tree refs/heads/verify--dump-marks >tree.out &&
324 test_cmp tree.exp_s tree.out &&
325 test_cmp marks.exp marks.large'
326
327###
328### series B
329###
330
331test_tick
332cat >input <<INPUT_END
333commit refs/heads/branch
334mark :1
335committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
336data <<COMMIT
337corrupt
338COMMIT
339
340from refs/heads/master
341M 755 0000000000000000000000000000000000000001 zero1
342
343INPUT_END
344test_expect_success 'B: fail on invalid blob sha1' '
345 test_must_fail git fast-import <input
346'
347rm -f .git/objects/pack_* .git/objects/index_*
348
349cat >input <<INPUT_END
350commit TEMP_TAG
351committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
352data <<COMMIT
353tag base
354COMMIT
355
356from refs/heads/master
357
358INPUT_END
359test_expect_success \
360 'B: accept branch name "TEMP_TAG"' \
361 'git fast-import <input &&
362 test -f .git/TEMP_TAG &&
363 test `git rev-parse master` = `git rev-parse TEMP_TAG^`'
364rm -f .git/TEMP_TAG
365
366git gc 2>/dev/null >/dev/null
367git prune 2>/dev/null >/dev/null
368
369cat >input <<INPUT_END
370commit refs/heads/empty-committer-1
371committer <> $GIT_COMMITTER_DATE
372data <<COMMIT
373empty commit
374COMMIT
375INPUT_END
376test_expect_success 'B: accept empty committer' '
377 git fast-import <input &&
378 out=$(git fsck) &&
379 echo "$out" &&
380 test -z "$out"
381'
382git update-ref -d refs/heads/empty-committer-1 || true
383
384git gc 2>/dev/null >/dev/null
385git prune 2>/dev/null >/dev/null
386
387cat >input <<INPUT_END
388commit refs/heads/empty-committer-2
389committer <a@b.com> $GIT_COMMITTER_DATE
390data <<COMMIT
391empty commit
392COMMIT
393INPUT_END
394test_expect_success 'B: accept and fixup committer with no name' '
395 git fast-import <input &&
396 out=$(git fsck) &&
397 echo "$out" &&
398 test -z "$out"
399'
400git update-ref -d refs/heads/empty-committer-2 || true
401
402git gc 2>/dev/null >/dev/null
403git prune 2>/dev/null >/dev/null
404
405cat >input <<INPUT_END
406commit refs/heads/invalid-committer
407committer Name email> $GIT_COMMITTER_DATE
408data <<COMMIT
409empty commit
410COMMIT
411INPUT_END
412test_expect_success 'B: fail on invalid committer (1)' '
413 test_must_fail git fast-import <input
414'
415git update-ref -d refs/heads/invalid-committer || true
416
417cat >input <<INPUT_END
418commit refs/heads/invalid-committer
419committer Name <e<mail> $GIT_COMMITTER_DATE
420data <<COMMIT
421empty commit
422COMMIT
423INPUT_END
424test_expect_success 'B: fail on invalid committer (2)' '
425 test_must_fail git fast-import <input
426'
427git update-ref -d refs/heads/invalid-committer || true
428
429cat >input <<INPUT_END
430commit refs/heads/invalid-committer
431committer Name <email>> $GIT_COMMITTER_DATE
432data <<COMMIT
433empty commit
434COMMIT
435INPUT_END
436test_expect_success 'B: fail on invalid committer (3)' '
437 test_must_fail git fast-import <input
438'
439git update-ref -d refs/heads/invalid-committer || true
440
441cat >input <<INPUT_END
442commit refs/heads/invalid-committer
443committer Name <email $GIT_COMMITTER_DATE
444data <<COMMIT
445empty commit
446COMMIT
447INPUT_END
448test_expect_success 'B: fail on invalid committer (4)' '
449 test_must_fail git fast-import <input
450'
451git update-ref -d refs/heads/invalid-committer || true
452
453cat >input <<INPUT_END
454commit refs/heads/invalid-committer
455committer Name<email> $GIT_COMMITTER_DATE
456data <<COMMIT
457empty commit
458COMMIT
459INPUT_END
460test_expect_success 'B: fail on invalid committer (5)' '
461 test_must_fail git fast-import <input
462'
463git update-ref -d refs/heads/invalid-committer || true
464
465###
466### series C
467###
468
469newf=`echo hi newf | git hash-object -w --stdin`
470oldf=`git rev-parse --verify master:file2`
471test_tick
472cat >input <<INPUT_END
473commit refs/heads/branch
474committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
475data <<COMMIT
476second
477COMMIT
478
479from refs/heads/master
480M 644 $oldf file2/oldf
481M 755 $newf file2/newf
482D file3
483
484INPUT_END
485test_expect_success \
486 'C: incremental import create pack from stdin' \
487 'git fast-import <input &&
488 git whatchanged branch'
489
490test_expect_success 'C: verify pack' '
491 verify_packs
492'
493
494test_expect_success \
495 'C: validate reuse existing blob' \
496 'test $newf = `git rev-parse --verify branch:file2/newf` &&
497 test $oldf = `git rev-parse --verify branch:file2/oldf`'
498
499cat >expect <<EOF
500parent `git rev-parse --verify master^0`
501author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
502committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
503
504second
505EOF
506test_expect_success \
507 'C: verify commit' \
508 'git cat-file commit branch | sed 1d >actual &&
509 test_cmp expect actual'
510
511cat >expect <<EOF
512:000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
513:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
514:100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
515EOF
516git diff-tree -M -r master branch >actual
517test_expect_success \
518 'C: validate rename result' \
519 'compare_diff_raw expect actual'
520
521###
522### series D
523###
524
525test_tick
526cat >input <<INPUT_END
527commit refs/heads/branch
528committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
529data <<COMMIT
530third
531COMMIT
532
533from refs/heads/branch^0
534M 644 inline newdir/interesting
535data <<EOF
536$file5_data
537EOF
538
539M 755 inline newdir/exec.sh
540data <<EOF
541$file6_data
542EOF
543
544INPUT_END
545test_expect_success \
546 'D: inline data in commit' \
547 'git fast-import <input &&
548 git whatchanged branch'
549
550test_expect_success 'D: verify pack' '
551 verify_packs
552'
553
554cat >expect <<EOF
555:000000 100755 0000000000000000000000000000000000000000 e74b7d465e52746be2b4bae983670711e6e66657 A newdir/exec.sh
556:000000 100644 0000000000000000000000000000000000000000 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 A newdir/interesting
557EOF
558git diff-tree -M -r branch^ branch >actual
559test_expect_success \
560 'D: validate new files added' \
561 'compare_diff_raw expect actual'
562
563echo "$file5_data" >expect
564test_expect_success \
565 'D: verify file5' \
566 'git cat-file blob branch:newdir/interesting >actual &&
567 test_cmp expect actual'
568
569echo "$file6_data" >expect
570test_expect_success \
571 'D: verify file6' \
572 'git cat-file blob branch:newdir/exec.sh >actual &&
573 test_cmp expect actual'
574
575###
576### series E
577###
578
579cat >input <<INPUT_END
580commit refs/heads/branch
581author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
582committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
583data <<COMMIT
584RFC 2822 type date
585COMMIT
586
587from refs/heads/branch^0
588
589INPUT_END
590test_expect_success 'E: rfc2822 date, --date-format=raw' '
591 test_must_fail git fast-import --date-format=raw <input
592'
593test_expect_success \
594 'E: rfc2822 date, --date-format=rfc2822' \
595 'git fast-import --date-format=rfc2822 <input'
596
597test_expect_success 'E: verify pack' '
598 verify_packs
599'
600
601cat >expect <<EOF
602author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
603committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
604
605RFC 2822 type date
606EOF
607test_expect_success \
608 'E: verify commit' \
609 'git cat-file commit branch | sed 1,2d >actual &&
610 test_cmp expect actual'
611
612###
613### series F
614###
615
616old_branch=`git rev-parse --verify branch^0`
617test_tick
618cat >input <<INPUT_END
619commit refs/heads/branch
620committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
621data <<COMMIT
622losing things already?
623COMMIT
624
625from refs/heads/branch~1
626
627reset refs/heads/other
628from refs/heads/branch
629
630INPUT_END
631test_expect_success \
632 'F: non-fast-forward update skips' \
633 'if git fast-import <input
634 then
635 echo BAD gfi did not fail
636 return 1
637 else
638 if test $old_branch = `git rev-parse --verify branch^0`
639 then
640 : branch unaffected and failure returned
641 return 0
642 else
643 echo BAD gfi changed branch $old_branch
644 return 1
645 fi
646 fi
647 '
648
649test_expect_success 'F: verify pack' '
650 verify_packs
651'
652
653cat >expect <<EOF
654tree `git rev-parse branch~1^{tree}`
655parent `git rev-parse branch~1`
656author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
657committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
658
659losing things already?
660EOF
661test_expect_success \
662 'F: verify other commit' \
663 'git cat-file commit other >actual &&
664 test_cmp expect actual'
665
666###
667### series G
668###
669
670old_branch=`git rev-parse --verify branch^0`
671test_tick
672cat >input <<INPUT_END
673commit refs/heads/branch
674committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
675data <<COMMIT
676losing things already?
677COMMIT
678
679from refs/heads/branch~1
680
681INPUT_END
682test_expect_success \
683 'G: non-fast-forward update forced' \
684 'git fast-import --force <input'
685
686test_expect_success 'G: verify pack' '
687 verify_packs
688'
689
690test_expect_success \
691 'G: branch changed, but logged' \
692 'test $old_branch != `git rev-parse --verify branch^0` &&
693 test $old_branch = `git rev-parse --verify branch@{1}`'
694
695###
696### series H
697###
698
699test_tick
700cat >input <<INPUT_END
701commit refs/heads/H
702committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
703data <<COMMIT
704third
705COMMIT
706
707from refs/heads/branch^0
708M 644 inline i-will-die
709data <<EOF
710this file will never exist.
711EOF
712
713deleteall
714M 644 inline h/e/l/lo
715data <<EOF
716$file5_data
717EOF
718
719INPUT_END
720test_expect_success \
721 'H: deletall, add 1' \
722 'git fast-import <input &&
723 git whatchanged H'
724
725test_expect_success 'H: verify pack' '
726 verify_packs
727'
728
729cat >expect <<EOF
730:100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf
731:100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf
732:100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4
733:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo
734:100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh
735EOF
736git diff-tree -M -r H^ H >actual
737test_expect_success \
738 'H: validate old files removed, new files added' \
739 'compare_diff_raw expect actual'
740
741echo "$file5_data" >expect
742test_expect_success \
743 'H: verify file' \
744 'git cat-file blob H:h/e/l/lo >actual &&
745 test_cmp expect actual'
746
747###
748### series I
749###
750
751cat >input <<INPUT_END
752commit refs/heads/export-boundary
753committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
754data <<COMMIT
755we have a border. its only 40 characters wide.
756COMMIT
757
758from refs/heads/branch
759
760INPUT_END
761test_expect_success \
762 'I: export-pack-edges' \
763 'git fast-import --export-pack-edges=edges.list <input'
764
765cat >expect <<EOF
766.git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
767EOF
768test_expect_success \
769 'I: verify edge list' \
770 'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
771 test_cmp expect actual'
772
773###
774### series J
775###
776
777cat >input <<INPUT_END
778commit refs/heads/J
779committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
780data <<COMMIT
781create J
782COMMIT
783
784from refs/heads/branch
785
786reset refs/heads/J
787
788commit refs/heads/J
789committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
790data <<COMMIT
791initialize J
792COMMIT
793
794INPUT_END
795test_expect_success \
796 'J: reset existing branch creates empty commit' \
797 'git fast-import <input'
798test_expect_success \
799 'J: branch has 1 commit, empty tree' \
800 'test 1 = `git rev-list J | wc -l` &&
801 test 0 = `git ls-tree J | wc -l`'
802
803cat >input <<INPUT_END
804reset refs/heads/J2
805
806tag wrong_tag
807from refs/heads/J2
808data <<EOF
809Tag branch that was reset.
810EOF
811INPUT_END
812test_expect_success \
813 'J: tag must fail on empty branch' \
814 'test_must_fail git fast-import <input'
815###
816### series K
817###
818
819cat >input <<INPUT_END
820commit refs/heads/K
821committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
822data <<COMMIT
823create K
824COMMIT
825
826from refs/heads/branch
827
828commit refs/heads/K
829committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
830data <<COMMIT
831redo K
832COMMIT
833
834from refs/heads/branch^1
835
836INPUT_END
837test_expect_success \
838 'K: reinit branch with from' \
839 'git fast-import <input'
840test_expect_success \
841 'K: verify K^1 = branch^1' \
842 'test `git rev-parse --verify branch^1` \
843 = `git rev-parse --verify K^1`'
844
845###
846### series L
847###
848
849cat >input <<INPUT_END
850blob
851mark :1
852data <<EOF
853some data
854EOF
855
856blob
857mark :2
858data <<EOF
859other data
860EOF
861
862commit refs/heads/L
863committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
864data <<COMMIT
865create L
866COMMIT
867
868M 644 :1 b.
869M 644 :1 b/other
870M 644 :1 ba
871
872commit refs/heads/L
873committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
874data <<COMMIT
875update L
876COMMIT
877
878M 644 :2 b.
879M 644 :2 b/other
880M 644 :2 ba
881INPUT_END
882
883cat >expect <<EXPECT_END
884:100644 100644 4268632... 55d3a52... M b.
885:040000 040000 0ae5cac... 443c768... M b
886:100644 100644 4268632... 55d3a52... M ba
887EXPECT_END
888
889test_expect_success \
890 'L: verify internal tree sorting' \
891 'git fast-import <input &&
892 git diff-tree --abbrev --raw L^ L >output &&
893 test_cmp expect output'
894
895cat >input <<INPUT_END
896blob
897mark :1
898data <<EOF
899the data
900EOF
901
902commit refs/heads/L2
903committer C O Mitter <committer@example.com> 1112912473 -0700
904data <<COMMIT
905init L2
906COMMIT
907M 644 :1 a/b/c
908M 644 :1 a/b/d
909M 644 :1 a/e/f
910
911commit refs/heads/L2
912committer C O Mitter <committer@example.com> 1112912473 -0700
913data <<COMMIT
914update L2
915COMMIT
916C a g
917C a/e g/b
918M 644 :1 g/b/h
919INPUT_END
920
921cat <<EOF >expect
922g/b/f
923g/b/h
924EOF
925
926test_expect_success \
927 'L: nested tree copy does not corrupt deltas' \
928 'git fast-import <input &&
929 git ls-tree L2 g/b/ >tmp &&
930 cat tmp | cut -f 2 >actual &&
931 test_cmp expect actual &&
932 git fsck `git rev-parse L2`'
933
934git update-ref -d refs/heads/L2
935
936###
937### series M
938###
939
940test_tick
941cat >input <<INPUT_END
942commit refs/heads/M1
943committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
944data <<COMMIT
945file rename
946COMMIT
947
948from refs/heads/branch^0
949R file2/newf file2/n.e.w.f
950
951INPUT_END
952
953cat >expect <<EOF
954:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f
955EOF
956test_expect_success \
957 'M: rename file in same subdirectory' \
958 'git fast-import <input &&
959 git diff-tree -M -r M1^ M1 >actual &&
960 compare_diff_raw expect actual'
961
962cat >input <<INPUT_END
963commit refs/heads/M2
964committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
965data <<COMMIT
966file rename
967COMMIT
968
969from refs/heads/branch^0
970R file2/newf i/am/new/to/you
971
972INPUT_END
973
974cat >expect <<EOF
975:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you
976EOF
977test_expect_success \
978 'M: rename file to new subdirectory' \
979 'git fast-import <input &&
980 git diff-tree -M -r M2^ M2 >actual &&
981 compare_diff_raw expect actual'
982
983cat >input <<INPUT_END
984commit refs/heads/M3
985committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
986data <<COMMIT
987file rename
988COMMIT
989
990from refs/heads/M2^0
991R i other/sub
992
993INPUT_END
994
995cat >expect <<EOF
996:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you
997EOF
998test_expect_success \
999 'M: rename subdirectory to new subdirectory' \
1000 'git fast-import <input &&
1001 git diff-tree -M -r M3^ M3 >actual &&
1002 compare_diff_raw expect actual'
1003
1004cat >input <<INPUT_END
1005commit refs/heads/M4
1006committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1007data <<COMMIT
1008rename root
1009COMMIT
1010
1011from refs/heads/M2^0
1012R "" sub
1013
1014INPUT_END
1015
1016cat >expect <<EOF
1017:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2/oldf sub/file2/oldf
1018:100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 R100 file4 sub/file4
1019:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you sub/i/am/new/to/you
1020:100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 R100 newdir/exec.sh sub/newdir/exec.sh
1021:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting sub/newdir/interesting
1022EOF
1023test_expect_success \
1024 'M: rename root to subdirectory' \
1025 'git fast-import <input &&
1026 git diff-tree -M -r M4^ M4 >actual &&
1027 cat actual &&
1028 compare_diff_raw expect actual'
1029
1030###
1031### series N
1032###
1033
1034test_tick
1035cat >input <<INPUT_END
1036commit refs/heads/N1
1037committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1038data <<COMMIT
1039file copy
1040COMMIT
1041
1042from refs/heads/branch^0
1043C file2/newf file2/n.e.w.f
1044
1045INPUT_END
1046
1047cat >expect <<EOF
1048:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f
1049EOF
1050test_expect_success \
1051 'N: copy file in same subdirectory' \
1052 'git fast-import <input &&
1053 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
1054 compare_diff_raw expect actual'
1055
1056cat >input <<INPUT_END
1057commit refs/heads/N2
1058committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1059data <<COMMIT
1060clean directory copy
1061COMMIT
1062
1063from refs/heads/branch^0
1064C file2 file3
1065
1066commit refs/heads/N2
1067committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1068data <<COMMIT
1069modify directory copy
1070COMMIT
1071
1072M 644 inline file3/file5
1073data <<EOF
1074$file5_data
1075EOF
1076
1077INPUT_END
1078
1079cat >expect <<EOF
1080:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1081:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1082:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1083EOF
1084test_expect_success \
1085 'N: copy then modify subdirectory' \
1086 'git fast-import <input &&
1087 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
1088 compare_diff_raw expect actual'
1089
1090cat >input <<INPUT_END
1091commit refs/heads/N3
1092committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1093data <<COMMIT
1094dirty directory copy
1095COMMIT
1096
1097from refs/heads/branch^0
1098M 644 inline file2/file5
1099data <<EOF
1100$file5_data
1101EOF
1102
1103C file2 file3
1104D file2/file5
1105
1106INPUT_END
1107
1108test_expect_success \
1109 'N: copy dirty subdirectory' \
1110 'git fast-import <input &&
1111 test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`'
1112
1113test_expect_success \
1114 'N: copy directory by id' \
1115 'cat >expect <<-\EOF &&
1116 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1117 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1118 EOF
1119 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1120 cat >input <<-INPUT_END &&
1121 commit refs/heads/N4
1122 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1123 data <<COMMIT
1124 copy by tree hash
1125 COMMIT
1126
1127 from refs/heads/branch^0
1128 M 040000 $subdir file3
1129 INPUT_END
1130 git fast-import <input &&
1131 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1132 compare_diff_raw expect actual'
1133
1134test_expect_success PIPE 'N: read and copy directory' '
1135 cat >expect <<-\EOF &&
1136 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1137 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1138 EOF
1139 git update-ref -d refs/heads/N4 &&
1140 rm -f backflow &&
1141 mkfifo backflow &&
1142 (
1143 exec <backflow &&
1144 cat <<-EOF &&
1145 commit refs/heads/N4
1146 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1147 data <<COMMIT
1148 copy by tree hash, part 2
1149 COMMIT
1150
1151 from refs/heads/branch^0
1152 ls "file2"
1153 EOF
1154 read mode type tree filename &&
1155 echo "M 040000 $tree file3"
1156 ) |
1157 git fast-import --cat-blob-fd=3 3>backflow &&
1158 git diff-tree -C --find-copies-harder -r N4^ N4 >actual &&
1159 compare_diff_raw expect actual
1160'
1161
1162test_expect_success PIPE 'N: empty directory reads as missing' '
1163 cat <<-\EOF >expect &&
1164 OBJNAME
1165 :000000 100644 OBJNAME OBJNAME A unrelated
1166 EOF
1167 echo "missing src" >expect.response &&
1168 git update-ref -d refs/heads/read-empty &&
1169 rm -f backflow &&
1170 mkfifo backflow &&
1171 (
1172 exec <backflow &&
1173 cat <<-EOF &&
1174 commit refs/heads/read-empty
1175 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1176 data <<COMMIT
1177 read "empty" (missing) directory
1178 COMMIT
1179
1180 M 100644 inline src/greeting
1181 data <<BLOB
1182 hello
1183 BLOB
1184 C src/greeting dst1/non-greeting
1185 C src/greeting unrelated
1186 # leave behind "empty" src directory
1187 D src/greeting
1188 ls "src"
1189 EOF
1190 read -r line &&
1191 printf "%s\n" "$line" >response &&
1192 cat <<-\EOF
1193 D dst1
1194 D dst2
1195 EOF
1196 ) |
1197 git fast-import --cat-blob-fd=3 3>backflow &&
1198 test_cmp expect.response response &&
1199 git rev-list read-empty |
1200 git diff-tree -r --root --stdin |
1201 sed "s/$_x40/OBJNAME/g" >actual &&
1202 test_cmp expect actual
1203'
1204
1205test_expect_success \
1206 'N: copy root directory by tree hash' \
1207 'cat >expect <<-\EOF &&
1208 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file3/newf
1209 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file3/oldf
1210 EOF
1211 root=$(git rev-parse refs/heads/branch^0^{tree}) &&
1212 cat >input <<-INPUT_END &&
1213 commit refs/heads/N6
1214 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1215 data <<COMMIT
1216 copy root directory by tree hash
1217 COMMIT
1218
1219 from refs/heads/branch^0
1220 M 040000 $root ""
1221 INPUT_END
1222 git fast-import <input &&
1223 git diff-tree -C --find-copies-harder -r N4 N6 >actual &&
1224 compare_diff_raw expect actual'
1225
1226test_expect_success \
1227 'N: copy root by path' \
1228 'cat >expect <<-\EOF &&
1229 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf oldroot/file2/newf
1230 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf oldroot/file2/oldf
1231 :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 C100 file4 oldroot/file4
1232 :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 C100 newdir/exec.sh oldroot/newdir/exec.sh
1233 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting oldroot/newdir/interesting
1234 EOF
1235 cat >input <<-INPUT_END &&
1236 commit refs/heads/N-copy-root-path
1237 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1238 data <<COMMIT
1239 copy root directory by (empty) path
1240 COMMIT
1241
1242 from refs/heads/branch^0
1243 C "" oldroot
1244 INPUT_END
1245 git fast-import <input &&
1246 git diff-tree -C --find-copies-harder -r branch N-copy-root-path >actual &&
1247 compare_diff_raw expect actual'
1248
1249test_expect_success \
1250 'N: delete directory by copying' \
1251 'cat >expect <<-\EOF &&
1252 OBJID
1253 :100644 000000 OBJID OBJID D foo/bar/qux
1254 OBJID
1255 :000000 100644 OBJID OBJID A foo/bar/baz
1256 :000000 100644 OBJID OBJID A foo/bar/qux
1257 EOF
1258 empty_tree=$(git mktree </dev/null) &&
1259 cat >input <<-INPUT_END &&
1260 commit refs/heads/N-delete
1261 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1262 data <<COMMIT
1263 collect data to be deleted
1264 COMMIT
1265
1266 deleteall
1267 M 100644 inline foo/bar/baz
1268 data <<DATA_END
1269 hello
1270 DATA_END
1271 C "foo/bar/baz" "foo/bar/qux"
1272 C "foo/bar/baz" "foo/bar/quux/1"
1273 C "foo/bar/baz" "foo/bar/quuux"
1274 M 040000 $empty_tree foo/bar/quux
1275 M 040000 $empty_tree foo/bar/quuux
1276
1277 commit refs/heads/N-delete
1278 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1279 data <<COMMIT
1280 delete subdirectory
1281 COMMIT
1282
1283 M 040000 $empty_tree foo/bar/qux
1284 INPUT_END
1285 git fast-import <input &&
1286 git rev-list N-delete |
1287 git diff-tree -r --stdin --root --always |
1288 sed -e "s/$_x40/OBJID/g" >actual &&
1289 test_cmp expect actual'
1290
1291test_expect_success \
1292 'N: modify copied tree' \
1293 'cat >expect <<-\EOF &&
1294 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
1295 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
1296 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
1297 EOF
1298 subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1299 cat >input <<-INPUT_END &&
1300 commit refs/heads/N5
1301 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1302 data <<COMMIT
1303 copy by tree hash
1304 COMMIT
1305
1306 from refs/heads/branch^0
1307 M 040000 $subdir file3
1308
1309 commit refs/heads/N5
1310 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1311 data <<COMMIT
1312 modify directory copy
1313 COMMIT
1314
1315 M 644 inline file3/file5
1316 data <<EOF
1317 $file5_data
1318 EOF
1319 INPUT_END
1320 git fast-import <input &&
1321 git diff-tree -C --find-copies-harder -r N5^^ N5 >actual &&
1322 compare_diff_raw expect actual'
1323
1324test_expect_success \
1325 'N: reject foo/ syntax' \
1326 'subdir=$(git rev-parse refs/heads/branch^0:file2) &&
1327 test_must_fail git fast-import <<-INPUT_END
1328 commit refs/heads/N5B
1329 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1330 data <<COMMIT
1331 copy with invalid syntax
1332 COMMIT
1333
1334 from refs/heads/branch^0
1335 M 040000 $subdir file3/
1336 INPUT_END'
1337
1338test_expect_success \
1339 'N: reject foo/ syntax in copy source' \
1340 'test_must_fail git fast-import <<-INPUT_END
1341 commit refs/heads/N5C
1342 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1343 data <<COMMIT
1344 copy with invalid syntax
1345 COMMIT
1346
1347 from refs/heads/branch^0
1348 C file2/ file3
1349 INPUT_END'
1350
1351test_expect_success \
1352 'N: reject foo/ syntax in rename source' \
1353 'test_must_fail git fast-import <<-INPUT_END
1354 commit refs/heads/N5D
1355 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1356 data <<COMMIT
1357 rename with invalid syntax
1358 COMMIT
1359
1360 from refs/heads/branch^0
1361 R file2/ file3
1362 INPUT_END'
1363
1364test_expect_success \
1365 'N: reject foo/ syntax in ls argument' \
1366 'test_must_fail git fast-import <<-INPUT_END
1367 commit refs/heads/N5E
1368 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1369 data <<COMMIT
1370 copy with invalid syntax
1371 COMMIT
1372
1373 from refs/heads/branch^0
1374 ls "file2/"
1375 INPUT_END'
1376
1377test_expect_success \
1378 'N: copy to root by id and modify' \
1379 'echo "hello, world" >expect.foo &&
1380 echo hello >expect.bar &&
1381 git fast-import <<-SETUP_END &&
1382 commit refs/heads/N7
1383 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1384 data <<COMMIT
1385 hello, tree
1386 COMMIT
1387
1388 deleteall
1389 M 644 inline foo/bar
1390 data <<EOF
1391 hello
1392 EOF
1393 SETUP_END
1394
1395 tree=$(git rev-parse --verify N7:) &&
1396 git fast-import <<-INPUT_END &&
1397 commit refs/heads/N8
1398 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1399 data <<COMMIT
1400 copy to root by id and modify
1401 COMMIT
1402
1403 M 040000 $tree ""
1404 M 644 inline foo/foo
1405 data <<EOF
1406 hello, world
1407 EOF
1408 INPUT_END
1409 git show N8:foo/foo >actual.foo &&
1410 git show N8:foo/bar >actual.bar &&
1411 test_cmp expect.foo actual.foo &&
1412 test_cmp expect.bar actual.bar'
1413
1414test_expect_success \
1415 'N: extract subtree' \
1416 'branch=$(git rev-parse --verify refs/heads/branch^{tree}) &&
1417 cat >input <<-INPUT_END &&
1418 commit refs/heads/N9
1419 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1420 data <<COMMIT
1421 extract subtree branch:newdir
1422 COMMIT
1423
1424 M 040000 $branch ""
1425 C "newdir" ""
1426 INPUT_END
1427 git fast-import <input &&
1428 git diff --exit-code branch:newdir N9'
1429
1430test_expect_success \
1431 'N: modify subtree, extract it, and modify again' \
1432 'echo hello >expect.baz &&
1433 echo hello, world >expect.qux &&
1434 git fast-import <<-SETUP_END &&
1435 commit refs/heads/N10
1436 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1437 data <<COMMIT
1438 hello, tree
1439 COMMIT
1440
1441 deleteall
1442 M 644 inline foo/bar/baz
1443 data <<EOF
1444 hello
1445 EOF
1446 SETUP_END
1447
1448 tree=$(git rev-parse --verify N10:) &&
1449 git fast-import <<-INPUT_END &&
1450 commit refs/heads/N11
1451 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1452 data <<COMMIT
1453 copy to root by id and modify
1454 COMMIT
1455
1456 M 040000 $tree ""
1457 M 100644 inline foo/bar/qux
1458 data <<EOF
1459 hello, world
1460 EOF
1461 R "foo" ""
1462 C "bar/qux" "bar/quux"
1463 INPUT_END
1464 git show N11:bar/baz >actual.baz &&
1465 git show N11:bar/qux >actual.qux &&
1466 git show N11:bar/quux >actual.quux &&
1467 test_cmp expect.baz actual.baz &&
1468 test_cmp expect.qux actual.qux &&
1469 test_cmp expect.qux actual.quux'
1470
1471###
1472### series O
1473###
1474
1475cat >input <<INPUT_END
1476#we will
1477commit refs/heads/O1
1478# -- ignore all of this text
1479committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1480# $GIT_COMMITTER_NAME has inserted here for his benefit.
1481data <<COMMIT
1482dirty directory copy
1483COMMIT
1484
1485# don't forget the import blank line!
1486#
1487# yes, we started from our usual base of branch^0.
1488# i like branch^0.
1489from refs/heads/branch^0
1490# and we need to reuse file2/file5 from N3 above.
1491M 644 inline file2/file5
1492# otherwise the tree will be different
1493data <<EOF
1494$file5_data
1495EOF
1496
1497# don't forget to copy file2 to file3
1498C file2 file3
1499#
1500# or to delete file5 from file2.
1501D file2/file5
1502# are we done yet?
1503
1504INPUT_END
1505
1506test_expect_success \
1507 'O: comments are all skipped' \
1508 'git fast-import <input &&
1509 test `git rev-parse N3` = `git rev-parse O1`'
1510
1511cat >input <<INPUT_END
1512commit refs/heads/O2
1513committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1514data <<COMMIT
1515dirty directory copy
1516COMMIT
1517from refs/heads/branch^0
1518M 644 inline file2/file5
1519data <<EOF
1520$file5_data
1521EOF
1522C file2 file3
1523D file2/file5
1524
1525INPUT_END
1526
1527test_expect_success \
1528 'O: blank lines not necessary after data commands' \
1529 'git fast-import <input &&
1530 test `git rev-parse N3` = `git rev-parse O2`'
1531
1532test_expect_success \
1533 'O: repack before next test' \
1534 'git repack -a -d'
1535
1536cat >input <<INPUT_END
1537commit refs/heads/O3
1538committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1539data <<COMMIT
1540zstring
1541COMMIT
1542commit refs/heads/O3
1543committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1544data <<COMMIT
1545zof
1546COMMIT
1547checkpoint
1548commit refs/heads/O3
1549mark :5
1550committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1551data <<COMMIT
1552zempty
1553COMMIT
1554checkpoint
1555commit refs/heads/O3
1556committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1557data <<COMMIT
1558zcommits
1559COMMIT
1560reset refs/tags/O3-2nd
1561from :5
1562reset refs/tags/O3-3rd
1563from :5
1564INPUT_END
1565
1566cat >expect <<INPUT_END
1567string
1568of
1569empty
1570commits
1571INPUT_END
1572test_expect_success \
1573 'O: blank lines not necessary after other commands' \
1574 'git fast-import <input &&
1575 test 8 = `find .git/objects/pack -type f | wc -l` &&
1576 test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
1577 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
1578 test_cmp expect actual'
1579
1580cat >input <<INPUT_END
1581commit refs/heads/O4
1582committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1583data <<COMMIT
1584zstring
1585COMMIT
1586commit refs/heads/O4
1587committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1588data <<COMMIT
1589zof
1590COMMIT
1591progress Two commits down, 2 to go!
1592commit refs/heads/O4
1593committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1594data <<COMMIT
1595zempty
1596COMMIT
1597progress Three commits down, 1 to go!
1598commit refs/heads/O4
1599committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1600data <<COMMIT
1601zcommits
1602COMMIT
1603progress I'm done!
1604INPUT_END
1605test_expect_success \
1606 'O: progress outputs as requested by input' \
1607 'git fast-import <input >actual &&
1608 grep "progress " <input >expect &&
1609 test_cmp expect actual'
1610
1611###
1612### series P (gitlinks)
1613###
1614
1615cat >input <<INPUT_END
1616blob
1617mark :1
1618data 10
1619test file
1620
1621reset refs/heads/sub
1622commit refs/heads/sub
1623mark :2
1624committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1625data 12
1626sub_initial
1627M 100644 :1 file
1628
1629blob
1630mark :3
1631data <<DATAEND
1632[submodule "sub"]
1633 path = sub
1634 url = "`pwd`/sub"
1635DATAEND
1636
1637commit refs/heads/subuse1
1638mark :4
1639committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1640data 8
1641initial
1642from refs/heads/master
1643M 100644 :3 .gitmodules
1644M 160000 :2 sub
1645
1646blob
1647mark :5
1648data 20
1649test file
1650more data
1651
1652commit refs/heads/sub
1653mark :6
1654committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1655data 11
1656sub_second
1657from :2
1658M 100644 :5 file
1659
1660commit refs/heads/subuse1
1661mark :7
1662committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1663data 7
1664second
1665from :4
1666M 160000 :6 sub
1667
1668INPUT_END
1669
1670test_expect_success \
1671 'P: superproject & submodule mix' \
1672 'git fast-import <input &&
1673 git checkout subuse1 &&
1674 rm -rf sub && mkdir sub && (cd sub &&
1675 git init &&
1676 git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
1677 git checkout master) &&
1678 git submodule init &&
1679 git submodule update'
1680
1681SUBLAST=$(git rev-parse --verify sub)
1682SUBPREV=$(git rev-parse --verify sub^)
1683
1684cat >input <<INPUT_END
1685blob
1686mark :1
1687data <<DATAEND
1688[submodule "sub"]
1689 path = sub
1690 url = "`pwd`/sub"
1691DATAEND
1692
1693commit refs/heads/subuse2
1694mark :2
1695committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1696data 8
1697initial
1698from refs/heads/master
1699M 100644 :1 .gitmodules
1700M 160000 $SUBPREV sub
1701
1702commit refs/heads/subuse2
1703mark :3
1704committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1705data 7
1706second
1707from :2
1708M 160000 $SUBLAST sub
1709
1710INPUT_END
1711
1712test_expect_success \
1713 'P: verbatim SHA gitlinks' \
1714 'git branch -D sub &&
1715 git gc && git prune &&
1716 git fast-import <input &&
1717 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)'
1718
1719test_tick
1720cat >input <<INPUT_END
1721commit refs/heads/subuse3
1722mark :1
1723committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1724data <<COMMIT
1725corrupt
1726COMMIT
1727
1728from refs/heads/subuse2
1729M 160000 inline sub
1730data <<DATA
1731$SUBPREV
1732DATA
1733
1734INPUT_END
1735
1736test_expect_success 'P: fail on inline gitlink' '
1737 test_must_fail git fast-import <input'
1738
1739test_tick
1740cat >input <<INPUT_END
1741blob
1742mark :1
1743data <<DATA
1744$SUBPREV
1745DATA
1746
1747commit refs/heads/subuse3
1748mark :2
1749committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1750data <<COMMIT
1751corrupt
1752COMMIT
1753
1754from refs/heads/subuse2
1755M 160000 :1 sub
1756
1757INPUT_END
1758
1759test_expect_success 'P: fail on blob mark in gitlink' '
1760 test_must_fail git fast-import <input'
1761
1762###
1763### series Q (notes)
1764###
1765
1766note1_data="The first note for the first commit"
1767note2_data="The first note for the second commit"
1768note3_data="The first note for the third commit"
1769note1b_data="The second note for the first commit"
1770note1c_data="The third note for the first commit"
1771note2b_data="The second note for the second commit"
1772
1773test_tick
1774cat >input <<INPUT_END
1775blob
1776mark :2
1777data <<EOF
1778$file2_data
1779EOF
1780
1781commit refs/heads/notes-test
1782mark :3
1783committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1784data <<COMMIT
1785first (:3)
1786COMMIT
1787
1788M 644 :2 file2
1789
1790blob
1791mark :4
1792data $file4_len
1793$file4_data
1794commit refs/heads/notes-test
1795mark :5
1796committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1797data <<COMMIT
1798second (:5)
1799COMMIT
1800
1801M 644 :4 file4
1802
1803commit refs/heads/notes-test
1804mark :6
1805committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1806data <<COMMIT
1807third (:6)
1808COMMIT
1809
1810M 644 inline file5
1811data <<EOF
1812$file5_data
1813EOF
1814
1815M 755 inline file6
1816data <<EOF
1817$file6_data
1818EOF
1819
1820blob
1821mark :7
1822data <<EOF
1823$note1_data
1824EOF
1825
1826blob
1827mark :8
1828data <<EOF
1829$note2_data
1830EOF
1831
1832commit refs/notes/foobar
1833mark :9
1834committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1835data <<COMMIT
1836notes (:9)
1837COMMIT
1838
1839N :7 :3
1840N :8 :5
1841N inline :6
1842data <<EOF
1843$note3_data
1844EOF
1845
1846commit refs/notes/foobar
1847mark :10
1848committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1849data <<COMMIT
1850notes (:10)
1851COMMIT
1852
1853N inline :3
1854data <<EOF
1855$note1b_data
1856EOF
1857
1858commit refs/notes/foobar2
1859mark :11
1860committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1861data <<COMMIT
1862notes (:11)
1863COMMIT
1864
1865N inline :3
1866data <<EOF
1867$note1c_data
1868EOF
1869
1870commit refs/notes/foobar
1871mark :12
1872committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1873data <<COMMIT
1874notes (:12)
1875COMMIT
1876
1877deleteall
1878N inline :5
1879data <<EOF
1880$note2b_data
1881EOF
1882
1883INPUT_END
1884
1885test_expect_success \
1886 'Q: commit notes' \
1887 'git fast-import <input &&
1888 git whatchanged notes-test'
1889
1890test_expect_success 'Q: verify pack' '
1891 verify_packs
1892'
1893
1894commit1=$(git rev-parse notes-test~2)
1895commit2=$(git rev-parse notes-test^)
1896commit3=$(git rev-parse notes-test)
1897
1898cat >expect <<EOF
1899author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1900committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1901
1902first (:3)
1903EOF
1904test_expect_success \
1905 'Q: verify first commit' \
1906 'git cat-file commit notes-test~2 | sed 1d >actual &&
1907 test_cmp expect actual'
1908
1909cat >expect <<EOF
1910parent $commit1
1911author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1912committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1913
1914second (:5)
1915EOF
1916test_expect_success \
1917 'Q: verify second commit' \
1918 'git cat-file commit notes-test^ | sed 1d >actual &&
1919 test_cmp expect actual'
1920
1921cat >expect <<EOF
1922parent $commit2
1923author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1924committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1925
1926third (:6)
1927EOF
1928test_expect_success \
1929 'Q: verify third commit' \
1930 'git cat-file commit notes-test | sed 1d >actual &&
1931 test_cmp expect actual'
1932
1933cat >expect <<EOF
1934author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1935committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1936
1937notes (:9)
1938EOF
1939test_expect_success \
1940 'Q: verify first notes commit' \
1941 'git cat-file commit refs/notes/foobar~2 | sed 1d >actual &&
1942 test_cmp expect actual'
1943
1944cat >expect.unsorted <<EOF
1945100644 blob $commit1
1946100644 blob $commit2
1947100644 blob $commit3
1948EOF
1949cat expect.unsorted | sort >expect
1950test_expect_success \
1951 'Q: verify first notes tree' \
1952 'git cat-file -p refs/notes/foobar~2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1953 test_cmp expect actual'
1954
1955echo "$note1_data" >expect
1956test_expect_success \
1957 'Q: verify first note for first commit' \
1958 'git cat-file blob refs/notes/foobar~2:$commit1 >actual && test_cmp expect actual'
1959
1960echo "$note2_data" >expect
1961test_expect_success \
1962 'Q: verify first note for second commit' \
1963 'git cat-file blob refs/notes/foobar~2:$commit2 >actual && test_cmp expect actual'
1964
1965echo "$note3_data" >expect
1966test_expect_success \
1967 'Q: verify first note for third commit' \
1968 'git cat-file blob refs/notes/foobar~2:$commit3 >actual && test_cmp expect actual'
1969
1970cat >expect <<EOF
1971parent `git rev-parse --verify refs/notes/foobar~2`
1972author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1973committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1974
1975notes (:10)
1976EOF
1977test_expect_success \
1978 'Q: verify second notes commit' \
1979 'git cat-file commit refs/notes/foobar^ | sed 1d >actual &&
1980 test_cmp expect actual'
1981
1982cat >expect.unsorted <<EOF
1983100644 blob $commit1
1984100644 blob $commit2
1985100644 blob $commit3
1986EOF
1987cat expect.unsorted | sort >expect
1988test_expect_success \
1989 'Q: verify second notes tree' \
1990 'git cat-file -p refs/notes/foobar^^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1991 test_cmp expect actual'
1992
1993echo "$note1b_data" >expect
1994test_expect_success \
1995 'Q: verify second note for first commit' \
1996 'git cat-file blob refs/notes/foobar^:$commit1 >actual && test_cmp expect actual'
1997
1998echo "$note2_data" >expect
1999test_expect_success \
2000 'Q: verify first note for second commit' \
2001 'git cat-file blob refs/notes/foobar^:$commit2 >actual && test_cmp expect actual'
2002
2003echo "$note3_data" >expect
2004test_expect_success \
2005 'Q: verify first note for third commit' \
2006 'git cat-file blob refs/notes/foobar^:$commit3 >actual && test_cmp expect actual'
2007
2008cat >expect <<EOF
2009author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2010committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2011
2012notes (:11)
2013EOF
2014test_expect_success \
2015 'Q: verify third notes commit' \
2016 'git cat-file commit refs/notes/foobar2 | sed 1d >actual &&
2017 test_cmp expect actual'
2018
2019cat >expect.unsorted <<EOF
2020100644 blob $commit1
2021EOF
2022cat expect.unsorted | sort >expect
2023test_expect_success \
2024 'Q: verify third notes tree' \
2025 'git cat-file -p refs/notes/foobar2^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2026 test_cmp expect actual'
2027
2028echo "$note1c_data" >expect
2029test_expect_success \
2030 'Q: verify third note for first commit' \
2031 'git cat-file blob refs/notes/foobar2:$commit1 >actual && test_cmp expect actual'
2032
2033cat >expect <<EOF
2034parent `git rev-parse --verify refs/notes/foobar^`
2035author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2036committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2037
2038notes (:12)
2039EOF
2040test_expect_success \
2041 'Q: verify fourth notes commit' \
2042 'git cat-file commit refs/notes/foobar | sed 1d >actual &&
2043 test_cmp expect actual'
2044
2045cat >expect.unsorted <<EOF
2046100644 blob $commit2
2047EOF
2048cat expect.unsorted | sort >expect
2049test_expect_success \
2050 'Q: verify fourth notes tree' \
2051 'git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
2052 test_cmp expect actual'
2053
2054echo "$note2b_data" >expect
2055test_expect_success \
2056 'Q: verify second note for second commit' \
2057 'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual'
2058
2059cat >input <<EOF
2060reset refs/heads/Q0
2061
2062commit refs/heads/note-Q0
2063committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2064data <<COMMIT
2065Note for an empty branch.
2066COMMIT
2067
2068N inline refs/heads/Q0
2069data <<NOTE
2070some note
2071NOTE
2072EOF
2073test_expect_success \
2074 'Q: deny note on empty branch' \
2075 'test_must_fail git fast-import <input'
2076###
2077### series R (feature and option)
2078###
2079
2080cat >input <<EOF
2081feature no-such-feature-exists
2082EOF
2083
2084test_expect_success 'R: abort on unsupported feature' '
2085 test_must_fail git fast-import <input
2086'
2087
2088cat >input <<EOF
2089feature date-format=now
2090EOF
2091
2092test_expect_success 'R: supported feature is accepted' '
2093 git fast-import <input
2094'
2095
2096cat >input << EOF
2097blob
2098data 3
2099hi
2100feature date-format=now
2101EOF
2102
2103test_expect_success 'R: abort on receiving feature after data command' '
2104 test_must_fail git fast-import <input
2105'
2106
2107cat >input << EOF
2108feature import-marks=git.marks
2109feature import-marks=git2.marks
2110EOF
2111
2112test_expect_success 'R: only one import-marks feature allowed per stream' '
2113 test_must_fail git fast-import <input
2114'
2115
2116cat >input << EOF
2117feature export-marks=git.marks
2118blob
2119mark :1
2120data 3
2121hi
2122
2123EOF
2124
2125test_expect_success \
2126 'R: export-marks feature results in a marks file being created' \
2127 'cat input | git fast-import &&
2128 grep :1 git.marks'
2129
2130test_expect_success \
2131 'R: export-marks options can be overridden by commandline options' \
2132 'cat input | git fast-import --export-marks=other.marks &&
2133 grep :1 other.marks'
2134
2135test_expect_success 'R: catch typo in marks file name' '
2136 test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null &&
2137 echo "feature import-marks=nonexistent.marks" |
2138 test_must_fail git fast-import
2139'
2140
2141test_expect_success 'R: import and output marks can be the same file' '
2142 rm -f io.marks &&
2143 blob=$(echo hi | git hash-object --stdin) &&
2144 cat >expect <<-EOF &&
2145 :1 $blob
2146 :2 $blob
2147 EOF
2148 git fast-import --export-marks=io.marks <<-\EOF &&
2149 blob
2150 mark :1
2151 data 3
2152 hi
2153
2154 EOF
2155 git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF &&
2156 blob
2157 mark :2
2158 data 3
2159 hi
2160
2161 EOF
2162 test_cmp expect io.marks
2163'
2164
2165test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' '
2166 rm -f io.marks &&
2167 test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF
2168 blob
2169 mark :1
2170 data 3
2171 hi
2172
2173 EOF
2174'
2175
2176test_expect_success 'R: --import-marks-if-exists' '
2177 rm -f io.marks &&
2178 blob=$(echo hi | git hash-object --stdin) &&
2179 echo ":1 $blob" >expect &&
2180 git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF &&
2181 blob
2182 mark :1
2183 data 3
2184 hi
2185
2186 EOF
2187 test_cmp expect io.marks
2188'
2189
2190test_expect_success 'R: feature import-marks-if-exists' '
2191 rm -f io.marks &&
2192 >expect &&
2193
2194 git fast-import --export-marks=io.marks <<-\EOF &&
2195 feature import-marks-if-exists=not_io.marks
2196 EOF
2197 test_cmp expect io.marks &&
2198
2199 blob=$(echo hi | git hash-object --stdin) &&
2200
2201 echo ":1 $blob" >io.marks &&
2202 echo ":1 $blob" >expect &&
2203 echo ":2 $blob" >>expect &&
2204
2205 git fast-import --export-marks=io.marks <<-\EOF &&
2206 feature import-marks-if-exists=io.marks
2207 blob
2208 mark :2
2209 data 3
2210 hi
2211
2212 EOF
2213 test_cmp expect io.marks &&
2214
2215 echo ":3 $blob" >>expect &&
2216
2217 git fast-import --import-marks=io.marks \
2218 --export-marks=io.marks <<-\EOF &&
2219 feature import-marks-if-exists=not_io.marks
2220 blob
2221 mark :3
2222 data 3
2223 hi
2224
2225 EOF
2226 test_cmp expect io.marks &&
2227
2228 >expect &&
2229
2230 git fast-import --import-marks-if-exists=not_io.marks \
2231 --export-marks=io.marks <<-\EOF &&
2232 feature import-marks-if-exists=io.marks
2233 EOF
2234 test_cmp expect io.marks
2235'
2236
2237cat >input << EOF
2238feature import-marks=marks.out
2239feature export-marks=marks.new
2240EOF
2241
2242test_expect_success \
2243 'R: import to output marks works without any content' \
2244 'cat input | git fast-import &&
2245 test_cmp marks.out marks.new'
2246
2247cat >input <<EOF
2248feature import-marks=nonexistent.marks
2249feature export-marks=marks.new
2250EOF
2251
2252test_expect_success \
2253 'R: import marks prefers commandline marks file over the stream' \
2254 'cat input | git fast-import --import-marks=marks.out &&
2255 test_cmp marks.out marks.new'
2256
2257
2258cat >input <<EOF
2259feature import-marks=nonexistent.marks
2260feature export-marks=combined.marks
2261EOF
2262
2263test_expect_success 'R: multiple --import-marks= should be honoured' '
2264 head -n2 marks.out > one.marks &&
2265 tail -n +3 marks.out > two.marks &&
2266 git fast-import --import-marks=one.marks --import-marks=two.marks <input &&
2267 test_cmp marks.out combined.marks
2268'
2269
2270cat >input <<EOF
2271feature relative-marks
2272feature import-marks=relative.in
2273feature export-marks=relative.out
2274EOF
2275
2276test_expect_success 'R: feature relative-marks should be honoured' '
2277 mkdir -p .git/info/fast-import/ &&
2278 cp marks.new .git/info/fast-import/relative.in &&
2279 git fast-import <input &&
2280 test_cmp marks.new .git/info/fast-import/relative.out
2281'
2282
2283cat >input <<EOF
2284feature relative-marks
2285feature import-marks=relative.in
2286feature no-relative-marks
2287feature export-marks=non-relative.out
2288EOF
2289
2290test_expect_success 'R: feature no-relative-marks should be honoured' '
2291 git fast-import <input &&
2292 test_cmp marks.new non-relative.out
2293'
2294
2295test_expect_success 'R: feature ls supported' '
2296 echo "feature ls" |
2297 git fast-import
2298'
2299
2300test_expect_success 'R: feature cat-blob supported' '
2301 echo "feature cat-blob" |
2302 git fast-import
2303'
2304
2305test_expect_success 'R: cat-blob-fd must be a nonnegative integer' '
2306 test_must_fail git fast-import --cat-blob-fd=-1 </dev/null
2307'
2308
2309test_expect_success !MINGW 'R: print old blob' '
2310 blob=$(echo "yes it can" | git hash-object -w --stdin) &&
2311 cat >expect <<-EOF &&
2312 ${blob} blob 11
2313 yes it can
2314
2315 EOF
2316 echo "cat-blob $blob" |
2317 git fast-import --cat-blob-fd=6 6>actual &&
2318 test_cmp expect actual
2319'
2320
2321test_expect_success !MINGW 'R: in-stream cat-blob-fd not respected' '
2322 echo hello >greeting &&
2323 blob=$(git hash-object -w greeting) &&
2324 cat >expect <<-EOF &&
2325 ${blob} blob 6
2326 hello
2327
2328 EOF
2329 git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF &&
2330 cat-blob $blob
2331 EOF
2332 test_cmp expect actual.3 &&
2333 test_cmp empty actual.1 &&
2334 git fast-import 3>actual.3 >actual.1 <<-EOF &&
2335 option cat-blob-fd=3
2336 cat-blob $blob
2337 EOF
2338 test_cmp empty actual.3 &&
2339 test_cmp expect actual.1
2340'
2341
2342test_expect_success !MINGW 'R: print new blob' '
2343 blob=$(echo "yep yep yep" | git hash-object --stdin) &&
2344 cat >expect <<-EOF &&
2345 ${blob} blob 12
2346 yep yep yep
2347
2348 EOF
2349 git fast-import --cat-blob-fd=6 6>actual <<-\EOF &&
2350 blob
2351 mark :1
2352 data <<BLOB_END
2353 yep yep yep
2354 BLOB_END
2355 cat-blob :1
2356 EOF
2357 test_cmp expect actual
2358'
2359
2360test_expect_success !MINGW 'R: print new blob by sha1' '
2361 blob=$(echo "a new blob named by sha1" | git hash-object --stdin) &&
2362 cat >expect <<-EOF &&
2363 ${blob} blob 25
2364 a new blob named by sha1
2365
2366 EOF
2367 git fast-import --cat-blob-fd=6 6>actual <<-EOF &&
2368 blob
2369 data <<BLOB_END
2370 a new blob named by sha1
2371 BLOB_END
2372 cat-blob $blob
2373 EOF
2374 test_cmp expect actual
2375'
2376
2377test_expect_success 'setup: big file' '
2378 (
2379 echo "the quick brown fox jumps over the lazy dog" >big &&
2380 for i in 1 2 3
2381 do
2382 cat big big big big >bigger &&
2383 cat bigger bigger bigger bigger >big ||
2384 exit
2385 done
2386 )
2387'
2388
2389test_expect_success 'R: print two blobs to stdout' '
2390 blob1=$(git hash-object big) &&
2391 blob1_len=$(wc -c <big) &&
2392 blob2=$(echo hello | git hash-object --stdin) &&
2393 {
2394 echo ${blob1} blob $blob1_len &&
2395 cat big &&
2396 cat <<-EOF
2397
2398 ${blob2} blob 6
2399 hello
2400
2401 EOF
2402 } >expect &&
2403 {
2404 cat <<-\END_PART1 &&
2405 blob
2406 mark :1
2407 data <<data_end
2408 END_PART1
2409 cat big &&
2410 cat <<-\EOF
2411 data_end
2412 blob
2413 mark :2
2414 data <<data_end
2415 hello
2416 data_end
2417 cat-blob :1
2418 cat-blob :2
2419 EOF
2420 } |
2421 git fast-import >actual &&
2422 test_cmp expect actual
2423'
2424
2425test_expect_success PIPE 'R: copy using cat-file' '
2426 expect_id=$(git hash-object big) &&
2427 expect_len=$(wc -c <big) &&
2428 echo $expect_id blob $expect_len >expect.response &&
2429
2430 rm -f blobs &&
2431 cat >frontend <<-\FRONTEND_END &&
2432 #!/bin/sh
2433 FRONTEND_END
2434
2435 mkfifo blobs &&
2436 (
2437 export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE &&
2438 cat <<-\EOF &&
2439 feature cat-blob
2440 blob
2441 mark :1
2442 data <<BLOB
2443 EOF
2444 cat big &&
2445 cat <<-\EOF &&
2446 BLOB
2447 cat-blob :1
2448 EOF
2449
2450 read blob_id type size <&3 &&
2451 echo "$blob_id $type $size" >response &&
2452 head_c $size >blob <&3 &&
2453 read newline <&3 &&
2454
2455 cat <<-EOF &&
2456 commit refs/heads/copied
2457 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2458 data <<COMMIT
2459 copy big file as file3
2460 COMMIT
2461 M 644 inline file3
2462 data <<BLOB
2463 EOF
2464 cat blob &&
2465 echo BLOB
2466 ) 3<blobs |
2467 git fast-import --cat-blob-fd=3 3>blobs &&
2468 git show copied:file3 >actual &&
2469 test_cmp expect.response response &&
2470 test_cmp big actual
2471'
2472
2473test_expect_success PIPE 'R: print blob mid-commit' '
2474 rm -f blobs &&
2475 echo "A blob from _before_ the commit." >expect &&
2476 mkfifo blobs &&
2477 (
2478 exec 3<blobs &&
2479 cat <<-EOF &&
2480 feature cat-blob
2481 blob
2482 mark :1
2483 data <<BLOB
2484 A blob from _before_ the commit.
2485 BLOB
2486 commit refs/heads/temporary
2487 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2488 data <<COMMIT
2489 Empty commit
2490 COMMIT
2491 cat-blob :1
2492 EOF
2493
2494 read blob_id type size <&3 &&
2495 head_c $size >actual <&3 &&
2496 read newline <&3 &&
2497
2498 echo
2499 ) |
2500 git fast-import --cat-blob-fd=3 3>blobs &&
2501 test_cmp expect actual
2502'
2503
2504test_expect_success PIPE 'R: print staged blob within commit' '
2505 rm -f blobs &&
2506 echo "A blob from _within_ the commit." >expect &&
2507 mkfifo blobs &&
2508 (
2509 exec 3<blobs &&
2510 cat <<-EOF &&
2511 feature cat-blob
2512 commit refs/heads/within
2513 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2514 data <<COMMIT
2515 Empty commit
2516 COMMIT
2517 M 644 inline within
2518 data <<BLOB
2519 A blob from _within_ the commit.
2520 BLOB
2521 EOF
2522
2523 to_get=$(
2524 echo "A blob from _within_ the commit." |
2525 git hash-object --stdin
2526 ) &&
2527 echo "cat-blob $to_get" &&
2528
2529 read blob_id type size <&3 &&
2530 head_c $size >actual <&3 &&
2531 read newline <&3 &&
2532
2533 echo deleteall
2534 ) |
2535 git fast-import --cat-blob-fd=3 3>blobs &&
2536 test_cmp expect actual
2537'
2538
2539cat >input << EOF
2540option git quiet
2541blob
2542data 3
2543hi
2544
2545EOF
2546
2547test_expect_success 'R: quiet option results in no stats being output' '
2548 cat input | git fast-import 2> output &&
2549 test_cmp empty output
2550'
2551
2552test_expect_success 'R: feature done means terminating "done" is mandatory' '
2553 echo feature done | test_must_fail git fast-import &&
2554 test_must_fail git fast-import --done </dev/null
2555'
2556
2557test_expect_success 'R: terminating "done" with trailing gibberish is ok' '
2558 git fast-import <<-\EOF &&
2559 feature done
2560 done
2561 trailing gibberish
2562 EOF
2563 git fast-import <<-\EOF
2564 done
2565 more trailing gibberish
2566 EOF
2567'
2568
2569test_expect_success 'R: terminating "done" within commit' '
2570 cat >expect <<-\EOF &&
2571 OBJID
2572 :000000 100644 OBJID OBJID A hello.c
2573 :000000 100644 OBJID OBJID A hello2.c
2574 EOF
2575 git fast-import <<-EOF &&
2576 commit refs/heads/done-ends
2577 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2578 data <<EOT
2579 Commit terminated by "done" command
2580 EOT
2581 M 100644 inline hello.c
2582 data <<EOT
2583 Hello, world.
2584 EOT
2585 C hello.c hello2.c
2586 done
2587 EOF
2588 git rev-list done-ends |
2589 git diff-tree -r --stdin --root --always |
2590 sed -e "s/$_x40/OBJID/g" >actual &&
2591 test_cmp expect actual
2592'
2593
2594cat >input <<EOF
2595option git non-existing-option
2596EOF
2597
2598test_expect_success 'R: die on unknown option' '
2599 test_must_fail git fast-import <input
2600'
2601
2602test_expect_success 'R: unknown commandline options are rejected' '\
2603 test_must_fail git fast-import --non-existing-option < /dev/null
2604'
2605
2606test_expect_success 'R: die on invalid option argument' '
2607 echo "option git active-branches=-5" |
2608 test_must_fail git fast-import &&
2609 echo "option git depth=" |
2610 test_must_fail git fast-import &&
2611 test_must_fail git fast-import --depth="5 elephants" </dev/null
2612'
2613
2614cat >input <<EOF
2615option non-existing-vcs non-existing-option
2616EOF
2617
2618test_expect_success 'R: ignore non-git options' '
2619 git fast-import <input
2620'
2621
2622##
2623## R: very large blobs
2624##
2625blobsize=$((2*1024*1024 + 53))
2626test-genrandom bar $blobsize >expect
2627cat >input <<INPUT_END
2628commit refs/heads/big-file
2629committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2630data <<COMMIT
2631R - big file
2632COMMIT
2633
2634M 644 inline big1
2635data $blobsize
2636INPUT_END
2637cat expect >>input
2638cat >>input <<INPUT_END
2639M 644 inline big2
2640data $blobsize
2641INPUT_END
2642cat expect >>input
2643echo >>input
2644
2645test_expect_success \
2646 'R: blob bigger than threshold' \
2647 'test_create_repo R &&
2648 git --git-dir=R/.git fast-import --big-file-threshold=1 <input'
2649
2650test_expect_success 'R: verify created pack' '
2651 (
2652 cd R &&
2653 verify_packs -v > ../verify
2654 )
2655'
2656
2657test_expect_success \
2658 'R: verify written objects' \
2659 'git --git-dir=R/.git cat-file blob big-file:big1 >actual &&
2660 test_cmp_bin expect actual &&
2661 a=$(git --git-dir=R/.git rev-parse big-file:big1) &&
2662 b=$(git --git-dir=R/.git rev-parse big-file:big2) &&
2663 test $a = $b'
2664test_expect_success \
2665 'R: blob appears only once' \
2666 'n=$(grep $a verify | wc -l) &&
2667 test 1 = $n'
2668
2669###
2670### series S
2671###
2672#
2673# Make sure missing spaces and EOLs after mark references
2674# cause errors.
2675#
2676# Setup:
2677#
2678# 1--2--4
2679# \ /
2680# -3-
2681#
2682# commit marks: 301, 302, 303, 304
2683# blob marks: 403, 404, resp.
2684# note mark: 202
2685#
2686# The error message when a space is missing not at the
2687# end of the line is:
2688#
2689# Missing space after ..
2690#
2691# or when extra characters come after the mark at the end
2692# of the line:
2693#
2694# Garbage after ..
2695#
2696# or when the dataref is neither "inline " or a known SHA1,
2697#
2698# Invalid dataref ..
2699#
2700test_tick
2701
2702cat >input <<INPUT_END
2703commit refs/heads/S
2704mark :301
2705committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2706data <<COMMIT
2707commit 1
2708COMMIT
2709M 100644 inline hello.c
2710data <<BLOB
2711blob 1
2712BLOB
2713
2714commit refs/heads/S
2715mark :302
2716committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2717data <<COMMIT
2718commit 2
2719COMMIT
2720from :301
2721M 100644 inline hello.c
2722data <<BLOB
2723blob 2
2724BLOB
2725
2726blob
2727mark :403
2728data <<BLOB
2729blob 3
2730BLOB
2731
2732blob
2733mark :202
2734data <<BLOB
2735note 2
2736BLOB
2737INPUT_END
2738
2739test_expect_success 'S: initialize for S tests' '
2740 git fast-import --export-marks=marks <input
2741'
2742
2743#
2744# filemodify, three datarefs
2745#
2746test_expect_success 'S: filemodify with garbage after mark must fail' '
2747 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2748 commit refs/heads/S
2749 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2750 data <<COMMIT
2751 commit N
2752 COMMIT
2753 M 100644 :403x hello.c
2754 EOF
2755 cat err &&
2756 test_i18ngrep "space after mark" err
2757'
2758
2759# inline is misspelled; fast-import thinks it is some unknown dataref
2760test_expect_success 'S: filemodify with garbage after inline must fail' '
2761 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2762 commit refs/heads/S
2763 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2764 data <<COMMIT
2765 commit N
2766 COMMIT
2767 M 100644 inlineX hello.c
2768 data <<BLOB
2769 inline
2770 BLOB
2771 EOF
2772 cat err &&
2773 test_i18ngrep "nvalid dataref" err
2774'
2775
2776test_expect_success 'S: filemodify with garbage after sha1 must fail' '
2777 sha1=$(grep :403 marks | cut -d\ -f2) &&
2778 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2779 commit refs/heads/S
2780 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2781 data <<COMMIT
2782 commit N
2783 COMMIT
2784 M 100644 ${sha1}x hello.c
2785 EOF
2786 cat err &&
2787 test_i18ngrep "space after SHA1" err
2788'
2789
2790#
2791# notemodify, three ways to say dataref
2792#
2793test_expect_success 'S: notemodify with garabge after mark dataref must fail' '
2794 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2795 commit refs/heads/S
2796 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2797 data <<COMMIT
2798 commit S note dataref markref
2799 COMMIT
2800 N :202x :302
2801 EOF
2802 cat err &&
2803 test_i18ngrep "space after mark" err
2804'
2805
2806test_expect_success 'S: notemodify with garbage after inline dataref must fail' '
2807 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2808 commit refs/heads/S
2809 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2810 data <<COMMIT
2811 commit S note dataref inline
2812 COMMIT
2813 N inlineX :302
2814 data <<BLOB
2815 note blob
2816 BLOB
2817 EOF
2818 cat err &&
2819 test_i18ngrep "nvalid dataref" err
2820'
2821
2822test_expect_success 'S: notemodify with garbage after sha1 dataref must fail' '
2823 sha1=$(grep :202 marks | cut -d\ -f2) &&
2824 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2825 commit refs/heads/S
2826 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2827 data <<COMMIT
2828 commit S note dataref sha1
2829 COMMIT
2830 N ${sha1}x :302
2831 EOF
2832 cat err &&
2833 test_i18ngrep "space after SHA1" err
2834'
2835
2836#
2837# notemodify, mark in commit-ish
2838#
2839test_expect_success 'S: notemodify with garbage after mark commit-ish must fail' '
2840 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2841 commit refs/heads/Snotes
2842 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2843 data <<COMMIT
2844 commit S note commit-ish
2845 COMMIT
2846 N :202 :302x
2847 EOF
2848 cat err &&
2849 test_i18ngrep "after mark" err
2850'
2851
2852#
2853# from
2854#
2855test_expect_success 'S: from with garbage after mark must fail' '
2856 test_must_fail \
2857 git fast-import --import-marks=marks --export-marks=marks <<-EOF 2>err &&
2858 commit refs/heads/S2
2859 mark :303
2860 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2861 data <<COMMIT
2862 commit 3
2863 COMMIT
2864 from :301x
2865 M 100644 :403 hello.c
2866 EOF
2867
2868
2869 # go create the commit, need it for merge test
2870 git fast-import --import-marks=marks --export-marks=marks <<-EOF &&
2871 commit refs/heads/S2
2872 mark :303
2873 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2874 data <<COMMIT
2875 commit 3
2876 COMMIT
2877 from :301
2878 M 100644 :403 hello.c
2879 EOF
2880
2881 # now evaluate the error
2882 cat err &&
2883 test_i18ngrep "after mark" err
2884'
2885
2886
2887#
2888# merge
2889#
2890test_expect_success 'S: merge with garbage after mark must fail' '
2891 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2892 commit refs/heads/S
2893 mark :304
2894 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2895 data <<COMMIT
2896 merge 4
2897 COMMIT
2898 from :302
2899 merge :303x
2900 M 100644 :403 hello.c
2901 EOF
2902 cat err &&
2903 test_i18ngrep "after mark" err
2904'
2905
2906#
2907# tag, from markref
2908#
2909test_expect_success 'S: tag with garbage after mark must fail' '
2910 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2911 tag refs/tags/Stag
2912 from :302x
2913 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2914 data <<TAG
2915 tag S
2916 TAG
2917 EOF
2918 cat err &&
2919 test_i18ngrep "after mark" err
2920'
2921
2922#
2923# cat-blob markref
2924#
2925test_expect_success 'S: cat-blob with garbage after mark must fail' '
2926 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2927 cat-blob :403x
2928 EOF
2929 cat err &&
2930 test_i18ngrep "after mark" err
2931'
2932
2933#
2934# ls markref
2935#
2936test_expect_success 'S: ls with garbage after mark must fail' '
2937 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2938 ls :302x hello.c
2939 EOF
2940 cat err &&
2941 test_i18ngrep "space after mark" err
2942'
2943
2944test_expect_success 'S: ls with garbage after sha1 must fail' '
2945 sha1=$(grep :302 marks | cut -d\ -f2) &&
2946 test_must_fail git fast-import --import-marks=marks <<-EOF 2>err &&
2947 ls ${sha1}x hello.c
2948 EOF
2949 cat err &&
2950 test_i18ngrep "space after tree-ish" err
2951'
2952
2953###
2954### series T (ls)
2955###
2956# Setup is carried over from series S.
2957
2958test_expect_success 'T: ls root tree' '
2959 sed -e "s/Z\$//" >expect <<-EOF &&
2960 040000 tree $(git rev-parse S^{tree}) Z
2961 EOF
2962 sha1=$(git rev-parse --verify S) &&
2963 git fast-import --import-marks=marks <<-EOF >actual &&
2964 ls $sha1 ""
2965 EOF
2966 test_cmp expect actual
2967'
2968
2969test_expect_success 'T: delete branch' '
2970 git branch to-delete &&
2971 git fast-import <<-EOF &&
2972 reset refs/heads/to-delete
2973 from 0000000000000000000000000000000000000000
2974 EOF
2975 test_must_fail git rev-parse --verify refs/heads/to-delete
2976'
2977
2978test_expect_success 'T: empty reset doesnt delete branch' '
2979 git branch not-to-delete &&
2980 git fast-import <<-EOF &&
2981 reset refs/heads/not-to-delete
2982 EOF
2983 git show-ref &&
2984 git rev-parse --verify refs/heads/not-to-delete
2985'
2986
2987###
2988### series U (filedelete)
2989###
2990
2991cat >input <<INPUT_END
2992commit refs/heads/U
2993committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
2994data <<COMMIT
2995test setup
2996COMMIT
2997M 100644 inline hello.c
2998data <<BLOB
2999blob 1
3000BLOB
3001M 100644 inline good/night.txt
3002data <<BLOB
3003sleep well
3004BLOB
3005M 100644 inline good/bye.txt
3006data <<BLOB
3007au revoir
3008BLOB
3009
3010INPUT_END
3011
3012test_expect_success 'U: initialize for U tests' '
3013 git fast-import <input
3014'
3015
3016cat >input <<INPUT_END
3017commit refs/heads/U
3018committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3019data <<COMMIT
3020delete good/night.txt
3021COMMIT
3022from refs/heads/U^0
3023D good/night.txt
3024
3025INPUT_END
3026
3027test_expect_success 'U: filedelete file succeeds' '
3028 git fast-import <input
3029'
3030
3031cat >expect <<EOF
3032:100644 000000 2907ebb4bf85d91bf0716bb3bd8a68ef48d6da76 0000000000000000000000000000000000000000 D good/night.txt
3033EOF
3034
3035git diff-tree -M -r U^1 U >actual
3036
3037test_expect_success 'U: validate file delete result' '
3038 compare_diff_raw expect actual
3039'
3040
3041cat >input <<INPUT_END
3042commit refs/heads/U
3043committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3044data <<COMMIT
3045delete good dir
3046COMMIT
3047from refs/heads/U^0
3048D good
3049
3050INPUT_END
3051
3052test_expect_success 'U: filedelete directory succeeds' '
3053 git fast-import <input
3054'
3055
3056cat >expect <<EOF
3057:100644 000000 69cb75792f55123d8389c156b0b41c2ff00ed507 0000000000000000000000000000000000000000 D good/bye.txt
3058EOF
3059
3060git diff-tree -M -r U^1 U >actual
3061
3062test_expect_success 'U: validate directory delete result' '
3063 compare_diff_raw expect actual
3064'
3065
3066cat >input <<INPUT_END
3067commit refs/heads/U
3068committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
3069data <<COMMIT
3070must succeed
3071COMMIT
3072from refs/heads/U^0
3073D ""
3074
3075INPUT_END
3076
3077test_expect_success 'U: filedelete root succeeds' '
3078 git fast-import <input
3079'
3080
3081cat >expect <<EOF
3082:100644 000000 c18147dc648481eeb65dc5e66628429a64843327 0000000000000000000000000000000000000000 D hello.c
3083EOF
3084
3085git diff-tree -M -r U^1 U >actual
3086
3087test_expect_success 'U: validate root delete result' '
3088 compare_diff_raw expect actual
3089'
3090
3091test_done