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
'iso-8859-1' '
71 git config i18n.commitencoding ISO8859-1 &&
72 # use author and committer name in ISO-8859-1 to match it.
73 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
76 git commit -s -m den file &&
77 git fast-export wer^..wer >iso8859-1.fi &&
78 sed "s/wer/i18n/" iso8859-1.fi |
81 git cat-file commit i18n >actual &&
85 test_expect_success
'import/export-marks' '
87 git checkout -b marks master &&
88 git fast-export --export-marks=tmp-marks HEAD &&
90 test_line_count = 3 tmp-marks &&
91 git fast-export --import-marks=tmp-marks \
92 --export-marks=tmp-marks HEAD >actual &&
93 test $(grep ^commit actual | wc -l) -eq 0 &&
95 git commit -m "last commit" file &&
96 git fast-export --import-marks=tmp-marks \
97 --export-marks=tmp-marks HEAD >actual &&
98 test $(grep ^commit\ actual | wc -l) -eq 1 &&
99 test_line_count = 4 tmp-marks
103 cat > signed-tag-import
<< EOF
105 from $(git rev-parse HEAD)
106 tagger C O Mitter <committer@example.com> 1112911993 -0700
109 -----BEGIN PGP SIGNATURE-----
110 Version: GnuPG v1.4.5 (GNU/Linux)
112 fakedsignaturefakedsignaturefakedsignaturefakedsignaturfakedsign
113 aturefakedsignaturefake=
115 -----END PGP SIGNATURE-----
118 test_expect_success
'set up faked signed tag' '
120 cat signed-tag-import | git fast-import
124 test_expect_success
'signed-tags=abort' '
126 test_must_fail git fast-export --signed-tags=abort sign-your-name
130 test_expect_success
'signed-tags=verbatim' '
132 git fast-export --signed-tags=verbatim sign-your-name > output &&
137 test_expect_success
'signed-tags=strip' '
139 git fast-export --signed-tags=strip sign-your-name > output &&
144 test_expect_success
'signed-tags=warn-strip' '
145 git fast-export --signed-tags=warn-strip sign-your-name >output 2>err &&
150 test_expect_success
'setup submodule' '
152 git checkout -f master &&
157 echo test file > file &&
159 git commit -m sub_initial
161 git submodule add "$(pwd)/sub" sub &&
162 git commit -m initial &&
166 echo more data >> file &&
168 git commit -m sub_second
175 test_expect_success
'submodule fast-export | fast-import' '
177 SUBENT1=$(git ls-tree master^ sub) &&
178 SUBENT2=$(git ls-tree master sub) &&
181 git --git-dir=new/.git init &&
182 git fast-export --signed-tags=strip --all >actual &&
185 test "$SUBENT1" = "$(git ls-tree refs/heads/master^ sub)" &&
186 test "$SUBENT2" = "$(git ls-tree refs/heads/master sub)" &&
187 git checkout master &&
188 git submodule init &&
189 git submodule update &&
190 cmp sub/file ../sub/file) <actual
194 GIT_AUTHOR_NAME
='A U Thor'; export GIT_AUTHOR_NAME
195 GIT_COMMITTER_NAME
='C O Mitter'; export GIT_COMMITTER_NAME
197 test_expect_success
'setup copies' '
199 git config --unset i18n.commitencoding &&
200 git checkout -b copy rein &&
202 git commit -m move1 &&
206 git mv file2 file5 &&
207 git commit -m copy1 &&
211 git commit -m copy2 &&
213 echo more text >> file6 &&
214 echo even more text >> file6 &&
216 git commit -m modify &&
219 echo test >> file7 &&
221 git commit -m copy_modify
225 test_expect_success
'fast-export -C -C | fast-import' '
227 ENTRY=$(git rev-parse --verify copy) &&
230 git --git-dir=new/.git init &&
231 git fast-export -C -C --signed-tags=strip --all > output &&
232 grep "^C file2 file4\$" output &&
236 test $ENTRY = $(git rev-parse --verify refs/heads/copy))
240 test_expect_success
'fast-export | fast-import when master is tagged' '
242 git tag -m msg last &&
243 git fast-export -C -C --signed-tags=strip --all > output &&
244 test $(grep -c "^tag " output) = 3
248 cat > tag-content
<< EOF
249 object $(git rev-parse HEAD)
254 test_expect_success
'cope with tagger-less tags' '
256 TAG=$(git hash-object -t tag -w tag-content) &&
257 git update-ref refs/tags/sonnenschein $TAG &&
258 git fast-export -C -C --signed-tags=strip --all > output &&
259 test $(grep -c "^tag " output) = 4 &&
260 ! grep "Unspecified Tagger" output &&
261 git fast-export -C -C --signed-tags=strip --all \
262 --fake-missing-tagger > output &&
263 test $(grep -c "^tag " output) = 4 &&
264 grep "Unspecified Tagger" output
268 test_expect_success
'setup for limiting exports by PATH' '
269 mkdir limit-by-paths &&
275 git commit -m "First file" &&
278 git commit -m "Second file" &&
279 git tag -a -m msg mytag &&
280 echo morefoo >> bar &&
282 git commit -m "Change to second file"
286 cat > limit-by-paths
/expected
<< EOF
292 reset refs/tags/mytag
293 commit refs/tags/mytag
295 author A U Thor <author@example.com> 1112912713 -0700
296 committer C O Mitter <committer@example.com> 1112912713 -0700
303 test_expect_success
'dropping tag of filtered out object' '
306 git fast-export --tag-of-filtered-object=drop mytag -- there > output &&
307 test_cmp expected output
311 cat >> limit-by-paths
/expected
<< EOF
314 tagger C O Mitter <committer@example.com> 1112912713 -0700
320 test_expect_success
'rewriting tag of filtered out object' '
323 git fast-export --tag-of-filtered-object=rewrite mytag -- there > output &&
324 test_cmp expected output
328 cat > limit-by-paths
/expected
<< EOF
339 reset refs/heads/master
340 commit refs/heads/master
342 author A U Thor <author@example.com> 1112912713 -0700
343 committer C O Mitter <committer@example.com> 1112912713 -0700
351 test_expect_failure
'no exact-ref revisions included' '
354 git fast-export master~2..master~1 > output &&
355 test_cmp expected output
359 test_expect_success
'path limiting with import-marks does not lose unmodified files' '
360 git checkout -b simple marks~2 &&
361 git fast-export --export-marks=marks simple -- file > /dev/null &&
362 echo more content >> file &&
364 git commit -mnext file &&
365 git fast-export --import-marks=marks simple -- file file0 >actual &&
369 test_expect_success
'full-tree re-shows unmodified files' '
370 git checkout -f simple &&
371 git fast-export --full-tree simple >actual &&
372 test $(grep -c file0 actual) -eq 3
375 test_expect_success
'set-up a few more tags for tag export tests' '
376 git checkout -f master &&
377 HEAD_TREE=$(git show -s --pretty=raw HEAD | grep tree | sed "s/tree //") &&
378 git tag tree_tag -m "tagging a tree" $HEAD_TREE &&
379 git tag -a tree_tag-obj -m "tagging a tree" $HEAD_TREE &&
380 git tag tag-obj_tag -m "tagging a tag" tree_tag-obj &&
381 git tag -a tag-obj_tag-obj -m "tagging a tag" tree_tag-obj
384 test_expect_success
'tree_tag' '
386 (cd result && git init) &&
387 git fast-export tree_tag > fe-stream &&
388 (cd result && git fast-import < ../fe-stream)
391 # NEEDSWORK: not just check return status, but validate the output
392 test_expect_success
'tree_tag-obj' 'git fast-export tree_tag-obj'
393 test_expect_success
'tag-obj_tag' 'git fast-export tag-obj_tag'
394 test_expect_success
'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj'
396 test_expect_success
'directory becomes symlink' '
397 git init dirtosymlink &&
403 echo hello > foo/world &&
404 echo hello > bar/world &&
405 git add foo/world bar/world &&
406 git commit -q -mone &&
408 test_ln_s_add bar foo &&
413 git fast-export master -- foo |
414 (cd ../result && git fast-import --quiet)
416 (cd result && git show master:foo)
419 test_expect_success
'fast-export quotes pathnames' '
420 git init crazy-paths &&
422 blob=$(echo foo | git hash-object -w --stdin) &&
423 git update-index --add \
424 --cacheinfo 100644 $blob "$(printf "path with\\nnewline")" \
425 --cacheinfo 100644 $blob "path with \"quote\"" \
426 --cacheinfo 100644 $blob "path with \\backslash" \
427 --cacheinfo 100644 $blob "path with space" &&
428 git commit -m addition &&
429 git ls-files -z -s | perl -0pe "s{\\t}{$&subdir/}" >index &&
430 git read-tree --empty &&
431 git update-index -z --index-info <index &&
432 git commit -m rename &&
433 git read-tree --empty &&
434 git commit -m deletion &&
435 git fast-export -M HEAD >export.out &&
436 git rev-list HEAD >expect &&
439 git fast-import <../export.out &&
440 git rev-list HEAD >actual &&
441 test_cmp ../expect actual
445 test_expect_success
'test bidirectionality' '
448 git init marks-test &&
449 git fast-export --export-marks=marks-cur --import-marks=marks-cur --branches | \
450 git --git-dir=marks-test/.git fast-import --export-marks=marks-new --import-marks=marks-new &&
453 echo Wohlauf > file &&
454 git commit -a -m "back in time") &&
455 git --git-dir=marks-test/.git fast-export --export-marks=marks-new --import-marks=marks-new --branches | \
456 git fast-import --export-marks=marks-cur --import-marks=marks-cur
459 cat > expected
<< EOF
465 commit refs/heads/master
467 author A U Thor <author@example.com> 1112912773 -0700
468 committer C O Mitter <committer@example.com> 1112912773 -0700
476 test_expect_success
'avoid uninteresting refs' '
478 git fast-export --import-marks=tmp-marks \
479 --export-marks=tmp-marks master > /dev/null &&
481 git branch uninteresting &&
483 git commit -a -m bump &&
484 git fast-export --import-marks=tmp-marks \
485 --export-marks=tmp-marks ^uninteresting ^v1.0 master > actual &&
486 test_cmp expected actual
489 cat > expected
<< EOF
490 reset refs/heads/master
495 test_expect_success
'refs are updated even if no commits need to be exported' '
497 git fast-export --import-marks=tmp-marks \
498 --export-marks=tmp-marks master > /dev/null &&
499 git fast-export --import-marks=tmp-marks \
500 --export-marks=tmp-marks master > actual &&
501 test_cmp expected actual
504 test_expect_success
'use refspec' '
505 git fast-export --refspec refs/heads/master:refs/heads/foobar master >actual2 &&
506 grep "^commit " actual2 | sort | uniq >actual &&
507 echo "commit refs/heads/foobar" > expected &&
508 test_cmp expected actual
511 test_expect_success
'delete refspec' '
512 git branch to-delete &&
513 git fast-export --refspec :refs/heads/to-delete to-delete ^to-delete > actual &&
514 cat > expected <<-EOF &&
515 reset refs/heads/to-delete
516 from 0000000000000000000000000000000000000000
519 test_cmp expected actual
522 test_expect_success
'when using -C, do not declare copy when source of copy is also modified' '
523 test_create_repo src &&
524 echo a_line >src/file.txt &&
525 git -C src add file.txt &&
526 git -C src commit -m 1st_commit &&
528 cp src/file.txt src/file2.txt &&
529 echo another_line >>src/file.txt &&
530 git -C src add file.txt file2.txt &&
531 git -C src commit -m 2nd_commit &&
533 test_create_repo dst &&
534 git -C src fast-export --all -C >actual &&
535 git -C dst fast-import <actual &&
536 git -C src show >expected &&
537 git -C dst show >actual &&
538 test_cmp expected actual
541 test_expect_success
'merge commit gets exported with --import-marks' '
542 test_create_repo merging &&
545 test_commit initial &&
546 git checkout -b topic &&
547 test_commit on-topic &&
548 git checkout master &&
549 test_commit on-master &&
551 git merge --no-ff -m Yeah topic &&
553 echo ":1 $(git rev-parse HEAD^^)" >marks &&
554 git fast-export --import-marks=marks master >out &&