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