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 |
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))
56 test_expect_success
'fast-export master~2..master' '
58 git fast-export master~2..master |
59 sed "s/master/partial/" |
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 |
81 git cat-file commit i18n | grep "Áéí óú")
84 test_expect_success
'import/export-marks' '
86 git checkout -b marks master &&
87 git fast-export --export-marks=tmp-marks HEAD &&
89 test_line_count = 3 tmp-marks &&
91 git fast-export --import-marks=tmp-marks\
92 --export-marks=tmp-marks HEAD |
97 git commit -m "last commit" file &&
99 git fast-export --import-marks=tmp-marks \
100 --export-marks=tmp-marks HEAD |
104 test_line_count = 4 tmp-marks
108 cat > signed-tag-import
<< EOF
110 from $(git rev-parse HEAD)
111 tagger C O Mitter <committer@example.com> 1112911993 -0700
114 -----BEGIN PGP SIGNATURE-----
115 Version: GnuPG v1.4.5 (GNU/Linux)
117 fakedsignaturefakedsignaturefakedsignaturefakedsignaturfakedsign
118 aturefakedsignaturefake=
120 -----END PGP SIGNATURE-----
123 test_expect_success
'set up faked signed tag' '
125 cat signed-tag-import | git fast-import
129 test_expect_success
'signed-tags=abort' '
131 test_must_fail git fast-export --signed-tags=abort sign-your-name
135 test_expect_success
'signed-tags=verbatim' '
137 git fast-export --signed-tags=verbatim sign-your-name > output &&
142 test_expect_success
'signed-tags=strip' '
144 git fast-export --signed-tags=strip sign-your-name > output &&
149 test_expect_success
'setup submodule' '
151 git checkout -f master &&
156 echo test file > file &&
158 git commit -m sub_initial
160 git submodule add "`pwd`/sub" sub &&
161 git commit -m initial &&
165 echo more data >> file &&
167 git commit -m sub_second
174 test_expect_success
'submodule fast-export | fast-import' '
176 SUBENT1=$(git ls-tree master^ sub) &&
177 SUBENT2=$(git ls-tree master sub) &&
180 git --git-dir=new/.git init &&
181 git fast-export --signed-tags=strip --all |
184 test "$SUBENT1" = "$(git ls-tree refs/heads/master^ sub)" &&
185 test "$SUBENT2" = "$(git ls-tree refs/heads/master sub)" &&
186 git checkout master &&
187 git submodule init &&
188 git submodule update &&
189 cmp sub/file ../sub/file)
193 GIT_AUTHOR_NAME
='A U Thor'; export GIT_AUTHOR_NAME
194 GIT_COMMITTER_NAME
='C O Mitter'; export GIT_COMMITTER_NAME
196 test_expect_success
'setup copies' '
198 git config --unset i18n.commitencoding &&
199 git checkout -b copy rein &&
201 git commit -m move1 &&
205 git mv file2 file5 &&
206 git commit -m copy1 &&
210 git commit -m copy2 &&
212 echo more text >> file6 &&
213 echo even more text >> file6 &&
215 git commit -m modify &&
218 echo test >> file7 &&
220 git commit -m copy_modify
224 test_expect_success
'fast-export -C -C | fast-import' '
226 ENTRY=$(git rev-parse --verify copy) &&
229 git --git-dir=new/.git init &&
230 git fast-export -C -C --signed-tags=strip --all > output &&
231 grep "^C file6 file7\$" output &&
235 test $ENTRY = $(git rev-parse --verify refs/heads/copy))
239 test_expect_success
'fast-export | fast-import when master is tagged' '
241 git tag -m msg last &&
242 git fast-export -C -C --signed-tags=strip --all > output &&
243 test $(grep -c "^tag " output) = 3
247 cat > tag-content
<< EOF
248 object $(git rev-parse HEAD)
253 test_expect_success
'cope with tagger-less tags' '
255 TAG=$(git hash-object -t tag -w tag-content) &&
256 git update-ref refs/tags/sonnenschein $TAG &&
257 git fast-export -C -C --signed-tags=strip --all > output &&
258 test $(grep -c "^tag " output) = 4 &&
259 ! grep "Unspecified Tagger" output &&
260 git fast-export -C -C --signed-tags=strip --all \
261 --fake-missing-tagger > output &&
262 test $(grep -c "^tag " output) = 4 &&
263 grep "Unspecified Tagger" output
267 test_expect_success
'setup for limiting exports by PATH' '
268 mkdir limit-by-paths &&
274 git commit -m "First file" &&
277 git commit -m "Second file" &&
278 git tag -a -m msg mytag &&
279 echo morefoo >> bar &&
281 git commit -m "Change to second file"
285 cat > limit-by-paths
/expected
<< EOF
291 reset refs/tags/mytag
292 commit refs/tags/mytag
294 author A U Thor <author@example.com> 1112912713 -0700
295 committer C O Mitter <committer@example.com> 1112912713 -0700
302 test_expect_success
'dropping tag of filtered out object' '
305 git fast-export --tag-of-filtered-object=drop mytag -- there > output &&
306 test_cmp expected output
310 cat >> limit-by-paths
/expected
<< EOF
313 tagger C O Mitter <committer@example.com> 1112912713 -0700
319 test_expect_success
'rewriting tag of filtered out object' '
322 git fast-export --tag-of-filtered-object=rewrite mytag -- there > output &&
323 test_cmp expected output
327 cat > limit-by-paths
/expected
<< EOF
338 reset refs/heads/master
339 commit refs/heads/master
341 author A U Thor <author@example.com> 1112912713 -0700
342 committer C O Mitter <committer@example.com> 1112912713 -0700
350 test_expect_failure
'no exact-ref revisions included' '
353 git fast-export master~2..master~1 > output &&
354 test_cmp expected output
358 test_expect_success
'path limiting with import-marks does not lose unmodified files' '
359 git checkout -b simple marks~2 &&
360 git fast-export --export-marks=marks simple -- file > /dev/null &&
361 echo more content >> file &&
363 git commit -mnext file &&
364 git fast-export --import-marks=marks simple -- file file0 | grep file0
367 test_expect_success
'full-tree re-shows unmodified files' '
368 git checkout -f simple &&
369 test $(git fast-export --full-tree simple | grep -c file0) -eq 3
372 test_expect_success
'set-up a few more tags for tag export tests' '
373 git checkout -f master &&
374 HEAD_TREE=`git show -s --pretty=raw HEAD | grep tree | sed "s/tree //"` &&
375 git tag tree_tag -m "tagging a tree" $HEAD_TREE &&
376 git tag -a tree_tag-obj -m "tagging a tree" $HEAD_TREE &&
377 git tag tag-obj_tag -m "tagging a tag" tree_tag-obj &&
378 git tag -a tag-obj_tag-obj -m "tagging a tag" tree_tag-obj
381 test_expect_success
'tree_tag' '
383 (cd result && git init) &&
384 git fast-export tree_tag > fe-stream &&
385 (cd result && git fast-import < ../fe-stream)
388 # NEEDSWORK: not just check return status, but validate the output
389 test_expect_success
'tree_tag-obj' 'git fast-export tree_tag-obj'
390 test_expect_success
'tag-obj_tag' 'git fast-export tag-obj_tag'
391 test_expect_success
'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj'
393 test_expect_success SYMLINKS
'directory becomes symlink' '
394 git init dirtosymlink &&
400 echo hello > foo/world &&
401 echo hello > bar/world &&
402 git add foo/world bar/world &&
403 git commit -q -mone &&
411 git fast-export master -- foo |
412 (cd ../result && git fast-import --quiet)
414 (cd result && git show master:foo)
417 test_expect_success
'fast-export quotes pathnames' '
418 git init crazy-paths &&
420 blob=`echo foo | git hash-object -w --stdin` &&
421 git update-index --add \
422 --cacheinfo 100644 $blob "$(printf "path with\\nnewline")" \
423 --cacheinfo 100644 $blob "path with \"quote\"" \
424 --cacheinfo 100644 $blob "path with \\backslash" \
425 --cacheinfo 100644 $blob "path with space" &&
426 git commit -m addition &&
427 git ls-files -z -s | "$PERL_PATH" -0pe "s{\\t}{$&subdir/}" >index &&
428 git read-tree --empty &&
429 git update-index -z --index-info <index &&
430 git commit -m rename &&
431 git read-tree --empty &&
432 git commit -m deletion &&
433 git fast-export -M HEAD >export.out &&
434 git rev-list HEAD >expect &&
437 git fast-import <../export.out &&
438 git rev-list HEAD >actual &&
439 test_cmp ../expect actual
443 test_expect_success
'test bidirectionality' '
446 git init marks-test &&
447 git fast-export --export-marks=marks-cur --import-marks=marks-cur --branches | \
448 git --git-dir=marks-test/.git fast-import --export-marks=marks-new --import-marks=marks-new &&
451 echo Wohlauf > file &&
452 git commit -a -m "back in time") &&
453 git --git-dir=marks-test/.git fast-export --export-marks=marks-new --import-marks=marks-new --branches | \
454 git fast-import --export-marks=marks-cur --import-marks=marks-cur