]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9300-fast-import.sh
fast-import: test the new option command
[thirdparty/git.git] / t / t9300-fast-import.sh
CommitLineData
50aee995
SP
1#!/bin/sh
2#
3# Copyright (c) 2007 Shawn Pearce
4#
5
eaa2a6fc 6test_description='test git fast-import utility'
50aee995 7. ./test-lib.sh
bfdbee98 8. "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
50aee995 9
8232dc42
SP
10file2_data='file2
11second line of EOF'
12
13file3_data='EOF
14in 3rd file
15 END'
16
17file4_data=abcd
18file4_len=4
19
b715cfbb
SP
20file5_data='an inline file.
21 we should see it later.'
22
23file6_data='#!/bin/sh
24echo "$@"'
25
50aee995
SP
26###
27### series A
28###
29
30test_tick
31cat >input <<INPUT_END
32blob
33mark :2
34data <<EOF
8232dc42 35$file2_data
50aee995
SP
36EOF
37
38blob
39mark :3
40data <<END
8232dc42 41$file3_data
50aee995
SP
42END
43
44blob
45mark :4
8232dc42
SP
46data $file4_len
47$file4_data
50aee995
SP
48commit refs/heads/master
49mark :5
50committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
51data <<COMMIT
52initial
53COMMIT
54
55M 644 :2 file2
56M 644 :3 file3
57M 755 :4 file4
58
88fbf67b
JH
59tag series-A
60from :5
61data <<EOF
62An annotated tag without a tagger
63EOF
64
50aee995
SP
65INPUT_END
66test_expect_success \
67 'A: create pack from stdin' \
eaa2a6fc 68 'git fast-import --export-marks=marks.out <input &&
5be60078 69 git whatchanged master'
50aee995
SP
70test_expect_success \
71 'A: verify pack' \
5be60078 72 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
50aee995
SP
73
74cat >expect <<EOF
75author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
76committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
77
78initial
79EOF
80test_expect_success \
81 'A: verify commit' \
5be60078 82 'git cat-file commit master | sed 1d >actual &&
3af82863 83 test_cmp expect actual'
50aee995
SP
84
85cat >expect <<EOF
86100644 blob file2
87100644 blob file3
88100755 blob file4
89EOF
90test_expect_success \
91 'A: verify tree' \
5be60078 92 'git cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
3af82863 93 test_cmp expect actual'
50aee995 94
8232dc42 95echo "$file2_data" >expect
50aee995
SP
96test_expect_success \
97 'A: verify file2' \
3af82863 98 'git cat-file blob master:file2 >actual && test_cmp expect actual'
50aee995 99
8232dc42 100echo "$file3_data" >expect
50aee995
SP
101test_expect_success \
102 'A: verify file3' \
3af82863 103 'git cat-file blob master:file3 >actual && test_cmp expect actual'
50aee995 104
8232dc42 105printf "$file4_data" >expect
50aee995
SP
106test_expect_success \
107 'A: verify file4' \
3af82863 108 'git cat-file blob master:file4 >actual && test_cmp expect actual'
50aee995 109
88fbf67b
JH
110cat >expect <<EOF
111object $(git rev-parse refs/heads/master)
112type commit
113tag series-A
114
115An annotated tag without a tagger
116EOF
117test_expect_success 'A: verify tag/series-A' '
118 git cat-file tag tags/series-A >actual &&
119 test_cmp expect actual
120'
121
50aee995 122cat >expect <<EOF
5be60078
JH
123:2 `git rev-parse --verify master:file2`
124:3 `git rev-parse --verify master:file3`
125:4 `git rev-parse --verify master:file4`
126:5 `git rev-parse --verify master^0`
50aee995
SP
127EOF
128test_expect_success \
129 'A: verify marks output' \
3af82863 130 'test_cmp expect marks.out'
50aee995 131
e8438420
SP
132test_expect_success \
133 'A: verify marks import' \
eaa2a6fc 134 'git fast-import \
e8438420
SP
135 --import-marks=marks.out \
136 --export-marks=marks.new \
137 </dev/null &&
3af82863 138 test_cmp expect marks.new'
e8438420 139
aac65ed1
SP
140test_tick
141cat >input <<INPUT_END
142commit refs/heads/verify--import-marks
143committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
144data <<COMMIT
145recreate from :5
146COMMIT
147
148from :5
149M 755 :2 copy-of-file2
150
151INPUT_END
152test_expect_success \
153 'A: verify marks import does not crash' \
eaa2a6fc 154 'git fast-import --import-marks=marks.out <input &&
5be60078 155 git whatchanged verify--import-marks'
aac65ed1
SP
156test_expect_success \
157 'A: verify pack' \
5be60078 158 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
aac65ed1
SP
159cat >expect <<EOF
160:000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2
161EOF
5be60078 162git diff-tree -M -r master verify--import-marks >actual
aac65ed1
SP
163test_expect_success \
164 'A: verify diff' \
165 'compare_diff_raw expect actual &&
5be60078
JH
166 test `git rev-parse --verify master:file2` \
167 = `git rev-parse --verify verify--import-marks:copy-of-file2`'
aac65ed1 168
50aee995
SP
169###
170### series B
171###
172
173test_tick
174cat >input <<INPUT_END
175commit refs/heads/branch
176mark :1
177committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
178data <<COMMIT
179corrupt
180COMMIT
181
182from refs/heads/master
183M 755 0000000000000000000000000000000000000001 zero1
184
185INPUT_END
41ac414e 186test_expect_success 'B: fail on invalid blob sha1' '
eaa2a6fc 187 test_must_fail git fast-import <input
41ac414e 188'
50aee995
SP
189rm -f .git/objects/pack_* .git/objects/index_*
190
ea08a6fd
SP
191cat >input <<INPUT_END
192commit .badbranchname
193committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
194data <<COMMIT
195corrupt
196COMMIT
197
198from refs/heads/master
199
200INPUT_END
41ac414e 201test_expect_success 'B: fail on invalid branch name ".badbranchname"' '
eaa2a6fc 202 test_must_fail git fast-import <input
41ac414e 203'
ea08a6fd
SP
204rm -f .git/objects/pack_* .git/objects/index_*
205
206cat >input <<INPUT_END
207commit bad[branch]name
208committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
209data <<COMMIT
210corrupt
211COMMIT
212
213from refs/heads/master
214
215INPUT_END
41ac414e 216test_expect_success 'B: fail on invalid branch name "bad[branch]name"' '
eaa2a6fc 217 test_must_fail git fast-import <input
41ac414e 218'
ea08a6fd
SP
219rm -f .git/objects/pack_* .git/objects/index_*
220
221cat >input <<INPUT_END
222commit TEMP_TAG
223committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
224data <<COMMIT
225tag base
226COMMIT
227
228from refs/heads/master
229
230INPUT_END
231test_expect_success \
232 'B: accept branch name "TEMP_TAG"' \
eaa2a6fc 233 'git fast-import <input &&
ea08a6fd
SP
234 test -f .git/TEMP_TAG &&
235 test `git rev-parse master` = `git rev-parse TEMP_TAG^`'
236rm -f .git/TEMP_TAG
237
50aee995
SP
238###
239### series C
240###
241
eaa2a6fc 242newf=`echo hi newf | git hash-object -w --stdin`
5be60078 243oldf=`git rev-parse --verify master:file2`
50aee995
SP
244test_tick
245cat >input <<INPUT_END
246commit refs/heads/branch
247committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
248data <<COMMIT
249second
250COMMIT
251
252from refs/heads/master
253M 644 $oldf file2/oldf
254M 755 $newf file2/newf
255D file3
256
257INPUT_END
258test_expect_success \
259 'C: incremental import create pack from stdin' \
eaa2a6fc 260 'git fast-import <input &&
5be60078 261 git whatchanged branch'
50aee995
SP
262test_expect_success \
263 'C: verify pack' \
5be60078 264 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
50aee995
SP
265test_expect_success \
266 'C: validate reuse existing blob' \
5be60078
JH
267 'test $newf = `git rev-parse --verify branch:file2/newf`
268 test $oldf = `git rev-parse --verify branch:file2/oldf`'
50aee995
SP
269
270cat >expect <<EOF
5be60078 271parent `git rev-parse --verify master^0`
50aee995
SP
272author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
273committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
274
275second
276EOF
277test_expect_success \
278 'C: verify commit' \
5be60078 279 'git cat-file commit branch | sed 1d >actual &&
3af82863 280 test_cmp expect actual'
50aee995
SP
281
282cat >expect <<EOF
283:000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
284:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
285:100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
286EOF
5be60078 287git diff-tree -M -r master branch >actual
50aee995
SP
288test_expect_success \
289 'C: validate rename result' \
290 'compare_diff_raw expect actual'
291
b715cfbb
SP
292###
293### series D
294###
295
296test_tick
297cat >input <<INPUT_END
298commit refs/heads/branch
299committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
300data <<COMMIT
301third
302COMMIT
303
304from refs/heads/branch^0
305M 644 inline newdir/interesting
306data <<EOF
307$file5_data
308EOF
309
310M 755 inline newdir/exec.sh
311data <<EOF
312$file6_data
313EOF
314
315INPUT_END
316test_expect_success \
317 'D: inline data in commit' \
eaa2a6fc 318 'git fast-import <input &&
5be60078 319 git whatchanged branch'
b715cfbb
SP
320test_expect_success \
321 'D: verify pack' \
5be60078 322 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
b715cfbb
SP
323
324cat >expect <<EOF
325:000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A newdir/exec.sh
326:000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A newdir/interesting
327EOF
5be60078 328git diff-tree -M -r branch^ branch >actual
b715cfbb
SP
329test_expect_success \
330 'D: validate new files added' \
331 'compare_diff_raw expect actual'
332
333echo "$file5_data" >expect
334test_expect_success \
335 'D: verify file5' \
5be60078 336 'git cat-file blob branch:newdir/interesting >actual &&
3af82863 337 test_cmp expect actual'
b715cfbb
SP
338
339echo "$file6_data" >expect
340test_expect_success \
341 'D: verify file6' \
5be60078 342 'git cat-file blob branch:newdir/exec.sh >actual &&
3af82863 343 test_cmp expect actual'
b715cfbb 344
63e0c8b3
SP
345###
346### series E
347###
348
349cat >input <<INPUT_END
350commit refs/heads/branch
351author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
352committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
353data <<COMMIT
354RFC 2822 type date
355COMMIT
356
357from refs/heads/branch^0
358
359INPUT_END
41ac414e 360test_expect_success 'E: rfc2822 date, --date-format=raw' '
eaa2a6fc 361 test_must_fail git fast-import --date-format=raw <input
41ac414e 362'
63e0c8b3
SP
363test_expect_success \
364 'E: rfc2822 date, --date-format=rfc2822' \
eaa2a6fc 365 'git fast-import --date-format=rfc2822 <input'
63e0c8b3
SP
366test_expect_success \
367 'E: verify pack' \
5be60078 368 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
63e0c8b3
SP
369
370cat >expect <<EOF
371author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
372committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
373
374RFC 2822 type date
375EOF
376test_expect_success \
377 'E: verify commit' \
5be60078 378 'git cat-file commit branch | sed 1,2d >actual &&
3af82863 379 test_cmp expect actual'
63e0c8b3 380
7073e69e
SP
381###
382### series F
383###
384
5be60078 385old_branch=`git rev-parse --verify branch^0`
7073e69e
SP
386test_tick
387cat >input <<INPUT_END
388commit refs/heads/branch
389committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
390data <<COMMIT
391losing things already?
392COMMIT
393
394from refs/heads/branch~1
395
396reset refs/heads/other
397from refs/heads/branch
398
399INPUT_END
400test_expect_success \
401 'F: non-fast-forward update skips' \
eaa2a6fc 402 'if git fast-import <input
7073e69e
SP
403 then
404 echo BAD gfi did not fail
405 return 1
406 else
5be60078 407 if test $old_branch = `git rev-parse --verify branch^0`
7073e69e
SP
408 then
409 : branch unaffected and failure returned
410 return 0
411 else
412 echo BAD gfi changed branch $old_branch
413 return 1
414 fi
415 fi
416 '
417test_expect_success \
418 'F: verify pack' \
5be60078 419 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
7073e69e
SP
420
421cat >expect <<EOF
5be60078
JH
422tree `git rev-parse branch~1^{tree}`
423parent `git rev-parse branch~1`
7073e69e
SP
424author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
425committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
426
427losing things already?
428EOF
429test_expect_success \
430 'F: verify other commit' \
5be60078 431 'git cat-file commit other >actual &&
3af82863 432 test_cmp expect actual'
7073e69e
SP
433
434###
435### series G
436###
437
5be60078 438old_branch=`git rev-parse --verify branch^0`
7073e69e
SP
439test_tick
440cat >input <<INPUT_END
441commit refs/heads/branch
442committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
443data <<COMMIT
444losing things already?
445COMMIT
446
447from refs/heads/branch~1
448
449INPUT_END
450test_expect_success \
451 'G: non-fast-forward update forced' \
eaa2a6fc 452 'git fast-import --force <input'
7073e69e
SP
453test_expect_success \
454 'G: verify pack' \
5be60078 455 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
7073e69e
SP
456test_expect_success \
457 'G: branch changed, but logged' \
5be60078
JH
458 'test $old_branch != `git rev-parse --verify branch^0` &&
459 test $old_branch = `git rev-parse --verify branch@{1}`'
7073e69e 460
825769a8
SP
461###
462### series H
463###
464
465test_tick
466cat >input <<INPUT_END
467commit refs/heads/H
468committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
469data <<COMMIT
470third
471COMMIT
472
473from refs/heads/branch^0
474M 644 inline i-will-die
475data <<EOF
476this file will never exist.
477EOF
478
479deleteall
480M 644 inline h/e/l/lo
481data <<EOF
482$file5_data
483EOF
484
485INPUT_END
486test_expect_success \
487 'H: deletall, add 1' \
eaa2a6fc 488 'git fast-import <input &&
5be60078 489 git whatchanged H'
825769a8
SP
490test_expect_success \
491 'H: verify pack' \
5be60078 492 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
825769a8
SP
493
494cat >expect <<EOF
495:100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf
496:100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf
497:100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4
498:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo
499:100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh
500EOF
5be60078 501git diff-tree -M -r H^ H >actual
825769a8
SP
502test_expect_success \
503 'H: validate old files removed, new files added' \
504 'compare_diff_raw expect actual'
505
506echo "$file5_data" >expect
507test_expect_success \
508 'H: verify file' \
5be60078 509 'git cat-file blob H:h/e/l/lo >actual &&
3af82863 510 test_cmp expect actual'
825769a8 511
bdf1c06d
SP
512###
513### series I
514###
515
516cat >input <<INPUT_END
517commit refs/heads/export-boundary
518committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
519data <<COMMIT
520we have a border. its only 40 characters wide.
521COMMIT
522
523from refs/heads/branch
524
525INPUT_END
526test_expect_success \
527 'I: export-pack-edges' \
eaa2a6fc 528 'git fast-import --export-pack-edges=edges.list <input'
bdf1c06d
SP
529
530cat >expect <<EOF
5be60078 531.git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
bdf1c06d
SP
532EOF
533test_expect_success \
534 'I: verify edge list' \
535 'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
3af82863 536 test_cmp expect actual'
bdf1c06d 537
ea5e370a
SP
538###
539### series J
540###
541
542cat >input <<INPUT_END
543commit refs/heads/J
544committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
545data <<COMMIT
546create J
547COMMIT
548
549from refs/heads/branch
550
551reset refs/heads/J
552
553commit refs/heads/J
554committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
555data <<COMMIT
556initialize J
557COMMIT
558
559INPUT_END
560test_expect_success \
561 'J: reset existing branch creates empty commit' \
eaa2a6fc 562 'git fast-import <input'
ea5e370a
SP
563test_expect_success \
564 'J: branch has 1 commit, empty tree' \
5be60078 565 'test 1 = `git rev-list J | wc -l` &&
ea5e370a
SP
566 test 0 = `git ls-tree J | wc -l`'
567
568###
569### series K
570###
571
572cat >input <<INPUT_END
573commit refs/heads/K
574committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
575data <<COMMIT
576create K
577COMMIT
578
579from refs/heads/branch
580
581commit refs/heads/K
582committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
583data <<COMMIT
584redo K
585COMMIT
586
587from refs/heads/branch^1
588
589INPUT_END
590test_expect_success \
591 'K: reinit branch with from' \
eaa2a6fc 592 'git fast-import <input'
ea5e370a
SP
593test_expect_success \
594 'K: verify K^1 = branch^1' \
5be60078
JH
595 'test `git rev-parse --verify branch^1` \
596 = `git rev-parse --verify K^1`'
ea5e370a 597
e7411303
JK
598###
599### series L
600###
601
602cat >input <<INPUT_END
603blob
604mark :1
605data <<EOF
606some data
607EOF
608
609blob
610mark :2
611data <<EOF
612other data
613EOF
614
615commit refs/heads/L
616committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
617data <<COMMIT
618create L
619COMMIT
620
621M 644 :1 b.
622M 644 :1 b/other
623M 644 :1 ba
624
625commit refs/heads/L
626committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
627data <<COMMIT
628update L
629COMMIT
630
631M 644 :2 b.
632M 644 :2 b/other
633M 644 :2 ba
634INPUT_END
635
636cat >expect <<EXPECT_END
637:100644 100644 4268632... 55d3a52... M b.
638:040000 040000 0ae5cac... 443c768... M b
639:100644 100644 4268632... 55d3a52... M ba
640EXPECT_END
641
642test_expect_success \
643 'L: verify internal tree sorting' \
eaa2a6fc 644 'git fast-import <input &&
82cb8afa 645 git diff-tree --abbrev --raw L^ L >output &&
3af82863 646 test_cmp expect output'
e7411303 647
f39a946a
SP
648###
649### series M
650###
651
652test_tick
653cat >input <<INPUT_END
654commit refs/heads/M1
655committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
656data <<COMMIT
657file rename
658COMMIT
659
660from refs/heads/branch^0
661R file2/newf file2/n.e.w.f
662
663INPUT_END
664
665cat >expect <<EOF
666:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f
667EOF
668test_expect_success \
669 'M: rename file in same subdirectory' \
eaa2a6fc 670 'git fast-import <input &&
f39a946a
SP
671 git diff-tree -M -r M1^ M1 >actual &&
672 compare_diff_raw expect actual'
673
674cat >input <<INPUT_END
675commit refs/heads/M2
676committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
677data <<COMMIT
678file rename
679COMMIT
680
681from refs/heads/branch^0
682R file2/newf i/am/new/to/you
683
684INPUT_END
685
686cat >expect <<EOF
687:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you
688EOF
689test_expect_success \
690 'M: rename file to new subdirectory' \
eaa2a6fc 691 'git fast-import <input &&
f39a946a
SP
692 git diff-tree -M -r M2^ M2 >actual &&
693 compare_diff_raw expect actual'
694
695cat >input <<INPUT_END
696commit refs/heads/M3
697committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
698data <<COMMIT
699file rename
700COMMIT
701
702from refs/heads/M2^0
703R i other/sub
704
705INPUT_END
706
707cat >expect <<EOF
708:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you
709EOF
710test_expect_success \
711 'M: rename subdirectory to new subdirectory' \
eaa2a6fc 712 'git fast-import <input &&
f39a946a
SP
713 git diff-tree -M -r M3^ M3 >actual &&
714 compare_diff_raw expect actual'
715
b6f3481b
SP
716###
717### series N
718###
719
720test_tick
721cat >input <<INPUT_END
722commit refs/heads/N1
723committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
724data <<COMMIT
725file copy
726COMMIT
727
728from refs/heads/branch^0
729C file2/newf file2/n.e.w.f
730
731INPUT_END
732
733cat >expect <<EOF
734:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f
735EOF
736test_expect_success \
737 'N: copy file in same subdirectory' \
eaa2a6fc 738 'git fast-import <input &&
b6f3481b
SP
739 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
740 compare_diff_raw expect actual'
741
742cat >input <<INPUT_END
743commit refs/heads/N2
744committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
745data <<COMMIT
746clean directory copy
747COMMIT
748
749from refs/heads/branch^0
750C file2 file3
751
752commit refs/heads/N2
753committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
754data <<COMMIT
755modify directory copy
756COMMIT
757
758M 644 inline file3/file5
759data <<EOF
760$file5_data
761EOF
762
763INPUT_END
764
765cat >expect <<EOF
766:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
767:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
768:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
769EOF
770test_expect_success \
771 'N: copy then modify subdirectory' \
eaa2a6fc 772 'git fast-import <input &&
b6f3481b
SP
773 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
774 compare_diff_raw expect actual'
775
776cat >input <<INPUT_END
777commit refs/heads/N3
778committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
779data <<COMMIT
780dirty directory copy
781COMMIT
782
783from refs/heads/branch^0
784M 644 inline file2/file5
785data <<EOF
786$file5_data
787EOF
788
789C file2 file3
790D file2/file5
791
792INPUT_END
793
794test_expect_success \
795 'N: copy dirty subdirectory' \
eaa2a6fc
NS
796 'git fast-import <input &&
797 test `git rev-parse N2^{tree}` = `git rev-parse N3^{tree}`'
b6f3481b 798
401d53fa
SP
799###
800### series O
801###
802
803cat >input <<INPUT_END
804#we will
805commit refs/heads/O1
806# -- ignore all of this text
807committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
808# $GIT_COMMITTER_NAME has inserted here for his benefit.
809data <<COMMIT
810dirty directory copy
811COMMIT
812
813# don't forget the import blank line!
814#
815# yes, we started from our usual base of branch^0.
816# i like branch^0.
817from refs/heads/branch^0
818# and we need to reuse file2/file5 from N3 above.
819M 644 inline file2/file5
820# otherwise the tree will be different
821data <<EOF
822$file5_data
823EOF
824
825# don't forget to copy file2 to file3
826C file2 file3
827#
828# or to delete file5 from file2.
829D file2/file5
830# are we done yet?
831
832INPUT_END
833
834test_expect_success \
835 'O: comments are all skipped' \
eaa2a6fc
NS
836 'git fast-import <input &&
837 test `git rev-parse N3` = `git rev-parse O1`'
401d53fa 838
2c570cde
SP
839cat >input <<INPUT_END
840commit refs/heads/O2
841committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
842data <<COMMIT
843dirty directory copy
844COMMIT
845from refs/heads/branch^0
846M 644 inline file2/file5
847data <<EOF
848$file5_data
849EOF
850C file2 file3
851D file2/file5
852
853INPUT_END
854
855test_expect_success \
856 'O: blank lines not necessary after data commands' \
eaa2a6fc
NS
857 'git fast-import <input &&
858 test `git rev-parse N3` = `git rev-parse O2`'
2c570cde 859
1fdb649c
SP
860test_expect_success \
861 'O: repack before next test' \
862 'git repack -a -d'
863
864cat >input <<INPUT_END
865commit refs/heads/O3
866committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
867data <<COMMIT
868zstring
869COMMIT
870commit refs/heads/O3
871committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
872data <<COMMIT
873zof
874COMMIT
875checkpoint
876commit refs/heads/O3
877mark :5
878committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
879data <<COMMIT
880zempty
881COMMIT
882checkpoint
883commit refs/heads/O3
884committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
885data <<COMMIT
886zcommits
887COMMIT
888reset refs/tags/O3-2nd
889from :5
655e8515
AS
890reset refs/tags/O3-3rd
891from :5
1fdb649c
SP
892INPUT_END
893
894cat >expect <<INPUT_END
895string
896of
897empty
898commits
899INPUT_END
900test_expect_success \
901 'O: blank lines not necessary after other commands' \
eaa2a6fc 902 'git fast-import <input &&
1fdb649c
SP
903 test 8 = `find .git/objects/pack -type f | wc -l` &&
904 test `git rev-parse refs/tags/O3-2nd` = `git rev-parse O3^` &&
905 git log --reverse --pretty=oneline O3 | sed s/^.*z// >actual &&
3af82863 906 test_cmp expect actual'
1fdb649c 907
ac053c02
SP
908cat >input <<INPUT_END
909commit refs/heads/O4
910committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
911data <<COMMIT
912zstring
913COMMIT
914commit refs/heads/O4
915committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
916data <<COMMIT
917zof
918COMMIT
919progress Two commits down, 2 to go!
920commit refs/heads/O4
921committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
922data <<COMMIT
923zempty
924COMMIT
925progress Three commits down, 1 to go!
926commit refs/heads/O4
927committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
928data <<COMMIT
929zcommits
930COMMIT
931progress I'm done!
932INPUT_END
933test_expect_success \
934 'O: progress outputs as requested by input' \
eaa2a6fc 935 'git fast-import <input >actual &&
ac053c02 936 grep "progress " <input >expect &&
3af82863 937 test_cmp expect actual'
ac053c02 938
03db4525
AG
939###
940### series P (gitlinks)
941###
942
943cat >input <<INPUT_END
944blob
945mark :1
946data 10
947test file
948
949reset refs/heads/sub
950commit refs/heads/sub
951mark :2
952committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
953data 12
954sub_initial
955M 100644 :1 file
956
957blob
958mark :3
959data <<DATAEND
960[submodule "sub"]
961 path = sub
962 url = "`pwd`/sub"
963DATAEND
964
965commit refs/heads/subuse1
966mark :4
967committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
968data 8
969initial
970from refs/heads/master
971M 100644 :3 .gitmodules
972M 160000 :2 sub
973
974blob
975mark :5
976data 20
977test file
978more data
979
980commit refs/heads/sub
981mark :6
982committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
983data 11
984sub_second
985from :2
986M 100644 :5 file
987
988commit refs/heads/subuse1
989mark :7
990committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
991data 7
992second
993from :4
994M 160000 :6 sub
995
996INPUT_END
997
998test_expect_success \
999 'P: supermodule & submodule mix' \
eaa2a6fc 1000 'git fast-import <input &&
03db4525
AG
1001 git checkout subuse1 &&
1002 rm -rf sub && mkdir sub && cd sub &&
1003 git init &&
8ee5d731 1004 git fetch --update-head-ok .. refs/heads/sub:refs/heads/master &&
03db4525
AG
1005 git checkout master &&
1006 cd .. &&
1007 git submodule init &&
1008 git submodule update'
1009
eaa2a6fc
NS
1010SUBLAST=$(git rev-parse --verify sub)
1011SUBPREV=$(git rev-parse --verify sub^)
03db4525
AG
1012
1013cat >input <<INPUT_END
1014blob
1015mark :1
1016data <<DATAEND
1017[submodule "sub"]
1018 path = sub
1019 url = "`pwd`/sub"
1020DATAEND
1021
1022commit refs/heads/subuse2
1023mark :2
1024committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1025data 8
1026initial
1027from refs/heads/master
1028M 100644 :1 .gitmodules
1029M 160000 $SUBPREV sub
1030
1031commit refs/heads/subuse2
1032mark :3
1033committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1034data 7
1035second
1036from :2
1037M 160000 $SUBLAST sub
1038
1039INPUT_END
1040
1041test_expect_success \
1042 'P: verbatim SHA gitlinks' \
1043 'git branch -D sub &&
1044 git gc && git prune &&
eaa2a6fc
NS
1045 git fast-import <input &&
1046 test $(git rev-parse --verify subuse2) = $(git rev-parse --verify subuse1)'
03db4525
AG
1047
1048test_tick
1049cat >input <<INPUT_END
1050commit refs/heads/subuse3
1051mark :1
1052committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1053data <<COMMIT
1054corrupt
1055COMMIT
1056
1057from refs/heads/subuse2
1058M 160000 inline sub
1059data <<DATA
1060$SUBPREV
1061DATA
1062
1063INPUT_END
1064
1065test_expect_success 'P: fail on inline gitlink' '
eaa2a6fc 1066 test_must_fail git fast-import <input'
03db4525
AG
1067
1068test_tick
1069cat >input <<INPUT_END
1070blob
1071mark :1
1072data <<DATA
1073$SUBPREV
1074DATA
1075
1076commit refs/heads/subuse3
1077mark :2
1078committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1079data <<COMMIT
1080corrupt
1081COMMIT
1082
1083from refs/heads/subuse2
1084M 160000 :1 sub
1085
1086INPUT_END
1087
1088test_expect_success 'P: fail on blob mark in gitlink' '
eaa2a6fc 1089 test_must_fail git fast-import <input'
03db4525 1090
a8dd2e7d
JH
1091###
1092### series Q (notes)
1093###
1094
1095note1_data="Note for the first commit"
1096note2_data="Note for the second commit"
1097note3_data="Note for the third commit"
1098
1099test_tick
1100cat >input <<INPUT_END
1101blob
1102mark :2
1103data <<EOF
1104$file2_data
1105EOF
1106
1107commit refs/heads/notes-test
1108mark :3
1109committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1110data <<COMMIT
1111first (:3)
1112COMMIT
1113
1114M 644 :2 file2
1115
1116blob
1117mark :4
1118data $file4_len
1119$file4_data
1120commit refs/heads/notes-test
1121mark :5
1122committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1123data <<COMMIT
1124second (:5)
1125COMMIT
1126
1127M 644 :4 file4
1128
1129commit refs/heads/notes-test
1130mark :6
1131committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1132data <<COMMIT
1133third (:6)
1134COMMIT
1135
1136M 644 inline file5
1137data <<EOF
1138$file5_data
1139EOF
1140
1141M 755 inline file6
1142data <<EOF
1143$file6_data
1144EOF
1145
1146blob
1147mark :7
1148data <<EOF
1149$note1_data
1150EOF
1151
1152blob
1153mark :8
1154data <<EOF
1155$note2_data
1156EOF
1157
1158commit refs/notes/foobar
1159mark :9
1160committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1161data <<COMMIT
1162notes (:9)
1163COMMIT
1164
1165N :7 :3
1166N :8 :5
1167N inline :6
1168data <<EOF
1169$note3_data
1170EOF
1171
1172INPUT_END
1173test_expect_success \
1174 'Q: commit notes' \
1175 'git fast-import <input &&
1176 git whatchanged notes-test'
1177test_expect_success \
1178 'Q: verify pack' \
1179 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
1180
1181commit1=$(git rev-parse notes-test~2)
1182commit2=$(git rev-parse notes-test^)
1183commit3=$(git rev-parse notes-test)
1184
1185cat >expect <<EOF
1186author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1187committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1188
1189first (:3)
1190EOF
1191test_expect_success \
1192 'Q: verify first commit' \
1193 'git cat-file commit notes-test~2 | sed 1d >actual &&
1194 test_cmp expect actual'
1195
1196cat >expect <<EOF
1197parent $commit1
1198author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1199committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1200
1201second (:5)
1202EOF
1203test_expect_success \
1204 'Q: verify second commit' \
1205 'git cat-file commit notes-test^ | sed 1d >actual &&
1206 test_cmp expect actual'
1207
1208cat >expect <<EOF
1209parent $commit2
1210author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1211committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1212
1213third (:6)
1214EOF
1215test_expect_success \
1216 'Q: verify third commit' \
1217 'git cat-file commit notes-test | sed 1d >actual &&
1218 test_cmp expect actual'
1219
1220cat >expect <<EOF
1221author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1222committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
1223
1224notes (:9)
1225EOF
1226test_expect_success \
1227 'Q: verify notes commit' \
1228 'git cat-file commit refs/notes/foobar | sed 1d >actual &&
1229 test_cmp expect actual'
1230
1231cat >expect.unsorted <<EOF
1232100644 blob $commit1
1233100644 blob $commit2
1234100644 blob $commit3
1235EOF
1236cat expect.unsorted | sort >expect
1237test_expect_success \
1238 'Q: verify notes tree' \
1239 'git cat-file -p refs/notes/foobar^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
1240 test_cmp expect actual'
1241
1242echo "$note1_data" >expect
1243test_expect_success \
1244 'Q: verify note for first commit' \
1245 'git cat-file blob refs/notes/foobar:$commit1 >actual && test_cmp expect actual'
1246
1247echo "$note2_data" >expect
1248test_expect_success \
1249 'Q: verify note for second commit' \
1250 'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual'
1251
1252echo "$note3_data" >expect
1253test_expect_success \
1254 'Q: verify note for third commit' \
1255 'git cat-file blob refs/notes/foobar:$commit3 >actual && test_cmp expect actual'
1256
f963bd5d 1257###
2792f26c 1258### series R (feature and option)
f963bd5d
SR
1259###
1260
1261cat >input <<EOF
1262feature no-such-feature-exists
1263EOF
1264
1265test_expect_success 'R: abort on unsupported feature' '
1266 test_must_fail git fast-import <input
1267'
1268
1269cat >input <<EOF
1270feature date-format=now
1271EOF
1272
1273test_expect_success 'R: supported feature is accepted' '
1274 git fast-import <input
1275'
1276
1277cat >input << EOF
1278blob
1279data 3
1280hi
1281feature date-format=now
1282EOF
1283
1284test_expect_success 'R: abort on receiving feature after data command' '
1285 test_must_fail git fast-import <input
1286'
1287
1288cat >input << EOF
1289feature export-marks=git.marks
1290blob
1291mark :1
1292data 3
1293hi
1294
1295EOF
1296
1297test_expect_success \
1298 'R: export-marks feature results in a marks file being created' \
1299 'cat input | git fast-import &&
1300 grep :1 git.marks'
1301
1302test_expect_success \
1303 'R: export-marks options can be overriden by commandline options' \
1304 'cat input | git fast-import --export-marks=other.marks &&
1305 grep :1 other.marks'
1306
1307cat >input << EOF
1308feature import-marks=marks.out
1309feature export-marks=marks.new
1310EOF
1311
1312test_expect_success \
1313 'R: import to output marks works without any content' \
1314 'cat input | git fast-import &&
1315 test_cmp marks.out marks.new'
1316
1317cat >input <<EOF
1318feature import-marks=nonexistant.marks
1319feature export-marks=marks.new
1320EOF
1321
1322test_expect_success \
1323 'R: import marks prefers commandline marks file over the stream' \
1324 'cat input | git fast-import --import-marks=marks.out &&
1325 test_cmp marks.out marks.new'
1326
2792f26c
SR
1327cat >input << EOF
1328option git quiet
1329blob
1330data 3
1331hi
1332
1333EOF
1334
1335touch empty
1336
1337test_expect_success 'R: quiet option results in no stats being output' '
1338 cat input | git fast-import 2> output &&
1339 test_cmp empty output
1340'
1341
1342cat >input <<EOF
1343option git non-existing-option
1344EOF
1345
1346test_expect_success 'R: die on unknown option' '
1347 test_must_fail git fast-import <input
1348'
1349
1350test_expect_success 'R: unknown commandline options are rejected' '\
1351 test_must_fail git fast-import --non-existing-option < /dev/null
1352'
1353
1354cat >input <<EOF
1355option non-existing-vcs non-existing-option
1356EOF
1357
1358test_expect_success 'R: ignore non-git options' '
1359 git fast-import <input
1360'
1361
50aee995 1362test_done