3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='git fast-export'
9 test_expect_success 'setup' '
11 echo break it > file0 &&
14 echo Wohlauf > file &&
17 git commit -m initial &&
18 echo die Luft > file &&
19 echo geht frisch > file2 &&
22 git commit -m second &&
25 git commit -m third file2 &&
28 git checkout -b wer HEAD^ &&
31 git commit -m sitzt file2 &&
33 git tag -a -m valentin muss &&
34 git merge -s ours master
38 test_expect_success 'fast-export | fast-import' '
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) &&
45 git --git-dir=new/.git init &&
46 git fast-export --all >actual &&
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
56 test_expect_success 'fast-export master~2..master' '
58 git fast-export master~2..master >actual &&
59 sed "s/master/partial/" actual |
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)
69 test_expect_success 'fast-export --reference-excluded-parents master~2..master' '
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 |
77 test $MASTER = $(git rev-parse --verify refs/heads/rewrite))
80 test_expect_success 'fast-export --show-original-ids' '
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
90 test_expect_success 'fast-export --show-original-ids | git fast-import' '
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)
97 test_expect_success 'reencoding iso-8859-7' '
99 test_when_finished "git reset --hard HEAD~1" &&
100 test_config i18n.commitencoding iso-8859-7 &&
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 |
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
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)
121 test_expect_success 'aborting on iso-8859-7' '
123 test_when_finished "git reset --hard HEAD~1" &&
124 test_config i18n.commitencoding iso-8859-7 &&
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
130 test_expect_success 'preserving iso-8859-7' '
132 test_when_finished "git reset --hard HEAD~1" &&
133 test_config i18n.commitencoding iso-8859-7 &&
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 |
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)
153 test_expect_success 'encoding preserved if reencoding fails' '
155 test_when_finished "git reset --hard HEAD~1" &&
156 test_config i18n.commitencoding iso-8859-7 &&
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 |
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)
174 test_expect_success 'import/export-marks' '
176 git checkout -b marks master &&
177 git fast-export --export-marks=tmp-marks HEAD &&
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
192 cat > signed-tag-import << EOF
194 from $(git rev-parse HEAD)
195 tagger C O Mitter <committer@example.com> 1112911993 -0700
198 -----BEGIN PGP SIGNATURE-----
199 Version: GnuPG v1.4.5 (GNU/Linux)
201 fakedsignaturefakedsignaturefakedsignaturefakedsignaturfakedsign
202 aturefakedsignaturefake=
204 -----END PGP SIGNATURE-----
207 test_expect_success 'set up faked signed tag' '
209 cat signed-tag-import | git fast-import
213 test_expect_success 'signed-tags=abort' '
215 test_must_fail git fast-export --signed-tags=abort sign-your-name
219 test_expect_success 'signed-tags=verbatim' '
221 git fast-export --signed-tags=verbatim sign-your-name > output &&
226 test_expect_success 'signed-tags=strip' '
228 git fast-export --signed-tags=strip sign-your-name > output &&
233 test_expect_success 'signed-tags=warn-strip' '
234 git fast-export --signed-tags=warn-strip sign-your-name >output 2>err &&
239 test_expect_success 'setup submodule' '
241 git checkout -f master &&
246 echo test file > file &&
248 git commit -m sub_initial
250 git submodule add "$(pwd)/sub" sub &&
251 git commit -m initial &&
255 echo more data >> file &&
257 git commit -m sub_second
264 test_expect_success 'submodule fast-export | fast-import' '
266 SUBENT1=$(git ls-tree master^ sub) &&
267 SUBENT2=$(git ls-tree master sub) &&
270 git --git-dir=new/.git init &&
271 git fast-export --signed-tags=strip --all >actual &&
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
283 GIT_AUTHOR_NAME='A U Thor'; export GIT_AUTHOR_NAME
284 GIT_COMMITTER_NAME='C O Mitter'; export GIT_COMMITTER_NAME
286 test_expect_success 'setup copies' '
288 git checkout -b copy rein &&
290 git commit -m move1 &&
294 git mv file2 file5 &&
295 git commit -m copy1 &&
299 git commit -m copy2 &&
301 echo more text >> file6 &&
302 echo even more text >> file6 &&
304 git commit -m modify &&
307 echo test >> file7 &&
309 git commit -m copy_modify
313 test_expect_success 'fast-export -C -C | fast-import' '
315 ENTRY=$(git rev-parse --verify copy) &&
318 git --git-dir=new/.git init &&
319 git fast-export -C -C --signed-tags=strip --all > output &&
320 grep "^C file2 file4\$" output &&
324 test $ENTRY = $(git rev-parse --verify refs/heads/copy))
328 test_expect_success 'fast-export | fast-import when master is tagged' '
330 git tag -m msg last &&
331 git fast-export -C -C --signed-tags=strip --all > output &&
332 test $(grep -c "^tag " output) = 3
336 cat > tag-content << EOF
337 object $(git rev-parse HEAD)
342 test_expect_success 'cope with tagger-less tags' '
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
356 test_expect_success 'setup for limiting exports by PATH' '
357 mkdir limit-by-paths &&
363 git commit -m "First file" &&
366 git commit -m "Second file" &&
367 git tag -a -m msg mytag &&
368 echo morefoo >> bar &&
370 git commit -m "Change to second file"
374 cat > limit-by-paths/expected << EOF
380 reset refs/tags/mytag
381 commit refs/tags/mytag
383 author A U Thor <author@example.com> 1112912713 -0700
384 committer C O Mitter <committer@example.com> 1112912713 -0700
391 test_expect_success 'dropping tag of filtered out object' '
394 git fast-export --tag-of-filtered-object=drop mytag -- there > output &&
395 test_cmp expected output
399 cat >> limit-by-paths/expected << EOF
402 tagger C O Mitter <committer@example.com> 1112912713 -0700
408 test_expect_success 'rewriting tag of filtered out object' '
411 git fast-export --tag-of-filtered-object=rewrite mytag -- there > output &&
412 test_cmp expected output
416 test_expect_success 'rewrite tag predating pathspecs to nothing' '
417 test_create_repo rewrite_tag_predating_pathspecs &&
419 cd rewrite_tag_predating_pathspecs &&
421 test_commit initial &&
423 git tag -a -m "Some old tag" v0.0.0.0.0.0.1 &&
427 git fast-export --tag-of-filtered-object=rewrite --all -- bar.t >output &&
428 grep from.$ZERO_OID output
432 cat > limit-by-paths/expected << EOF
443 reset refs/heads/master
444 commit refs/heads/master
446 author A U Thor <author@example.com> 1112912713 -0700
447 committer C O Mitter <committer@example.com> 1112912713 -0700
455 test_expect_failure 'no exact-ref revisions included' '
458 git fast-export master~2..master~1 > output &&
459 test_cmp expected output
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 &&
468 git commit -mnext file &&
469 git fast-export --import-marks=marks simple -- file file0 >actual &&
473 test_expect_success 'avoid corrupt stream with non-existent mark' '
474 test_create_repo avoid_non_existent_mark &&
476 cd avoid_non_existent_mark &&
478 test_commit important-path &&
480 test_commit ignored &&
485 echo foo >>important-path.t &&
486 git add important-path.t &&
487 test_commit more changes &&
489 git fast-export --all -- important-path.t | git fast-import --force
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
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
508 test_expect_success 'tree_tag' '
510 (cd result && git init) &&
511 git fast-export tree_tag > fe-stream &&
512 (cd result && git fast-import < ../fe-stream)
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'
520 test_expect_success 'directory becomes symlink' '
521 git init dirtosymlink &&
527 echo hello > foo/world &&
528 echo hello > bar/world &&
529 git add foo/world bar/world &&
530 git commit -q -mone &&
532 test_ln_s_add bar foo &&
537 git fast-export master -- foo |
538 (cd ../result && git fast-import --quiet)
540 (cd result && git show master:foo)
543 test_expect_success 'fast-export quotes pathnames' '
544 git init 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 &&
563 git fast-import <../export.out &&
564 git rev-list HEAD >actual &&
565 test_cmp ../expect actual
569 test_expect_success 'test bidirectionality' '
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 &&
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
583 cat > expected << EOF
589 commit refs/heads/master
591 author A U Thor <author@example.com> 1112912773 -0700
592 committer C O Mitter <committer@example.com> 1112912773 -0700
600 test_expect_success 'avoid uninteresting refs' '
602 git fast-export --import-marks=tmp-marks \
603 --export-marks=tmp-marks master > /dev/null &&
605 git branch uninteresting &&
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
613 cat > expected << EOF
614 reset refs/heads/master
619 test_expect_success 'refs are updated even if no commits need to be exported' '
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
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
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
643 test_cmp expected actual
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
653 test_cmp expected actual
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 &&
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 &&
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
675 test_expect_success 'merge commit gets exported with --import-marks' '
676 test_create_repo merging &&
679 test_commit initial &&
680 git checkout -b topic &&
681 test_commit on-topic &&
682 git checkout master &&
683 test_commit on-master &&
685 git merge --no-ff -m Yeah topic &&
687 echo ":1 $(git rev-parse HEAD^^)" >marks &&
688 git fast-export --import-marks=marks master >out &&