]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9350-fast-export.sh
fast-export: avoid dying when filtering by paths and old tags exist
[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
69test_expect_success 'iso-8859-1' '
70
e0d44c50 71 git config i18n.commitencoding ISO8859-1 &&
f2dc849e 72 # use author and committer name in ISO-8859-1 to match it.
8a7f8bed 73 . "$TEST_DIRECTORY"/t3901/8859-1.txt &&
f2dc849e
JS
74 test_tick &&
75 echo rosten >file &&
76 git commit -s -m den file &&
a4d4e32a
PK
77 git fast-export wer^..wer >iso8859-1.fi &&
78 sed "s/wer/i18n/" iso8859-1.fi |
f2dc849e
JS
79 (cd new &&
80 git fast-import &&
a4d4e32a
PK
81 git cat-file commit i18n >actual &&
82 grep "Áéí óú" actual)
f2dc849e 83
df6a7ff7
PB
84'
85test_expect_success 'import/export-marks' '
86
87 git checkout -b marks master &&
88 git fast-export --export-marks=tmp-marks HEAD &&
89 test -s tmp-marks &&
3fb0459b 90 test_line_count = 3 tmp-marks &&
a4d4e32a
PK
91 git fast-export --import-marks=tmp-marks \
92 --export-marks=tmp-marks HEAD >actual &&
93 test $(grep ^commit actual | wc -l) -eq 0 &&
df6a7ff7
PB
94 echo change > file &&
95 git commit -m "last commit" file &&
a4d4e32a
PK
96 git fast-export --import-marks=tmp-marks \
97 --export-marks=tmp-marks HEAD >actual &&
98 test $(grep ^commit\ actual | wc -l) -eq 1 &&
3fb0459b 99 test_line_count = 4 tmp-marks
df6a7ff7 100
f2dc849e
JS
101'
102
103cat > signed-tag-import << EOF
104tag sign-your-name
105from $(git rev-parse HEAD)
106tagger C O Mitter <committer@example.com> 1112911993 -0700
107data 210
108A message for a sign
109-----BEGIN PGP SIGNATURE-----
110Version: GnuPG v1.4.5 (GNU/Linux)
111
112fakedsignaturefakedsignaturefakedsignaturefakedsignaturfakedsign
113aturefakedsignaturefake=
114=/59v
115-----END PGP SIGNATURE-----
116EOF
117
118test_expect_success 'set up faked signed tag' '
119
120 cat signed-tag-import | git fast-import
121
122'
123
124test_expect_success 'signed-tags=abort' '
125
d492b31c 126 test_must_fail git fast-export --signed-tags=abort sign-your-name
f2dc849e
JS
127
128'
129
ee4bc371 130test_expect_success 'signed-tags=verbatim' '
f2dc849e 131
ee4bc371 132 git fast-export --signed-tags=verbatim sign-your-name > output &&
f2dc849e
JS
133 grep PGP output
134
135'
136
137test_expect_success 'signed-tags=strip' '
138
139 git fast-export --signed-tags=strip sign-your-name > output &&
140 ! grep PGP output
141
142'
143
cd16c59b
JK
144test_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
148'
149
03db4525
AG
150test_expect_success 'setup submodule' '
151
152 git checkout -f master &&
153 mkdir sub &&
4c367c6a
JH
154 (
155 cd sub &&
156 git init &&
157 echo test file > file &&
158 git add file &&
159 git commit -m sub_initial
160 ) &&
c7b793a1 161 git submodule add "$(pwd)/sub" sub &&
03db4525
AG
162 git commit -m initial &&
163 test_tick &&
4c367c6a
JH
164 (
165 cd sub &&
166 echo more data >> file &&
167 git add file &&
168 git commit -m sub_second
169 ) &&
03db4525
AG
170 git add sub &&
171 git commit -m second
172
173'
174
175test_expect_success 'submodule fast-export | fast-import' '
176
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 &&
a4d4e32a 182 git fast-export --signed-tags=strip --all >actual &&
03db4525
AG
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 &&
a4d4e32a 190 cmp sub/file ../sub/file) <actual
03db4525
AG
191
192'
193
91e80b98
JH
194GIT_AUTHOR_NAME='A U Thor'; export GIT_AUTHOR_NAME
195GIT_COMMITTER_NAME='C O Mitter'; export GIT_COMMITTER_NAME
ae7c5dce
AG
196
197test_expect_success 'setup copies' '
198
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
222
223'
224
225test_expect_success 'fast-export -C -C | fast-import' '
226
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 &&
b3e8ca89 232 grep "^C file2 file4\$" output &&
ae7c5dce
AG
233 cat output |
234 (cd new &&
235 git fast-import &&
236 test $ENTRY = $(git rev-parse --verify refs/heads/copy))
237
238'
239
2075ffb5 240test_expect_success 'fast-export | fast-import when master is tagged' '
283b9532
MV
241
242 git tag -m msg last &&
243 git fast-export -C -C --signed-tags=strip --all > output &&
244 test $(grep -c "^tag " output) = 3
245
246'
247
4e46a8d6
JS
248cat > tag-content << EOF
249object $(git rev-parse HEAD)
250type commit
251tag rosten
252EOF
253
254test_expect_success 'cope with tagger-less tags' '
255
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
265
266'
267
25e0ca5d
EN
268test_expect_success 'setup for limiting exports by PATH' '
269 mkdir limit-by-paths &&
4c367c6a
JH
270 (
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"
283 )
25e0ca5d
EN
284'
285
286cat > limit-by-paths/expected << EOF
287blob
288mark :1
289data 3
290hi
291
292reset refs/tags/mytag
293commit refs/tags/mytag
294mark :2
295author A U Thor <author@example.com> 1112912713 -0700
296committer C O Mitter <committer@example.com> 1112912713 -0700
297data 11
298First file
299M 100644 :1 there
300
301EOF
302
303test_expect_success 'dropping tag of filtered out object' '
4c367c6a 304(
25e0ca5d
EN
305 cd limit-by-paths &&
306 git fast-export --tag-of-filtered-object=drop mytag -- there > output &&
9ff10fc8 307 test_cmp expected output
4c367c6a 308)
25e0ca5d
EN
309'
310
311cat >> limit-by-paths/expected << EOF
312tag mytag
313from :2
314tagger C O Mitter <committer@example.com> 1112912713 -0700
315data 4
316msg
317
318EOF
319
320test_expect_success 'rewriting tag of filtered out object' '
4c367c6a 321(
25e0ca5d
EN
322 cd limit-by-paths &&
323 git fast-export --tag-of-filtered-object=rewrite mytag -- there > output &&
9ff10fc8 324 test_cmp expected output
4c367c6a 325)
25e0ca5d
EN
326'
327
1f30c904
EN
328test_expect_success 'rewrite tag predating pathspecs to nothing' '
329 test_create_repo rewrite_tag_predating_pathspecs &&
330 (
331 cd rewrite_tag_predating_pathspecs &&
332
333 test_commit initial &&
334
335 git tag -a -m "Some old tag" v0.0.0.0.0.0.1 &&
336
337 test_commit bar &&
338
339 git fast-export --tag-of-filtered-object=rewrite --all -- bar.t >output &&
340 grep from.$ZERO_OID output
341 )
342'
343
25e0ca5d
EN
344cat > limit-by-paths/expected << EOF
345blob
346mark :1
347data 4
348foo
349
350blob
351mark :2
352data 3
353hi
354
355reset refs/heads/master
356commit refs/heads/master
357mark :3
358author A U Thor <author@example.com> 1112912713 -0700
359committer C O Mitter <committer@example.com> 1112912713 -0700
360data 12
361Second file
362M 100644 :1 bar
363M 100644 :2 there
364
365EOF
366
367test_expect_failure 'no exact-ref revisions included' '
4c367c6a
JH
368 (
369 cd limit-by-paths &&
370 git fast-export master~2..master~1 > output &&
9ff10fc8 371 test_cmp expected output
4c367c6a 372 )
25e0ca5d
EN
373'
374
4087a02e
EN
375test_expect_success 'path limiting with import-marks does not lose unmodified files' '
376 git checkout -b simple marks~2 &&
377 git fast-export --export-marks=marks simple -- file > /dev/null &&
378 echo more content >> file &&
379 test_tick &&
380 git commit -mnext file &&
a4d4e32a
PK
381 git fast-export --import-marks=marks simple -- file file0 >actual &&
382 grep file0 actual
4087a02e
EN
383'
384
7f40ab09
EN
385test_expect_success 'full-tree re-shows unmodified files' '
386 git checkout -f simple &&
a4d4e32a
PK
387 git fast-export --full-tree simple >actual &&
388 test $(grep -c file0 actual) -eq 3
7f40ab09
EN
389'
390
41a5c70f
EFL
391test_expect_success 'set-up a few more tags for tag export tests' '
392 git checkout -f master &&
c7b793a1 393 HEAD_TREE=$(git show -s --pretty=raw HEAD | grep tree | sed "s/tree //") &&
41a5c70f
EFL
394 git tag tree_tag -m "tagging a tree" $HEAD_TREE &&
395 git tag -a tree_tag-obj -m "tagging a tree" $HEAD_TREE &&
396 git tag tag-obj_tag -m "tagging a tag" tree_tag-obj &&
397 git tag -a tag-obj_tag-obj -m "tagging a tag" tree_tag-obj
398'
399
02c48cd6
EN
400test_expect_success 'tree_tag' '
401 mkdir result &&
402 (cd result && git init) &&
403 git fast-export tree_tag > fe-stream &&
404 (cd result && git fast-import < ../fe-stream)
405'
406
41a5c70f 407# NEEDSWORK: not just check return status, but validate the output
c0582c53 408test_expect_success 'tree_tag-obj' 'git fast-export tree_tag-obj'
1982467d
EFL
409test_expect_success 'tag-obj_tag' 'git fast-export tag-obj_tag'
410test_expect_success 'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj'
41a5c70f 411
889c6f0e 412test_expect_success 'directory becomes symlink' '
f15652d9
EN
413 git init dirtosymlink &&
414 git init result &&
415 (
416 cd dirtosymlink &&
417 mkdir foo &&
418 mkdir bar &&
419 echo hello > foo/world &&
420 echo hello > bar/world &&
421 git add foo/world bar/world &&
422 git commit -q -mone &&
423 git rm -r foo &&
889c6f0e 424 test_ln_s_add bar foo &&
f15652d9
EN
425 git commit -q -mtwo
426 ) &&
427 (
428 cd dirtosymlink &&
429 git fast-export master -- foo |
430 (cd ../result && git fast-import --quiet)
431 ) &&
432 (cd result && git show master:foo)
433'
434
6280dfdc
JK
435test_expect_success 'fast-export quotes pathnames' '
436 git init crazy-paths &&
437 (cd crazy-paths &&
c7b793a1 438 blob=$(echo foo | git hash-object -w --stdin) &&
6280dfdc
JK
439 git update-index --add \
440 --cacheinfo 100644 $blob "$(printf "path with\\nnewline")" \
441 --cacheinfo 100644 $blob "path with \"quote\"" \
442 --cacheinfo 100644 $blob "path with \\backslash" \
443 --cacheinfo 100644 $blob "path with space" &&
444 git commit -m addition &&
94221d22 445 git ls-files -z -s | perl -0pe "s{\\t}{$&subdir/}" >index &&
6280dfdc
JK
446 git read-tree --empty &&
447 git update-index -z --index-info <index &&
448 git commit -m rename &&
449 git read-tree --empty &&
450 git commit -m deletion &&
ff59f6da 451 git fast-export -M HEAD >export.out &&
6280dfdc
JK
452 git rev-list HEAD >expect &&
453 git init result &&
454 cd result &&
455 git fast-import <../export.out &&
456 git rev-list HEAD >actual &&
457 test_cmp ../expect actual
458 )
459'
460
5d3698ff
FC
461test_expect_success 'test bidirectionality' '
462 >marks-cur &&
463 >marks-new &&
464 git init marks-test &&
465 git fast-export --export-marks=marks-cur --import-marks=marks-cur --branches | \
466 git --git-dir=marks-test/.git fast-import --export-marks=marks-new --import-marks=marks-new &&
467 (cd marks-test &&
468 git reset --hard &&
469 echo Wohlauf > file &&
470 git commit -a -m "back in time") &&
471 git --git-dir=marks-test/.git fast-export --export-marks=marks-new --import-marks=marks-new --branches | \
472 git fast-import --export-marks=marks-cur --import-marks=marks-cur
473'
474
49266e8a
FC
475cat > expected << EOF
476blob
477mark :13
478data 5
479bump
480
481commit refs/heads/master
482mark :14
483author A U Thor <author@example.com> 1112912773 -0700
484committer C O Mitter <committer@example.com> 1112912773 -0700
485data 5
486bump
487from :12
488M 100644 :13 file
489
490EOF
491
492test_expect_success 'avoid uninteresting refs' '
493 > tmp-marks &&
494 git fast-export --import-marks=tmp-marks \
495 --export-marks=tmp-marks master > /dev/null &&
496 git tag v1.0 &&
497 git branch uninteresting &&
498 echo bump > file &&
499 git commit -a -m bump &&
500 git fast-export --import-marks=tmp-marks \
501 --export-marks=tmp-marks ^uninteresting ^v1.0 master > actual &&
502 test_cmp expected actual
503'
504
f28e7c90
FC
505cat > expected << EOF
506reset refs/heads/master
507from :14
508
509EOF
510
511test_expect_success 'refs are updated even if no commits need to be exported' '
512 > tmp-marks &&
513 git fast-export --import-marks=tmp-marks \
514 --export-marks=tmp-marks master > /dev/null &&
515 git fast-export --import-marks=tmp-marks \
516 --export-marks=tmp-marks master > actual &&
517 test_cmp expected actual
518'
519
03e9010c 520test_expect_success 'use refspec' '
a4d4e32a
PK
521 git fast-export --refspec refs/heads/master:refs/heads/foobar master >actual2 &&
522 grep "^commit " actual2 | sort | uniq >actual &&
03e9010c
FC
523 echo "commit refs/heads/foobar" > expected &&
524 test_cmp expected actual
525'
526
60ed2643
FC
527test_expect_success 'delete refspec' '
528 git branch to-delete &&
529 git fast-export --refspec :refs/heads/to-delete to-delete ^to-delete > actual &&
530 cat > expected <<-EOF &&
531 reset refs/heads/to-delete
532 from 0000000000000000000000000000000000000000
533
534 EOF
535 test_cmp expected actual
536'
537
b3e8ca89
JT
538test_expect_success 'when using -C, do not declare copy when source of copy is also modified' '
539 test_create_repo src &&
540 echo a_line >src/file.txt &&
541 git -C src add file.txt &&
542 git -C src commit -m 1st_commit &&
543
544 cp src/file.txt src/file2.txt &&
545 echo another_line >>src/file.txt &&
546 git -C src add file.txt file2.txt &&
547 git -C src commit -m 2nd_commit &&
548
549 test_create_repo dst &&
a4d4e32a
PK
550 git -C src fast-export --all -C >actual &&
551 git -C dst fast-import <actual &&
b3e8ca89
JT
552 git -C src show >expected &&
553 git -C dst show >actual &&
554 test_cmp expected actual
555'
556
be011bbe
557test_expect_success 'merge commit gets exported with --import-marks' '
558 test_create_repo merging &&
559 (
560 cd merging &&
561 test_commit initial &&
562 git checkout -b topic &&
563 test_commit on-topic &&
564 git checkout master &&
565 test_commit on-master &&
566 test_tick &&
567 git merge --no-ff -m Yeah topic &&
568
569 echo ":1 $(git rev-parse HEAD^^)" >marks &&
570 git fast-export --import-marks=marks master >out &&
571 grep Yeah out
572 )
573'
574
f2dc849e 575test_done