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 ^muss^{commit} muss' '
57 git fast-export --tag-of-filtered-object=rewrite ^muss^{commit} muss >actual &&
58 cat >expected <<-EOF &&
60 from $(git rev-parse --verify muss^{commit})
61 $(git cat-file tag muss | grep tagger)
66 test_cmp expected actual
69 test_expect_success 'fast-export --mark-tags ^muss^{commit} muss' '
70 git fast-export --mark-tags --tag-of-filtered-object=rewrite ^muss^{commit} muss >actual &&
71 cat >expected <<-EOF &&
74 from $(git rev-parse --verify muss^{commit})
75 $(git cat-file tag muss | grep tagger)
80 test_cmp expected actual
83 test_expect_success 'fast-export master~2..master' '
85 git fast-export master~2..master >actual &&
86 sed "s/master/partial/" actual |
89 test $MASTER != $(git rev-parse --verify refs/heads/partial) &&
90 git diff --exit-code master partial &&
91 git diff --exit-code master^ partial^ &&
92 test_must_fail git rev-parse partial~2)
96 test_expect_success 'fast-export --reference-excluded-parents master~2..master' '
98 git fast-export --reference-excluded-parents master~2..master >actual &&
99 grep commit.refs/heads/master actual >commit-count &&
100 test_line_count = 2 commit-count &&
101 sed "s/master/rewrite/" actual |
104 test $MASTER = $(git rev-parse --verify refs/heads/rewrite))
107 test_expect_success 'fast-export --show-original-ids' '
109 git fast-export --show-original-ids master >output &&
110 grep ^original-oid output| sed -e s/^original-oid.// | sort >actual &&
111 git rev-list --objects master muss >objects-and-names &&
112 awk "{print \$1}" objects-and-names | sort >commits-trees-blobs &&
113 comm -23 actual commits-trees-blobs >unfound &&
114 test_must_be_empty unfound
117 test_expect_success 'fast-export --show-original-ids | git fast-import' '
119 git fast-export --show-original-ids master muss | git fast-import --quiet &&
120 test $MASTER = $(git rev-parse --verify refs/heads/master) &&
121 test $MUSS = $(git rev-parse --verify refs/tags/muss)
124 test_expect_success 'reencoding iso-8859-7' '
126 test_when_finished "git reset --hard HEAD~1" &&
127 test_config i18n.commitencoding iso-8859-7 &&
130 git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file &&
131 git fast-export --reencode=yes wer^..wer >iso-8859-7.fi &&
132 sed "s/wer/i18n/" iso-8859-7.fi |
135 # The commit object, if not re-encoded, would be 240 bytes.
136 # Removing the "encoding iso-8859-7\n" header drops 20 bytes.
137 # Re-encoding the Pi character from \xF0 (\360) in iso-8859-7
138 # to \xCF\x80 (\317\200) in UTF-8 adds a byte. Check for
140 test 221 -eq "$(git cat-file -s i18n)" &&
141 # ...and for the expected translation of bytes.
142 git cat-file commit i18n >actual &&
143 grep $(printf "\317\200") actual &&
144 # Also make sure the commit does not have the "encoding" header
145 ! grep ^encoding actual)
148 test_expect_success 'aborting on iso-8859-7' '
150 test_when_finished "git reset --hard HEAD~1" &&
151 test_config i18n.commitencoding iso-8859-7 &&
153 git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file &&
154 test_must_fail git fast-export --reencode=abort wer^..wer >iso-8859-7.fi
157 test_expect_success 'preserving iso-8859-7' '
159 test_when_finished "git reset --hard HEAD~1" &&
160 test_config i18n.commitencoding iso-8859-7 &&
162 git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file &&
163 git fast-export --reencode=no wer^..wer >iso-8859-7.fi &&
164 sed "s/wer/i18n-no-recoding/" iso-8859-7.fi |
167 # The commit object, if not re-encoded, is 240 bytes.
168 # Removing the "encoding iso-8859-7\n" header would drops 20
169 # bytes. Re-encoding the Pi character from \xF0 (\360) in
170 # iso-8859-7 to \xCF\x80 (\317\200) in UTF-8 adds a byte.
171 # Check for the expected size...
172 test 240 -eq "$(git cat-file -s i18n-no-recoding)" &&
173 # ...as well as the expected byte.
174 git cat-file commit i18n-no-recoding >actual &&
175 grep $(printf "\360") actual &&
176 # Also make sure the commit has the "encoding" header
177 grep ^encoding actual)
180 test_expect_success 'encoding preserved if reencoding fails' '
182 test_when_finished "git reset --hard HEAD~1" &&
183 test_config i18n.commitencoding iso-8859-7 &&
185 git commit -s -F "$TEST_DIRECTORY/t9350/broken-iso-8859-7-commit-message.txt" file &&
186 git fast-export --reencode=yes wer^..wer >iso-8859-7.fi &&
187 sed "s/wer/i18n-invalid/" iso-8859-7.fi |
190 git cat-file commit i18n-invalid >actual &&
191 # Make sure the commit still has the encoding header
192 grep ^encoding actual &&
193 # Verify that the commit has the expected size; i.e.
194 # that no bytes were re-encoded to a different encoding.
195 test 252 -eq "$(git cat-file -s i18n-invalid)" &&
196 # ...and check for the original special bytes
197 grep $(printf "\360") actual &&
198 grep $(printf "\377") actual)
201 test_expect_success 'import/export-marks' '
203 git checkout -b marks master &&
204 git fast-export --export-marks=tmp-marks HEAD &&
206 test_line_count = 3 tmp-marks &&
207 git fast-export --import-marks=tmp-marks \
208 --export-marks=tmp-marks HEAD >actual &&
209 test $(grep ^commit actual | wc -l) -eq 0 &&
210 echo change > file &&
211 git commit -m "last commit" file &&
212 git fast-export --import-marks=tmp-marks \
213 --export-marks=tmp-marks HEAD >actual &&
214 test $(grep ^commit\ actual | wc -l) -eq 1 &&
215 test_line_count = 4 tmp-marks
219 cat > signed-tag-import << EOF
221 from $(git rev-parse HEAD)
222 tagger C O Mitter <committer@example.com> 1112911993 -0700
225 -----BEGIN PGP SIGNATURE-----
226 Version: GnuPG v1.4.5 (GNU/Linux)
228 fakedsignaturefakedsignaturefakedsignaturefakedsignaturfakedsign
229 aturefakedsignaturefake=
231 -----END PGP SIGNATURE-----
234 test_expect_success 'set up faked signed tag' '
236 cat signed-tag-import | git fast-import
240 test_expect_success 'signed-tags=abort' '
242 test_must_fail git fast-export --signed-tags=abort sign-your-name
246 test_expect_success 'signed-tags=verbatim' '
248 git fast-export --signed-tags=verbatim sign-your-name > output &&
253 test_expect_success 'signed-tags=strip' '
255 git fast-export --signed-tags=strip sign-your-name > output &&
260 test_expect_success 'signed-tags=warn-strip' '
261 git fast-export --signed-tags=warn-strip sign-your-name >output 2>err &&
266 test_expect_success 'setup submodule' '
268 git checkout -f master &&
273 echo test file > file &&
275 git commit -m sub_initial
277 git submodule add "$(pwd)/sub" sub &&
278 git commit -m initial &&
282 echo more data >> file &&
284 git commit -m sub_second
291 test_expect_success 'submodule fast-export | fast-import' '
293 SUBENT1=$(git ls-tree master^ sub) &&
294 SUBENT2=$(git ls-tree master sub) &&
297 git --git-dir=new/.git init &&
298 git fast-export --signed-tags=strip --all >actual &&
301 test "$SUBENT1" = "$(git ls-tree refs/heads/master^ sub)" &&
302 test "$SUBENT2" = "$(git ls-tree refs/heads/master sub)" &&
303 git checkout master &&
304 git submodule init &&
305 git submodule update &&
306 cmp sub/file ../sub/file) <actual
310 GIT_AUTHOR_NAME='A U Thor'; export GIT_AUTHOR_NAME
311 GIT_COMMITTER_NAME='C O Mitter'; export GIT_COMMITTER_NAME
313 test_expect_success 'setup copies' '
315 git checkout -b copy rein &&
317 git commit -m move1 &&
321 git mv file2 file5 &&
322 git commit -m copy1 &&
326 git commit -m copy2 &&
328 echo more text >> file6 &&
329 echo even more text >> file6 &&
331 git commit -m modify &&
334 echo test >> file7 &&
336 git commit -m copy_modify
340 test_expect_success 'fast-export -C -C | fast-import' '
342 ENTRY=$(git rev-parse --verify copy) &&
345 git --git-dir=new/.git init &&
346 git fast-export -C -C --signed-tags=strip --all > output &&
347 grep "^C file2 file4\$" output &&
351 test $ENTRY = $(git rev-parse --verify refs/heads/copy))
355 test_expect_success 'fast-export | fast-import when master is tagged' '
357 git tag -m msg last &&
358 git fast-export -C -C --signed-tags=strip --all > output &&
359 test $(grep -c "^tag " output) = 3
363 cat > tag-content << EOF
364 object $(git rev-parse HEAD)
369 test_expect_success 'cope with tagger-less tags' '
371 TAG=$(git hash-object -t tag -w tag-content) &&
372 git update-ref refs/tags/sonnenschein $TAG &&
373 git fast-export -C -C --signed-tags=strip --all > output &&
374 test $(grep -c "^tag " output) = 4 &&
375 ! grep "Unspecified Tagger" output &&
376 git fast-export -C -C --signed-tags=strip --all \
377 --fake-missing-tagger > output &&
378 test $(grep -c "^tag " output) = 4 &&
379 grep "Unspecified Tagger" output
383 test_expect_success 'setup for limiting exports by PATH' '
384 mkdir limit-by-paths &&
390 git commit -m "First file" &&
393 git commit -m "Second file" &&
394 git tag -a -m msg mytag &&
395 echo morefoo >> bar &&
397 git commit -m "Change to second file"
401 cat > limit-by-paths/expected << EOF
407 reset refs/tags/mytag
408 commit refs/tags/mytag
410 author A U Thor <author@example.com> 1112912713 -0700
411 committer C O Mitter <committer@example.com> 1112912713 -0700
418 test_expect_success 'dropping tag of filtered out object' '
421 git fast-export --tag-of-filtered-object=drop mytag -- there > output &&
422 test_cmp expected output
426 cat >> limit-by-paths/expected << EOF
429 tagger C O Mitter <committer@example.com> 1112912713 -0700
435 test_expect_success 'rewriting tag of filtered out object' '
438 git fast-export --tag-of-filtered-object=rewrite mytag -- there > output &&
439 test_cmp expected output
443 test_expect_success 'rewrite tag predating pathspecs to nothing' '
444 test_create_repo rewrite_tag_predating_pathspecs &&
446 cd rewrite_tag_predating_pathspecs &&
448 test_commit initial &&
450 git tag -a -m "Some old tag" v0.0.0.0.0.0.1 &&
454 git fast-export --tag-of-filtered-object=rewrite --all -- bar.t >output &&
455 grep from.$ZERO_OID output
459 cat > limit-by-paths/expected << EOF
470 reset refs/heads/master
471 commit refs/heads/master
473 author A U Thor <author@example.com> 1112912713 -0700
474 committer C O Mitter <committer@example.com> 1112912713 -0700
482 test_expect_failure 'no exact-ref revisions included' '
485 git fast-export master~2..master~1 > output &&
486 test_cmp expected output
490 test_expect_success 'path limiting with import-marks does not lose unmodified files' '
491 git checkout -b simple marks~2 &&
492 git fast-export --export-marks=marks simple -- file > /dev/null &&
493 echo more content >> file &&
495 git commit -mnext file &&
496 git fast-export --import-marks=marks simple -- file file0 >actual &&
500 test_expect_success 'avoid corrupt stream with non-existent mark' '
501 test_create_repo avoid_non_existent_mark &&
503 cd avoid_non_existent_mark &&
505 test_commit important-path &&
507 test_commit ignored &&
512 echo foo >>important-path.t &&
513 git add important-path.t &&
514 test_commit more changes &&
516 git fast-export --all -- important-path.t | git fast-import --force
520 test_expect_success 'full-tree re-shows unmodified files' '
521 git checkout -f simple &&
522 git fast-export --full-tree simple >actual &&
523 test $(grep -c file0 actual) -eq 3
526 test_expect_success 'set-up a few more tags for tag export tests' '
527 git checkout -f master &&
528 HEAD_TREE=$(git show -s --pretty=raw HEAD | grep tree | sed "s/tree //") &&
529 git tag tree_tag -m "tagging a tree" $HEAD_TREE &&
530 git tag -a tree_tag-obj -m "tagging a tree" $HEAD_TREE &&
531 git tag tag-obj_tag -m "tagging a tag" tree_tag-obj &&
532 git tag -a tag-obj_tag-obj -m "tagging a tag" tree_tag-obj
535 test_expect_success 'tree_tag' '
537 (cd result && git init) &&
538 git fast-export tree_tag > fe-stream &&
539 (cd result && git fast-import < ../fe-stream)
542 # NEEDSWORK: not just check return status, but validate the output
543 # Note that these tests DO NOTHING other than print a warning that
544 # they are omitting the one tag we asked them to export (because the
545 # tags resolve to a tree). They exist just to make sure we do not
546 # abort but instead just warn.
547 test_expect_success 'tree_tag-obj' 'git fast-export tree_tag-obj'
548 test_expect_success 'tag-obj_tag' 'git fast-export tag-obj_tag'
549 test_expect_success 'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj'
551 test_expect_success 'handling tags of blobs' '
552 git tag -a -m "Tag of a blob" blobtag $(git rev-parse master:file) &&
553 git fast-export blobtag >actual &&
554 cat >expect <<-EOF &&
562 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
567 test_cmp expect actual
570 test_expect_success 'handling nested tags' '
571 git tag -a -m "This is a nested tag" nested muss &&
572 git fast-export --mark-tags nested >output &&
573 grep "^from $ZERO_OID$" output &&
574 grep "^tag nested$" output >tag_lines &&
575 test_line_count = 2 tag_lines
578 test_expect_success 'directory becomes symlink' '
579 git init dirtosymlink &&
585 echo hello > foo/world &&
586 echo hello > bar/world &&
587 git add foo/world bar/world &&
588 git commit -q -mone &&
590 test_ln_s_add bar foo &&
595 git fast-export master -- foo |
596 (cd ../result && git fast-import --quiet)
598 (cd result && git show master:foo)
601 test_expect_success 'fast-export quotes pathnames' '
602 git init crazy-paths &&
604 blob=$(echo foo | git hash-object -w --stdin) &&
605 git update-index --add \
606 --cacheinfo 100644 $blob "$(printf "path with\\nnewline")" \
607 --cacheinfo 100644 $blob "path with \"quote\"" \
608 --cacheinfo 100644 $blob "path with \\backslash" \
609 --cacheinfo 100644 $blob "path with space" &&
610 git commit -m addition &&
611 git ls-files -z -s | perl -0pe "s{\\t}{$&subdir/}" >index &&
612 git read-tree --empty &&
613 git update-index -z --index-info <index &&
614 git commit -m rename &&
615 git read-tree --empty &&
616 git commit -m deletion &&
617 git fast-export -M HEAD >export.out &&
618 git rev-list HEAD >expect &&
621 git fast-import <../export.out &&
622 git rev-list HEAD >actual &&
623 test_cmp ../expect actual
627 test_expect_success 'test bidirectionality' '
628 git init marks-test &&
629 git fast-export --export-marks=marks-cur --import-marks-if-exists=marks-cur --branches | \
630 git --git-dir=marks-test/.git fast-import --export-marks=marks-new --import-marks-if-exists=marks-new &&
633 echo Wohlauf > file &&
634 git commit -a -m "back in time") &&
635 git --git-dir=marks-test/.git fast-export --export-marks=marks-new --import-marks-if-exists=marks-new --branches | \
636 git fast-import --export-marks=marks-cur --import-marks-if-exists=marks-cur
639 cat > expected << EOF
645 commit refs/heads/master
647 author A U Thor <author@example.com> 1112912773 -0700
648 committer C O Mitter <committer@example.com> 1112912773 -0700
656 test_expect_success 'avoid uninteresting refs' '
658 git fast-export --import-marks=tmp-marks \
659 --export-marks=tmp-marks master > /dev/null &&
661 git branch uninteresting &&
663 git commit -a -m bump &&
664 git fast-export --import-marks=tmp-marks \
665 --export-marks=tmp-marks ^uninteresting ^v1.0 master > actual &&
666 test_cmp expected actual
669 cat > expected << EOF
670 reset refs/heads/master
675 test_expect_success 'refs are updated even if no commits need to be exported' '
677 git fast-export --import-marks=tmp-marks \
678 --export-marks=tmp-marks master > /dev/null &&
679 git fast-export --import-marks=tmp-marks \
680 --export-marks=tmp-marks master > actual &&
681 test_cmp expected actual
684 test_expect_success 'use refspec' '
685 git fast-export --refspec refs/heads/master:refs/heads/foobar master >actual2 &&
686 grep "^commit " actual2 | sort | uniq >actual &&
687 echo "commit refs/heads/foobar" > expected &&
688 test_cmp expected actual
691 test_expect_success 'delete ref because entire history excluded' '
692 git branch to-delete &&
693 git fast-export to-delete ^to-delete >actual &&
694 cat >expected <<-EOF &&
695 reset refs/heads/to-delete
696 from 0000000000000000000000000000000000000000
699 test_cmp expected actual
702 test_expect_success 'delete refspec' '
703 git fast-export --refspec :refs/heads/to-delete >actual &&
704 cat >expected <<-EOF &&
705 reset refs/heads/to-delete
706 from 0000000000000000000000000000000000000000
709 test_cmp expected actual
712 test_expect_success 'when using -C, do not declare copy when source of copy is also modified' '
713 test_create_repo src &&
714 echo a_line >src/file.txt &&
715 git -C src add file.txt &&
716 git -C src commit -m 1st_commit &&
718 cp src/file.txt src/file2.txt &&
719 echo another_line >>src/file.txt &&
720 git -C src add file.txt file2.txt &&
721 git -C src commit -m 2nd_commit &&
723 test_create_repo dst &&
724 git -C src fast-export --all -C >actual &&
725 git -C dst fast-import <actual &&
726 git -C src show >expected &&
727 git -C dst show >actual &&
728 test_cmp expected actual
731 test_expect_success 'merge commit gets exported with --import-marks' '
732 test_create_repo merging &&
735 test_commit initial &&
736 git checkout -b topic &&
737 test_commit on-topic &&
738 git checkout master &&
739 test_commit on-master &&
741 git merge --no-ff -m Yeah topic &&
743 echo ":1 $(git rev-parse HEAD^^)" >marks &&
744 git fast-export --import-marks=marks master >out &&