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