]> git.ipfire.org Git - thirdparty/git.git/blob - t/t9350-fast-export.sh
fast-export: add support for --import-marks-if-exists
[thirdparty/git.git] / t / t9350-fast-export.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2007 Johannes E. Schindelin
4 #
5
6 test_description='git fast-export'
7 . ./test-lib.sh
8
9 test_expect_success 'setup' '
10
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
35
36 '
37
38 test_expect_success 'fast-export | fast-import' '
39
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
53
54 '
55
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 &&
59 tag muss
60 from $(git rev-parse --verify muss^{commit})
61 $(git cat-file tag muss | grep tagger)
62 data 9
63 valentin
64
65 EOF
66 test_cmp expected actual
67 '
68
69 test_expect_success 'fast-export master~2..master' '
70
71 git fast-export master~2..master >actual &&
72 sed "s/master/partial/" actual |
73 (cd new &&
74 git fast-import &&
75 test $MASTER != $(git rev-parse --verify refs/heads/partial) &&
76 git diff --exit-code master partial &&
77 git diff --exit-code master^ partial^ &&
78 test_must_fail git rev-parse partial~2)
79
80 '
81
82 test_expect_success 'fast-export --reference-excluded-parents master~2..master' '
83
84 git fast-export --reference-excluded-parents master~2..master >actual &&
85 grep commit.refs/heads/master actual >commit-count &&
86 test_line_count = 2 commit-count &&
87 sed "s/master/rewrite/" actual |
88 (cd new &&
89 git fast-import &&
90 test $MASTER = $(git rev-parse --verify refs/heads/rewrite))
91 '
92
93 test_expect_success 'fast-export --show-original-ids' '
94
95 git fast-export --show-original-ids master >output &&
96 grep ^original-oid output| sed -e s/^original-oid.// | sort >actual &&
97 git rev-list --objects master muss >objects-and-names &&
98 awk "{print \$1}" objects-and-names | sort >commits-trees-blobs &&
99 comm -23 actual commits-trees-blobs >unfound &&
100 test_must_be_empty unfound
101 '
102
103 test_expect_success 'fast-export --show-original-ids | git fast-import' '
104
105 git fast-export --show-original-ids master muss | git fast-import --quiet &&
106 test $MASTER = $(git rev-parse --verify refs/heads/master) &&
107 test $MUSS = $(git rev-parse --verify refs/tags/muss)
108 '
109
110 test_expect_success 'reencoding iso-8859-7' '
111
112 test_when_finished "git reset --hard HEAD~1" &&
113 test_config i18n.commitencoding iso-8859-7 &&
114 test_tick &&
115 echo rosten >file &&
116 git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file &&
117 git fast-export --reencode=yes wer^..wer >iso-8859-7.fi &&
118 sed "s/wer/i18n/" iso-8859-7.fi |
119 (cd new &&
120 git fast-import &&
121 # The commit object, if not re-encoded, would be 240 bytes.
122 # Removing the "encoding iso-8859-7\n" header drops 20 bytes.
123 # Re-encoding the Pi character from \xF0 (\360) in iso-8859-7
124 # to \xCF\x80 (\317\200) in UTF-8 adds a byte. Check for
125 # the expected size.
126 test 221 -eq "$(git cat-file -s i18n)" &&
127 # ...and for the expected translation of bytes.
128 git cat-file commit i18n >actual &&
129 grep $(printf "\317\200") actual &&
130 # Also make sure the commit does not have the "encoding" header
131 ! grep ^encoding actual)
132 '
133
134 test_expect_success 'aborting on iso-8859-7' '
135
136 test_when_finished "git reset --hard HEAD~1" &&
137 test_config i18n.commitencoding iso-8859-7 &&
138 echo rosten >file &&
139 git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file &&
140 test_must_fail git fast-export --reencode=abort wer^..wer >iso-8859-7.fi
141 '
142
143 test_expect_success 'preserving iso-8859-7' '
144
145 test_when_finished "git reset --hard HEAD~1" &&
146 test_config i18n.commitencoding iso-8859-7 &&
147 echo rosten >file &&
148 git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file &&
149 git fast-export --reencode=no wer^..wer >iso-8859-7.fi &&
150 sed "s/wer/i18n-no-recoding/" iso-8859-7.fi |
151 (cd new &&
152 git fast-import &&
153 # The commit object, if not re-encoded, is 240 bytes.
154 # Removing the "encoding iso-8859-7\n" header would drops 20
155 # bytes. Re-encoding the Pi character from \xF0 (\360) in
156 # iso-8859-7 to \xCF\x80 (\317\200) in UTF-8 adds a byte.
157 # Check for the expected size...
158 test 240 -eq "$(git cat-file -s i18n-no-recoding)" &&
159 # ...as well as the expected byte.
160 git cat-file commit i18n-no-recoding >actual &&
161 grep $(printf "\360") actual &&
162 # Also make sure the commit has the "encoding" header
163 grep ^encoding actual)
164 '
165
166 test_expect_success 'encoding preserved if reencoding fails' '
167
168 test_when_finished "git reset --hard HEAD~1" &&
169 test_config i18n.commitencoding iso-8859-7 &&
170 echo rosten >file &&
171 git commit -s -F "$TEST_DIRECTORY/t9350/broken-iso-8859-7-commit-message.txt" file &&
172 git fast-export --reencode=yes wer^..wer >iso-8859-7.fi &&
173 sed "s/wer/i18n-invalid/" iso-8859-7.fi |
174 (cd new &&
175 git fast-import &&
176 git cat-file commit i18n-invalid >actual &&
177 # Make sure the commit still has the encoding header
178 grep ^encoding actual &&
179 # Verify that the commit has the expected size; i.e.
180 # that no bytes were re-encoded to a different encoding.
181 test 252 -eq "$(git cat-file -s i18n-invalid)" &&
182 # ...and check for the original special bytes
183 grep $(printf "\360") actual &&
184 grep $(printf "\377") actual)
185 '
186
187 test_expect_success 'import/export-marks' '
188
189 git checkout -b marks master &&
190 git fast-export --export-marks=tmp-marks HEAD &&
191 test -s tmp-marks &&
192 test_line_count = 3 tmp-marks &&
193 git fast-export --import-marks=tmp-marks \
194 --export-marks=tmp-marks HEAD >actual &&
195 test $(grep ^commit actual | wc -l) -eq 0 &&
196 echo change > file &&
197 git commit -m "last commit" file &&
198 git fast-export --import-marks=tmp-marks \
199 --export-marks=tmp-marks HEAD >actual &&
200 test $(grep ^commit\ actual | wc -l) -eq 1 &&
201 test_line_count = 4 tmp-marks
202
203 '
204
205 cat > signed-tag-import << EOF
206 tag sign-your-name
207 from $(git rev-parse HEAD)
208 tagger C O Mitter <committer@example.com> 1112911993 -0700
209 data 210
210 A message for a sign
211 -----BEGIN PGP SIGNATURE-----
212 Version: GnuPG v1.4.5 (GNU/Linux)
213
214 fakedsignaturefakedsignaturefakedsignaturefakedsignaturfakedsign
215 aturefakedsignaturefake=
216 =/59v
217 -----END PGP SIGNATURE-----
218 EOF
219
220 test_expect_success 'set up faked signed tag' '
221
222 cat signed-tag-import | git fast-import
223
224 '
225
226 test_expect_success 'signed-tags=abort' '
227
228 test_must_fail git fast-export --signed-tags=abort sign-your-name
229
230 '
231
232 test_expect_success 'signed-tags=verbatim' '
233
234 git fast-export --signed-tags=verbatim sign-your-name > output &&
235 grep PGP output
236
237 '
238
239 test_expect_success 'signed-tags=strip' '
240
241 git fast-export --signed-tags=strip sign-your-name > output &&
242 ! grep PGP output
243
244 '
245
246 test_expect_success 'signed-tags=warn-strip' '
247 git fast-export --signed-tags=warn-strip sign-your-name >output 2>err &&
248 ! grep PGP output &&
249 test -s err
250 '
251
252 test_expect_success 'setup submodule' '
253
254 git checkout -f master &&
255 mkdir sub &&
256 (
257 cd sub &&
258 git init &&
259 echo test file > file &&
260 git add file &&
261 git commit -m sub_initial
262 ) &&
263 git submodule add "$(pwd)/sub" sub &&
264 git commit -m initial &&
265 test_tick &&
266 (
267 cd sub &&
268 echo more data >> file &&
269 git add file &&
270 git commit -m sub_second
271 ) &&
272 git add sub &&
273 git commit -m second
274
275 '
276
277 test_expect_success 'submodule fast-export | fast-import' '
278
279 SUBENT1=$(git ls-tree master^ sub) &&
280 SUBENT2=$(git ls-tree master sub) &&
281 rm -rf new &&
282 mkdir new &&
283 git --git-dir=new/.git init &&
284 git fast-export --signed-tags=strip --all >actual &&
285 (cd new &&
286 git fast-import &&
287 test "$SUBENT1" = "$(git ls-tree refs/heads/master^ sub)" &&
288 test "$SUBENT2" = "$(git ls-tree refs/heads/master sub)" &&
289 git checkout master &&
290 git submodule init &&
291 git submodule update &&
292 cmp sub/file ../sub/file) <actual
293
294 '
295
296 GIT_AUTHOR_NAME='A U Thor'; export GIT_AUTHOR_NAME
297 GIT_COMMITTER_NAME='C O Mitter'; export GIT_COMMITTER_NAME
298
299 test_expect_success 'setup copies' '
300
301 git checkout -b copy rein &&
302 git mv file file3 &&
303 git commit -m move1 &&
304 test_tick &&
305 cp file2 file4 &&
306 git add file4 &&
307 git mv file2 file5 &&
308 git commit -m copy1 &&
309 test_tick &&
310 cp file3 file6 &&
311 git add file6 &&
312 git commit -m copy2 &&
313 test_tick &&
314 echo more text >> file6 &&
315 echo even more text >> file6 &&
316 git add file6 &&
317 git commit -m modify &&
318 test_tick &&
319 cp file6 file7 &&
320 echo test >> file7 &&
321 git add file7 &&
322 git commit -m copy_modify
323
324 '
325
326 test_expect_success 'fast-export -C -C | fast-import' '
327
328 ENTRY=$(git rev-parse --verify copy) &&
329 rm -rf new &&
330 mkdir new &&
331 git --git-dir=new/.git init &&
332 git fast-export -C -C --signed-tags=strip --all > output &&
333 grep "^C file2 file4\$" output &&
334 cat output |
335 (cd new &&
336 git fast-import &&
337 test $ENTRY = $(git rev-parse --verify refs/heads/copy))
338
339 '
340
341 test_expect_success 'fast-export | fast-import when master is tagged' '
342
343 git tag -m msg last &&
344 git fast-export -C -C --signed-tags=strip --all > output &&
345 test $(grep -c "^tag " output) = 3
346
347 '
348
349 cat > tag-content << EOF
350 object $(git rev-parse HEAD)
351 type commit
352 tag rosten
353 EOF
354
355 test_expect_success 'cope with tagger-less tags' '
356
357 TAG=$(git hash-object -t tag -w tag-content) &&
358 git update-ref refs/tags/sonnenschein $TAG &&
359 git fast-export -C -C --signed-tags=strip --all > output &&
360 test $(grep -c "^tag " output) = 4 &&
361 ! grep "Unspecified Tagger" output &&
362 git fast-export -C -C --signed-tags=strip --all \
363 --fake-missing-tagger > output &&
364 test $(grep -c "^tag " output) = 4 &&
365 grep "Unspecified Tagger" output
366
367 '
368
369 test_expect_success 'setup for limiting exports by PATH' '
370 mkdir limit-by-paths &&
371 (
372 cd limit-by-paths &&
373 git init &&
374 echo hi > there &&
375 git add there &&
376 git commit -m "First file" &&
377 echo foo > bar &&
378 git add bar &&
379 git commit -m "Second file" &&
380 git tag -a -m msg mytag &&
381 echo morefoo >> bar &&
382 git add bar &&
383 git commit -m "Change to second file"
384 )
385 '
386
387 cat > limit-by-paths/expected << EOF
388 blob
389 mark :1
390 data 3
391 hi
392
393 reset refs/tags/mytag
394 commit refs/tags/mytag
395 mark :2
396 author A U Thor <author@example.com> 1112912713 -0700
397 committer C O Mitter <committer@example.com> 1112912713 -0700
398 data 11
399 First file
400 M 100644 :1 there
401
402 EOF
403
404 test_expect_success 'dropping tag of filtered out object' '
405 (
406 cd limit-by-paths &&
407 git fast-export --tag-of-filtered-object=drop mytag -- there > output &&
408 test_cmp expected output
409 )
410 '
411
412 cat >> limit-by-paths/expected << EOF
413 tag mytag
414 from :2
415 tagger C O Mitter <committer@example.com> 1112912713 -0700
416 data 4
417 msg
418
419 EOF
420
421 test_expect_success 'rewriting tag of filtered out object' '
422 (
423 cd limit-by-paths &&
424 git fast-export --tag-of-filtered-object=rewrite mytag -- there > output &&
425 test_cmp expected output
426 )
427 '
428
429 test_expect_success 'rewrite tag predating pathspecs to nothing' '
430 test_create_repo rewrite_tag_predating_pathspecs &&
431 (
432 cd rewrite_tag_predating_pathspecs &&
433
434 test_commit initial &&
435
436 git tag -a -m "Some old tag" v0.0.0.0.0.0.1 &&
437
438 test_commit bar &&
439
440 git fast-export --tag-of-filtered-object=rewrite --all -- bar.t >output &&
441 grep from.$ZERO_OID output
442 )
443 '
444
445 cat > limit-by-paths/expected << EOF
446 blob
447 mark :1
448 data 4
449 foo
450
451 blob
452 mark :2
453 data 3
454 hi
455
456 reset refs/heads/master
457 commit refs/heads/master
458 mark :3
459 author A U Thor <author@example.com> 1112912713 -0700
460 committer C O Mitter <committer@example.com> 1112912713 -0700
461 data 12
462 Second file
463 M 100644 :1 bar
464 M 100644 :2 there
465
466 EOF
467
468 test_expect_failure 'no exact-ref revisions included' '
469 (
470 cd limit-by-paths &&
471 git fast-export master~2..master~1 > output &&
472 test_cmp expected output
473 )
474 '
475
476 test_expect_success 'path limiting with import-marks does not lose unmodified files' '
477 git checkout -b simple marks~2 &&
478 git fast-export --export-marks=marks simple -- file > /dev/null &&
479 echo more content >> file &&
480 test_tick &&
481 git commit -mnext file &&
482 git fast-export --import-marks=marks simple -- file file0 >actual &&
483 grep file0 actual
484 '
485
486 test_expect_success 'avoid corrupt stream with non-existent mark' '
487 test_create_repo avoid_non_existent_mark &&
488 (
489 cd avoid_non_existent_mark &&
490
491 test_commit important-path &&
492
493 test_commit ignored &&
494
495 git branch A &&
496 git branch B &&
497
498 echo foo >>important-path.t &&
499 git add important-path.t &&
500 test_commit more changes &&
501
502 git fast-export --all -- important-path.t | git fast-import --force
503 )
504 '
505
506 test_expect_success 'full-tree re-shows unmodified files' '
507 git checkout -f simple &&
508 git fast-export --full-tree simple >actual &&
509 test $(grep -c file0 actual) -eq 3
510 '
511
512 test_expect_success 'set-up a few more tags for tag export tests' '
513 git checkout -f master &&
514 HEAD_TREE=$(git show -s --pretty=raw HEAD | grep tree | sed "s/tree //") &&
515 git tag tree_tag -m "tagging a tree" $HEAD_TREE &&
516 git tag -a tree_tag-obj -m "tagging a tree" $HEAD_TREE &&
517 git tag tag-obj_tag -m "tagging a tag" tree_tag-obj &&
518 git tag -a tag-obj_tag-obj -m "tagging a tag" tree_tag-obj
519 '
520
521 test_expect_success 'tree_tag' '
522 mkdir result &&
523 (cd result && git init) &&
524 git fast-export tree_tag > fe-stream &&
525 (cd result && git fast-import < ../fe-stream)
526 '
527
528 # NEEDSWORK: not just check return status, but validate the output
529 test_expect_success 'tree_tag-obj' 'git fast-export tree_tag-obj'
530 test_expect_success 'tag-obj_tag' 'git fast-export tag-obj_tag'
531 test_expect_success 'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj'
532
533 test_expect_success 'directory becomes symlink' '
534 git init dirtosymlink &&
535 git init result &&
536 (
537 cd dirtosymlink &&
538 mkdir foo &&
539 mkdir bar &&
540 echo hello > foo/world &&
541 echo hello > bar/world &&
542 git add foo/world bar/world &&
543 git commit -q -mone &&
544 git rm -r foo &&
545 test_ln_s_add bar foo &&
546 git commit -q -mtwo
547 ) &&
548 (
549 cd dirtosymlink &&
550 git fast-export master -- foo |
551 (cd ../result && git fast-import --quiet)
552 ) &&
553 (cd result && git show master:foo)
554 '
555
556 test_expect_success 'fast-export quotes pathnames' '
557 git init crazy-paths &&
558 (cd crazy-paths &&
559 blob=$(echo foo | git hash-object -w --stdin) &&
560 git update-index --add \
561 --cacheinfo 100644 $blob "$(printf "path with\\nnewline")" \
562 --cacheinfo 100644 $blob "path with \"quote\"" \
563 --cacheinfo 100644 $blob "path with \\backslash" \
564 --cacheinfo 100644 $blob "path with space" &&
565 git commit -m addition &&
566 git ls-files -z -s | perl -0pe "s{\\t}{$&subdir/}" >index &&
567 git read-tree --empty &&
568 git update-index -z --index-info <index &&
569 git commit -m rename &&
570 git read-tree --empty &&
571 git commit -m deletion &&
572 git fast-export -M HEAD >export.out &&
573 git rev-list HEAD >expect &&
574 git init result &&
575 cd result &&
576 git fast-import <../export.out &&
577 git rev-list HEAD >actual &&
578 test_cmp ../expect actual
579 )
580 '
581
582 test_expect_success 'test bidirectionality' '
583 git init marks-test &&
584 git fast-export --export-marks=marks-cur --import-marks-if-exists=marks-cur --branches | \
585 git --git-dir=marks-test/.git fast-import --export-marks=marks-new --import-marks-if-exists=marks-new &&
586 (cd marks-test &&
587 git reset --hard &&
588 echo Wohlauf > file &&
589 git commit -a -m "back in time") &&
590 git --git-dir=marks-test/.git fast-export --export-marks=marks-new --import-marks-if-exists=marks-new --branches | \
591 git fast-import --export-marks=marks-cur --import-marks-if-exists=marks-cur
592 '
593
594 cat > expected << EOF
595 blob
596 mark :13
597 data 5
598 bump
599
600 commit refs/heads/master
601 mark :14
602 author A U Thor <author@example.com> 1112912773 -0700
603 committer C O Mitter <committer@example.com> 1112912773 -0700
604 data 5
605 bump
606 from :12
607 M 100644 :13 file
608
609 EOF
610
611 test_expect_success 'avoid uninteresting refs' '
612 > tmp-marks &&
613 git fast-export --import-marks=tmp-marks \
614 --export-marks=tmp-marks master > /dev/null &&
615 git tag v1.0 &&
616 git branch uninteresting &&
617 echo bump > file &&
618 git commit -a -m bump &&
619 git fast-export --import-marks=tmp-marks \
620 --export-marks=tmp-marks ^uninteresting ^v1.0 master > actual &&
621 test_cmp expected actual
622 '
623
624 cat > expected << EOF
625 reset refs/heads/master
626 from :14
627
628 EOF
629
630 test_expect_success 'refs are updated even if no commits need to be exported' '
631 > tmp-marks &&
632 git fast-export --import-marks=tmp-marks \
633 --export-marks=tmp-marks master > /dev/null &&
634 git fast-export --import-marks=tmp-marks \
635 --export-marks=tmp-marks master > actual &&
636 test_cmp expected actual
637 '
638
639 test_expect_success 'use refspec' '
640 git fast-export --refspec refs/heads/master:refs/heads/foobar master >actual2 &&
641 grep "^commit " actual2 | sort | uniq >actual &&
642 echo "commit refs/heads/foobar" > expected &&
643 test_cmp expected actual
644 '
645
646 test_expect_success 'delete ref because entire history excluded' '
647 git branch to-delete &&
648 git fast-export to-delete ^to-delete >actual &&
649 cat >expected <<-EOF &&
650 reset refs/heads/to-delete
651 from 0000000000000000000000000000000000000000
652
653 EOF
654 test_cmp expected actual
655 '
656
657 test_expect_success 'delete refspec' '
658 git fast-export --refspec :refs/heads/to-delete >actual &&
659 cat >expected <<-EOF &&
660 reset refs/heads/to-delete
661 from 0000000000000000000000000000000000000000
662
663 EOF
664 test_cmp expected actual
665 '
666
667 test_expect_success 'when using -C, do not declare copy when source of copy is also modified' '
668 test_create_repo src &&
669 echo a_line >src/file.txt &&
670 git -C src add file.txt &&
671 git -C src commit -m 1st_commit &&
672
673 cp src/file.txt src/file2.txt &&
674 echo another_line >>src/file.txt &&
675 git -C src add file.txt file2.txt &&
676 git -C src commit -m 2nd_commit &&
677
678 test_create_repo dst &&
679 git -C src fast-export --all -C >actual &&
680 git -C dst fast-import <actual &&
681 git -C src show >expected &&
682 git -C dst show >actual &&
683 test_cmp expected actual
684 '
685
686 test_expect_success 'merge commit gets exported with --import-marks' '
687 test_create_repo merging &&
688 (
689 cd merging &&
690 test_commit initial &&
691 git checkout -b topic &&
692 test_commit on-topic &&
693 git checkout master &&
694 test_commit on-master &&
695 test_tick &&
696 git merge --no-ff -m Yeah topic &&
697
698 echo ":1 $(git rev-parse HEAD^^)" >marks &&
699 git fast-export --import-marks=marks master >out &&
700 grep Yeah out
701 )
702 '
703
704 test_done