config: document the settings to colorize push errors/hints
[git/debian.git] / t / t9350-fast-export.sh
blobd5679ffb873b4657cd953f7b318a231f56671f20
1 #!/bin/sh
3 # Copyright (c) 2007 Johannes E. Schindelin
6 test_description='git fast-export'
7 . ./test-lib.sh
9 test_expect_success 'setup' '
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
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) &&
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
56 test_expect_success 'fast-export master~2..master' '
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)
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 &&
74 test_tick &&
75 echo rosten >file &&
76 git commit -s -m den file &&
77 git fast-export wer^..wer >iso8859-1.fi &&
78 sed "s/wer/i18n/" iso8859-1.fi |
79 (cd new &&
80 git fast-import &&
81 git cat-file commit i18n >actual &&
82 grep "Áéí óú" actual)
85 test_expect_success 'import/export-marks' '
87 git checkout -b marks master &&
88 git fast-export --export-marks=tmp-marks HEAD &&
89 test -s tmp-marks &&
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 &&
94 echo change > file &&
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
104 tag sign-your-name
105 from $(git rev-parse HEAD)
106 tagger C O Mitter <committer@example.com> 1112911993 -0700
107 data 210
108 A message for a sign
109 -----BEGIN PGP SIGNATURE-----
110 Version: GnuPG v1.4.5 (GNU/Linux)
112 fakedsignaturefakedsignaturefakedsignaturefakedsignaturfakedsign
113 aturefakedsignaturefake=
114 =/59v
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 &&
133 grep PGP output
137 test_expect_success 'signed-tags=strip' '
139 git fast-export --signed-tags=strip sign-your-name > output &&
140 ! grep PGP output
144 test_expect_success 'signed-tags=warn-strip' '
145 git fast-export --signed-tags=warn-strip sign-your-name >output 2>err &&
146 ! grep PGP output &&
147 test -s err
150 test_expect_success 'setup submodule' '
152 git checkout -f master &&
153 mkdir sub &&
155 cd sub &&
156 git init &&
157 echo test file > file &&
158 git add file &&
159 git commit -m sub_initial
160 ) &&
161 git submodule add "$(pwd)/sub" sub &&
162 git commit -m initial &&
163 test_tick &&
165 cd sub &&
166 echo more data >> file &&
167 git add file &&
168 git commit -m sub_second
169 ) &&
170 git add sub &&
171 git commit -m second
175 test_expect_success 'submodule fast-export | fast-import' '
177 SUBENT1=$(git ls-tree master^ sub) &&
178 SUBENT2=$(git ls-tree master sub) &&
179 rm -rf new &&
180 mkdir new &&
181 git --git-dir=new/.git init &&
182 git fast-export --signed-tags=strip --all >actual &&
183 (cd new &&
184 git fast-import &&
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 &&
201 git mv file file3 &&
202 git commit -m move1 &&
203 test_tick &&
204 cp file2 file4 &&
205 git add file4 &&
206 git mv file2 file5 &&
207 git commit -m copy1 &&
208 test_tick &&
209 cp file3 file6 &&
210 git add file6 &&
211 git commit -m copy2 &&
212 test_tick &&
213 echo more text >> file6 &&
214 echo even more text >> file6 &&
215 git add file6 &&
216 git commit -m modify &&
217 test_tick &&
218 cp file6 file7 &&
219 echo test >> file7 &&
220 git add file7 &&
221 git commit -m copy_modify
225 test_expect_success 'fast-export -C -C | fast-import' '
227 ENTRY=$(git rev-parse --verify copy) &&
228 rm -rf new &&
229 mkdir new &&
230 git --git-dir=new/.git init &&
231 git fast-export -C -C --signed-tags=strip --all > output &&
232 grep "^C file2 file4\$" output &&
233 cat output |
234 (cd new &&
235 git fast-import &&
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)
250 type commit
251 tag rosten
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 &&
271 cd limit-by-paths &&
272 git init &&
273 echo hi > there &&
274 git add there &&
275 git commit -m "First file" &&
276 echo foo > bar &&
277 git add bar &&
278 git commit -m "Second file" &&
279 git tag -a -m msg mytag &&
280 echo morefoo >> bar &&
281 git add bar &&
282 git commit -m "Change to second file"
286 cat > limit-by-paths/expected << EOF
287 blob
288 mark :1
289 data 3
292 reset refs/tags/mytag
293 commit refs/tags/mytag
294 mark :2
295 author A U Thor <author@example.com> 1112912713 -0700
296 committer C O Mitter <committer@example.com> 1112912713 -0700
297 data 11
298 First file
299 M 100644 :1 there
303 test_expect_success 'dropping tag of filtered out object' '
305 cd limit-by-paths &&
306 git fast-export --tag-of-filtered-object=drop mytag -- there > output &&
307 test_cmp expected output
311 cat >> limit-by-paths/expected << EOF
312 tag mytag
313 from :2
314 tagger C O Mitter <committer@example.com> 1112912713 -0700
315 data 4
320 test_expect_success 'rewriting tag of filtered out object' '
322 cd limit-by-paths &&
323 git fast-export --tag-of-filtered-object=rewrite mytag -- there > output &&
324 test_cmp expected output
328 cat > limit-by-paths/expected << EOF
329 blob
330 mark :1
331 data 4
334 blob
335 mark :2
336 data 3
339 reset refs/heads/master
340 commit refs/heads/master
341 mark :3
342 author A U Thor <author@example.com> 1112912713 -0700
343 committer C O Mitter <committer@example.com> 1112912713 -0700
344 data 12
345 Second file
346 M 100644 :1 bar
347 M 100644 :2 there
351 test_expect_failure 'no exact-ref revisions included' '
353 cd limit-by-paths &&
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 &&
363 test_tick &&
364 git commit -mnext file &&
365 git fast-export --import-marks=marks simple -- file file0 >actual &&
366 grep 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' '
385 mkdir result &&
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 &&
398 git init result &&
400 cd dirtosymlink &&
401 mkdir foo &&
402 mkdir bar &&
403 echo hello > foo/world &&
404 echo hello > bar/world &&
405 git add foo/world bar/world &&
406 git commit -q -mone &&
407 git rm -r foo &&
408 test_ln_s_add bar foo &&
409 git commit -q -mtwo
410 ) &&
412 cd dirtosymlink &&
413 git fast-export master -- foo |
414 (cd ../result && git fast-import --quiet)
415 ) &&
416 (cd result && git show master:foo)
419 test_expect_success 'fast-export quotes pathnames' '
420 git init crazy-paths &&
421 (cd 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 &&
437 git init result &&
438 cd result &&
439 git fast-import <../export.out &&
440 git rev-list HEAD >actual &&
441 test_cmp ../expect actual
445 test_expect_success 'test bidirectionality' '
446 >marks-cur &&
447 >marks-new &&
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 &&
451 (cd marks-test &&
452 git reset --hard &&
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
460 blob
461 mark :13
462 data 5
463 bump
465 commit refs/heads/master
466 mark :14
467 author A U Thor <author@example.com> 1112912773 -0700
468 committer C O Mitter <committer@example.com> 1112912773 -0700
469 data 5
470 bump
471 from :12
472 M 100644 :13 file
476 test_expect_success 'avoid uninteresting refs' '
477 > tmp-marks &&
478 git fast-export --import-marks=tmp-marks \
479 --export-marks=tmp-marks master > /dev/null &&
480 git tag v1.0 &&
481 git branch uninteresting &&
482 echo bump > file &&
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
491 from :14
495 test_expect_success 'refs are updated even if no commits need to be exported' '
496 > tmp-marks &&
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_done