]> git.ipfire.org Git - thirdparty/git.git/blob - t/t9350-fast-export.sh
Merge branch 'rs/nedalloc-fixlets'
[thirdparty/git.git] / t / t9350-fast-export.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Johannes E. Schindelin
4 #
5
6 test_description='git fast-export'
7 . ./test-lib.sh
8
9 test_expect_success 'setup' '
10
11 echo break it > file0 &&
12 git add file0 &&
13 test_tick &&
14 echo Wohlauf > file &&
15 git add file &&
16 test_tick &&
17 git commit -m initial &&
18 echo die Luft > file &&
19 echo geht frisch > file2 &&
20 git add file file2 &&
21 test_tick &&
22 git commit -m second &&
23 echo und > file2 &&
24 test_tick &&
25 git commit -m third file2 &&
26 test_tick &&
27 git tag rein &&
28 git checkout -b wer HEAD^ &&
29 echo lange > file2 &&
30 test_tick &&
31 git commit -m sitzt file2 &&
32 test_tick &&
33 git tag -a -m valentin muss &&
34 git merge -s ours master
35
36 '
37
38 test_expect_success 'fast-export | fast-import' '
39
40 MASTER=$(git rev-parse --verify master) &&
41 REIN=$(git rev-parse --verify rein) &&
42 WER=$(git rev-parse --verify wer) &&
43 MUSS=$(git rev-parse --verify muss) &&
44 mkdir new &&
45 git --git-dir=new/.git init &&
46 git fast-export --all >actual &&
47 (cd new &&
48 git fast-import &&
49 test $MASTER = $(git rev-parse --verify refs/heads/master) &&
50 test $REIN = $(git rev-parse --verify refs/tags/rein) &&
51 test $WER = $(git rev-parse --verify refs/heads/wer) &&
52 test $MUSS = $(git rev-parse --verify refs/tags/muss)) <actual
53
54 '
55
56 test_expect_success 'fast-export master~2..master' '
57
58 git fast-export master~2..master >actual &&
59 sed "s/master/partial/" actual |
60 (cd new &&
61 git fast-import &&
62 test $MASTER != $(git rev-parse --verify refs/heads/partial) &&
63 git diff --exit-code master partial &&
64 git diff --exit-code master^ partial^ &&
65 test_must_fail git rev-parse partial~2)
66
67 '
68
69 test_expect_success 'fast-export --reference-excluded-parents master~2..master' '
70
71 git fast-export --reference-excluded-parents master~2..master >actual &&
72 grep commit.refs/heads/master actual >commit-count &&
73 test_line_count = 2 commit-count &&
74 sed "s/master/rewrite/" actual |
75 (cd new &&
76 git fast-import &&
77 test $MASTER = $(git rev-parse --verify refs/heads/rewrite))
78 '
79
80 test_expect_success 'fast-export --show-original-ids' '
81
82 git fast-export --show-original-ids master >output &&
83 grep ^original-oid output| sed -e s/^original-oid.// | sort >actual &&
84 git rev-list --objects master muss >objects-and-names &&
85 awk "{print \$1}" objects-and-names | sort >commits-trees-blobs &&
86 comm -23 actual commits-trees-blobs >unfound &&
87 test_must_be_empty unfound
88 '
89
90 test_expect_success 'fast-export --show-original-ids | git fast-import' '
91
92 git fast-export --show-original-ids master muss | git fast-import --quiet &&
93 test $MASTER = $(git rev-parse --verify refs/heads/master) &&
94 test $MUSS = $(git rev-parse --verify refs/tags/muss)
95 '
96
97 test_expect_success 'reencoding iso-8859-7' '
98
99 test_when_finished "git reset --hard HEAD~1" &&
100 test_config i18n.commitencoding iso-8859-7 &&
101 test_tick &&
102 echo rosten >file &&
103 git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file &&
104 git fast-export --reencode=yes wer^..wer >iso-8859-7.fi &&
105 sed "s/wer/i18n/" iso-8859-7.fi |
106 (cd new &&
107 git fast-import &&
108 # The commit object, if not re-encoded, would be 240 bytes.
109 # Removing the "encoding iso-8859-7\n" header drops 20 bytes.
110 # Re-encoding the Pi character from \xF0 (\360) in iso-8859-7
111 # to \xCF\x80 (\317\200) in UTF-8 adds a byte. Check for
112 # the expected size.
113 test 221 -eq "$(git cat-file -s i18n)" &&
114 # ...and for the expected translation of bytes.
115 git cat-file commit i18n >actual &&
116 grep $(printf "\317\200") actual &&
117 # Also make sure the commit does not have the "encoding" header
118 ! grep ^encoding actual)
119 '
120
121 test_expect_success 'aborting on iso-8859-7' '
122
123 test_when_finished "git reset --hard HEAD~1" &&
124 test_config i18n.commitencoding iso-8859-7 &&
125 echo rosten >file &&
126 git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file &&
127 test_must_fail git fast-export --reencode=abort wer^..wer >iso-8859-7.fi
128 '
129
130 test_expect_success 'preserving iso-8859-7' '
131
132 test_when_finished "git reset --hard HEAD~1" &&
133 test_config i18n.commitencoding iso-8859-7 &&
134 echo rosten >file &&
135 git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file &&
136 git fast-export --reencode=no wer^..wer >iso-8859-7.fi &&
137 sed "s/wer/i18n-no-recoding/" iso-8859-7.fi |
138 (cd new &&
139 git fast-import &&
140 # The commit object, if not re-encoded, is 240 bytes.
141 # Removing the "encoding iso-8859-7\n" header would drops 20
142 # bytes. Re-encoding the Pi character from \xF0 (\360) in
143 # iso-8859-7 to \xCF\x80 (\317\200) in UTF-8 adds a byte.
144 # Check for the expected size...
145 test 240 -eq "$(git cat-file -s i18n-no-recoding)" &&
146 # ...as well as the expected byte.
147 git cat-file commit i18n-no-recoding >actual &&
148 grep $(printf "\360") actual &&
149 # Also make sure the commit has the "encoding" header
150 grep ^encoding actual)
151 '
152
153 test_expect_success 'encoding preserved if reencoding fails' '
154
155 test_when_finished "git reset --hard HEAD~1" &&
156 test_config i18n.commitencoding iso-8859-7 &&
157 echo rosten >file &&
158 git commit -s -F "$TEST_DIRECTORY/t9350/broken-iso-8859-7-commit-message.txt" file &&
159 git fast-export --reencode=yes wer^..wer >iso-8859-7.fi &&
160 sed "s/wer/i18n-invalid/" iso-8859-7.fi |
161 (cd new &&
162 git fast-import &&
163 git cat-file commit i18n-invalid >actual &&
164 # Make sure the commit still has the encoding header
165 grep ^encoding actual &&
166 # Verify that the commit has the expected size; i.e.
167 # that no bytes were re-encoded to a different encoding.
168 test 252 -eq "$(git cat-file -s i18n-invalid)" &&
169 # ...and check for the original special bytes
170 grep $(printf "\360") actual &&
171 grep $(printf "\377") actual)
172 '
173
174 test_expect_success 'import/export-marks' '
175
176 git checkout -b marks master &&
177 git fast-export --export-marks=tmp-marks HEAD &&
178 test -s tmp-marks &&
179 test_line_count = 3 tmp-marks &&
180 git fast-export --import-marks=tmp-marks \
181 --export-marks=tmp-marks HEAD >actual &&
182 test $(grep ^commit actual | wc -l) -eq 0 &&
183 echo change > file &&
184 git commit -m "last commit" file &&
185 git fast-export --import-marks=tmp-marks \
186 --export-marks=tmp-marks HEAD >actual &&
187 test $(grep ^commit\ actual | wc -l) -eq 1 &&
188 test_line_count = 4 tmp-marks
189
190 '
191
192 cat > signed-tag-import << EOF
193 tag sign-your-name
194 from $(git rev-parse HEAD)
195 tagger C O Mitter <committer@example.com> 1112911993 -0700
196 data 210
197 A message for a sign
198 -----BEGIN PGP SIGNATURE-----
199 Version: GnuPG v1.4.5 (GNU/Linux)
200
201 fakedsignaturefakedsignaturefakedsignaturefakedsignaturfakedsign
202 aturefakedsignaturefake=
203 =/59v
204 -----END PGP SIGNATURE-----
205 EOF
206
207 test_expect_success 'set up faked signed tag' '
208
209 cat signed-tag-import | git fast-import
210
211 '
212
213 test_expect_success 'signed-tags=abort' '
214
215 test_must_fail git fast-export --signed-tags=abort sign-your-name
216
217 '
218
219 test_expect_success 'signed-tags=verbatim' '
220
221 git fast-export --signed-tags=verbatim sign-your-name > output &&
222 grep PGP output
223
224 '
225
226 test_expect_success 'signed-tags=strip' '
227
228 git fast-export --signed-tags=strip sign-your-name > output &&
229 ! grep PGP output
230
231 '
232
233 test_expect_success 'signed-tags=warn-strip' '
234 git fast-export --signed-tags=warn-strip sign-your-name >output 2>err &&
235 ! grep PGP output &&
236 test -s err
237 '
238
239 test_expect_success 'setup submodule' '
240
241 git checkout -f master &&
242 mkdir sub &&
243 (
244 cd sub &&
245 git init &&
246 echo test file > file &&
247 git add file &&
248 git commit -m sub_initial
249 ) &&
250 git submodule add "$(pwd)/sub" sub &&
251 git commit -m initial &&
252 test_tick &&
253 (
254 cd sub &&
255 echo more data >> file &&
256 git add file &&
257 git commit -m sub_second
258 ) &&
259 git add sub &&
260 git commit -m second
261
262 '
263
264 test_expect_success 'submodule fast-export | fast-import' '
265
266 SUBENT1=$(git ls-tree master^ sub) &&
267 SUBENT2=$(git ls-tree master sub) &&
268 rm -rf new &&
269 mkdir new &&
270 git --git-dir=new/.git init &&
271 git fast-export --signed-tags=strip --all >actual &&
272 (cd new &&
273 git fast-import &&
274 test "$SUBENT1" = "$(git ls-tree refs/heads/master^ sub)" &&
275 test "$SUBENT2" = "$(git ls-tree refs/heads/master sub)" &&
276 git checkout master &&
277 git submodule init &&
278 git submodule update &&
279 cmp sub/file ../sub/file) <actual
280
281 '
282
283 GIT_AUTHOR_NAME='A U Thor'; export GIT_AUTHOR_NAME
284 GIT_COMMITTER_NAME='C O Mitter'; export GIT_COMMITTER_NAME
285
286 test_expect_success 'setup copies' '
287
288 git checkout -b copy rein &&
289 git mv file file3 &&
290 git commit -m move1 &&
291 test_tick &&
292 cp file2 file4 &&
293 git add file4 &&
294 git mv file2 file5 &&
295 git commit -m copy1 &&
296 test_tick &&
297 cp file3 file6 &&
298 git add file6 &&
299 git commit -m copy2 &&
300 test_tick &&
301 echo more text >> file6 &&
302 echo even more text >> file6 &&
303 git add file6 &&
304 git commit -m modify &&
305 test_tick &&
306 cp file6 file7 &&
307 echo test >> file7 &&
308 git add file7 &&
309 git commit -m copy_modify
310
311 '
312
313 test_expect_success 'fast-export -C -C | fast-import' '
314
315 ENTRY=$(git rev-parse --verify copy) &&
316 rm -rf new &&
317 mkdir new &&
318 git --git-dir=new/.git init &&
319 git fast-export -C -C --signed-tags=strip --all > output &&
320 grep "^C file2 file4\$" output &&
321 cat output |
322 (cd new &&
323 git fast-import &&
324 test $ENTRY = $(git rev-parse --verify refs/heads/copy))
325
326 '
327
328 test_expect_success 'fast-export | fast-import when master is tagged' '
329
330 git tag -m msg last &&
331 git fast-export -C -C --signed-tags=strip --all > output &&
332 test $(grep -c "^tag " output) = 3
333
334 '
335
336 cat > tag-content << EOF
337 object $(git rev-parse HEAD)
338 type commit
339 tag rosten
340 EOF
341
342 test_expect_success 'cope with tagger-less tags' '
343
344 TAG=$(git hash-object -t tag -w tag-content) &&
345 git update-ref refs/tags/sonnenschein $TAG &&
346 git fast-export -C -C --signed-tags=strip --all > output &&
347 test $(grep -c "^tag " output) = 4 &&
348 ! grep "Unspecified Tagger" output &&
349 git fast-export -C -C --signed-tags=strip --all \
350 --fake-missing-tagger > output &&
351 test $(grep -c "^tag " output) = 4 &&
352 grep "Unspecified Tagger" output
353
354 '
355
356 test_expect_success 'setup for limiting exports by PATH' '
357 mkdir limit-by-paths &&
358 (
359 cd limit-by-paths &&
360 git init &&
361 echo hi > there &&
362 git add there &&
363 git commit -m "First file" &&
364 echo foo > bar &&
365 git add bar &&
366 git commit -m "Second file" &&
367 git tag -a -m msg mytag &&
368 echo morefoo >> bar &&
369 git add bar &&
370 git commit -m "Change to second file"
371 )
372 '
373
374 cat > limit-by-paths/expected << EOF
375 blob
376 mark :1
377 data 3
378 hi
379
380 reset refs/tags/mytag
381 commit refs/tags/mytag
382 mark :2
383 author A U Thor <author@example.com> 1112912713 -0700
384 committer C O Mitter <committer@example.com> 1112912713 -0700
385 data 11
386 First file
387 M 100644 :1 there
388
389 EOF
390
391 test_expect_success 'dropping tag of filtered out object' '
392 (
393 cd limit-by-paths &&
394 git fast-export --tag-of-filtered-object=drop mytag -- there > output &&
395 test_cmp expected output
396 )
397 '
398
399 cat >> limit-by-paths/expected << EOF
400 tag mytag
401 from :2
402 tagger C O Mitter <committer@example.com> 1112912713 -0700
403 data 4
404 msg
405
406 EOF
407
408 test_expect_success 'rewriting tag of filtered out object' '
409 (
410 cd limit-by-paths &&
411 git fast-export --tag-of-filtered-object=rewrite mytag -- there > output &&
412 test_cmp expected output
413 )
414 '
415
416 test_expect_success 'rewrite tag predating pathspecs to nothing' '
417 test_create_repo rewrite_tag_predating_pathspecs &&
418 (
419 cd rewrite_tag_predating_pathspecs &&
420
421 test_commit initial &&
422
423 git tag -a -m "Some old tag" v0.0.0.0.0.0.1 &&
424
425 test_commit bar &&
426
427 git fast-export --tag-of-filtered-object=rewrite --all -- bar.t >output &&
428 grep from.$ZERO_OID output
429 )
430 '
431
432 cat > limit-by-paths/expected << EOF
433 blob
434 mark :1
435 data 4
436 foo
437
438 blob
439 mark :2
440 data 3
441 hi
442
443 reset refs/heads/master
444 commit refs/heads/master
445 mark :3
446 author A U Thor <author@example.com> 1112912713 -0700
447 committer C O Mitter <committer@example.com> 1112912713 -0700
448 data 12
449 Second file
450 M 100644 :1 bar
451 M 100644 :2 there
452
453 EOF
454
455 test_expect_failure 'no exact-ref revisions included' '
456 (
457 cd limit-by-paths &&
458 git fast-export master~2..master~1 > output &&
459 test_cmp expected output
460 )
461 '
462
463 test_expect_success 'path limiting with import-marks does not lose unmodified files' '
464 git checkout -b simple marks~2 &&
465 git fast-export --export-marks=marks simple -- file > /dev/null &&
466 echo more content >> file &&
467 test_tick &&
468 git commit -mnext file &&
469 git fast-export --import-marks=marks simple -- file file0 >actual &&
470 grep file0 actual
471 '
472
473 test_expect_success 'avoid corrupt stream with non-existent mark' '
474 test_create_repo avoid_non_existent_mark &&
475 (
476 cd avoid_non_existent_mark &&
477
478 test_commit important-path &&
479
480 test_commit ignored &&
481
482 git branch A &&
483 git branch B &&
484
485 echo foo >>important-path.t &&
486 git add important-path.t &&
487 test_commit more changes &&
488
489 git fast-export --all -- important-path.t | git fast-import --force
490 )
491 '
492
493 test_expect_success 'full-tree re-shows unmodified files' '
494 git checkout -f simple &&
495 git fast-export --full-tree simple >actual &&
496 test $(grep -c file0 actual) -eq 3
497 '
498
499 test_expect_success 'set-up a few more tags for tag export tests' '
500 git checkout -f master &&
501 HEAD_TREE=$(git show -s --pretty=raw HEAD | grep tree | sed "s/tree //") &&
502 git tag tree_tag -m "tagging a tree" $HEAD_TREE &&
503 git tag -a tree_tag-obj -m "tagging a tree" $HEAD_TREE &&
504 git tag tag-obj_tag -m "tagging a tag" tree_tag-obj &&
505 git tag -a tag-obj_tag-obj -m "tagging a tag" tree_tag-obj
506 '
507
508 test_expect_success 'tree_tag' '
509 mkdir result &&
510 (cd result && git init) &&
511 git fast-export tree_tag > fe-stream &&
512 (cd result && git fast-import < ../fe-stream)
513 '
514
515 # NEEDSWORK: not just check return status, but validate the output
516 test_expect_success 'tree_tag-obj' 'git fast-export tree_tag-obj'
517 test_expect_success 'tag-obj_tag' 'git fast-export tag-obj_tag'
518 test_expect_success 'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj'
519
520 test_expect_success 'directory becomes symlink' '
521 git init dirtosymlink &&
522 git init result &&
523 (
524 cd dirtosymlink &&
525 mkdir foo &&
526 mkdir bar &&
527 echo hello > foo/world &&
528 echo hello > bar/world &&
529 git add foo/world bar/world &&
530 git commit -q -mone &&
531 git rm -r foo &&
532 test_ln_s_add bar foo &&
533 git commit -q -mtwo
534 ) &&
535 (
536 cd dirtosymlink &&
537 git fast-export master -- foo |
538 (cd ../result && git fast-import --quiet)
539 ) &&
540 (cd result && git show master:foo)
541 '
542
543 test_expect_success 'fast-export quotes pathnames' '
544 git init crazy-paths &&
545 (cd crazy-paths &&
546 blob=$(echo foo | git hash-object -w --stdin) &&
547 git update-index --add \
548 --cacheinfo 100644 $blob "$(printf "path with\\nnewline")" \
549 --cacheinfo 100644 $blob "path with \"quote\"" \
550 --cacheinfo 100644 $blob "path with \\backslash" \
551 --cacheinfo 100644 $blob "path with space" &&
552 git commit -m addition &&
553 git ls-files -z -s | perl -0pe "s{\\t}{$&subdir/}" >index &&
554 git read-tree --empty &&
555 git update-index -z --index-info <index &&
556 git commit -m rename &&
557 git read-tree --empty &&
558 git commit -m deletion &&
559 git fast-export -M HEAD >export.out &&
560 git rev-list HEAD >expect &&
561 git init result &&
562 cd result &&
563 git fast-import <../export.out &&
564 git rev-list HEAD >actual &&
565 test_cmp ../expect actual
566 )
567 '
568
569 test_expect_success 'test bidirectionality' '
570 >marks-cur &&
571 >marks-new &&
572 git init marks-test &&
573 git fast-export --export-marks=marks-cur --import-marks=marks-cur --branches | \
574 git --git-dir=marks-test/.git fast-import --export-marks=marks-new --import-marks=marks-new &&
575 (cd marks-test &&
576 git reset --hard &&
577 echo Wohlauf > file &&
578 git commit -a -m "back in time") &&
579 git --git-dir=marks-test/.git fast-export --export-marks=marks-new --import-marks=marks-new --branches | \
580 git fast-import --export-marks=marks-cur --import-marks=marks-cur
581 '
582
583 cat > expected << EOF
584 blob
585 mark :13
586 data 5
587 bump
588
589 commit refs/heads/master
590 mark :14
591 author A U Thor <author@example.com> 1112912773 -0700
592 committer C O Mitter <committer@example.com> 1112912773 -0700
593 data 5
594 bump
595 from :12
596 M 100644 :13 file
597
598 EOF
599
600 test_expect_success 'avoid uninteresting refs' '
601 > tmp-marks &&
602 git fast-export --import-marks=tmp-marks \
603 --export-marks=tmp-marks master > /dev/null &&
604 git tag v1.0 &&
605 git branch uninteresting &&
606 echo bump > file &&
607 git commit -a -m bump &&
608 git fast-export --import-marks=tmp-marks \
609 --export-marks=tmp-marks ^uninteresting ^v1.0 master > actual &&
610 test_cmp expected actual
611 '
612
613 cat > expected << EOF
614 reset refs/heads/master
615 from :14
616
617 EOF
618
619 test_expect_success 'refs are updated even if no commits need to be exported' '
620 > tmp-marks &&
621 git fast-export --import-marks=tmp-marks \
622 --export-marks=tmp-marks master > /dev/null &&
623 git fast-export --import-marks=tmp-marks \
624 --export-marks=tmp-marks master > actual &&
625 test_cmp expected actual
626 '
627
628 test_expect_success 'use refspec' '
629 git fast-export --refspec refs/heads/master:refs/heads/foobar master >actual2 &&
630 grep "^commit " actual2 | sort | uniq >actual &&
631 echo "commit refs/heads/foobar" > expected &&
632 test_cmp expected actual
633 '
634
635 test_expect_success 'delete ref because entire history excluded' '
636 git branch to-delete &&
637 git fast-export to-delete ^to-delete >actual &&
638 cat >expected <<-EOF &&
639 reset refs/heads/to-delete
640 from 0000000000000000000000000000000000000000
641
642 EOF
643 test_cmp expected actual
644 '
645
646 test_expect_success 'delete refspec' '
647 git fast-export --refspec :refs/heads/to-delete >actual &&
648 cat >expected <<-EOF &&
649 reset refs/heads/to-delete
650 from 0000000000000000000000000000000000000000
651
652 EOF
653 test_cmp expected actual
654 '
655
656 test_expect_success 'when using -C, do not declare copy when source of copy is also modified' '
657 test_create_repo src &&
658 echo a_line >src/file.txt &&
659 git -C src add file.txt &&
660 git -C src commit -m 1st_commit &&
661
662 cp src/file.txt src/file2.txt &&
663 echo another_line >>src/file.txt &&
664 git -C src add file.txt file2.txt &&
665 git -C src commit -m 2nd_commit &&
666
667 test_create_repo dst &&
668 git -C src fast-export --all -C >actual &&
669 git -C dst fast-import <actual &&
670 git -C src show >expected &&
671 git -C dst show >actual &&
672 test_cmp expected actual
673 '
674
675 test_expect_success 'merge commit gets exported with --import-marks' '
676 test_create_repo merging &&
677 (
678 cd merging &&
679 test_commit initial &&
680 git checkout -b topic &&
681 test_commit on-topic &&
682 git checkout master &&
683 test_commit on-master &&
684 test_tick &&
685 git merge --no-ff -m Yeah topic &&
686
687 echo ":1 $(git rev-parse HEAD^^)" >marks &&
688 git fast-export --import-marks=marks master >out &&
689 grep Yeah out
690 )
691 '
692
693 test_done