]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9350-fast-export.sh
test-lib: refactor $GIT_SKIP_TESTS matching
[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 &&
46 git fast-export --all |
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))
53
54'
55
56test_expect_success 'fast-export master~2..master' '
57
58 git fast-export master~2..master |
59 sed "s/master/partial/" |
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.
bfdbee98 73 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
f2dc849e
JS
74 test_tick &&
75 echo rosten >file &&
76 git commit -s -m den file &&
77 git fast-export wer^..wer |
78 sed "s/wer/i18n/" |
79 (cd new &&
80 git fast-import &&
81 git cat-file commit i18n | grep "Áéí óú")
82
df6a7ff7
PB
83'
84test_expect_success 'import/export-marks' '
85
86 git checkout -b marks master &&
87 git fast-export --export-marks=tmp-marks HEAD &&
88 test -s tmp-marks &&
3fb0459b 89 test_line_count = 3 tmp-marks &&
df6a7ff7
PB
90 test $(
91 git fast-export --import-marks=tmp-marks\
92 --export-marks=tmp-marks HEAD |
93 grep ^commit |
94 wc -l) \
95 -eq 0 &&
96 echo change > file &&
97 git commit -m "last commit" file &&
98 test $(
99 git fast-export --import-marks=tmp-marks \
100 --export-marks=tmp-marks HEAD |
101 grep ^commit\ |
102 wc -l) \
103 -eq 1 &&
3fb0459b 104 test_line_count = 4 tmp-marks
df6a7ff7 105
f2dc849e
JS
106'
107
108cat > signed-tag-import << EOF
109tag sign-your-name
110from $(git rev-parse HEAD)
111tagger C O Mitter <committer@example.com> 1112911993 -0700
112data 210
113A message for a sign
114-----BEGIN PGP SIGNATURE-----
115Version: GnuPG v1.4.5 (GNU/Linux)
116
117fakedsignaturefakedsignaturefakedsignaturefakedsignaturfakedsign
118aturefakedsignaturefake=
119=/59v
120-----END PGP SIGNATURE-----
121EOF
122
123test_expect_success 'set up faked signed tag' '
124
125 cat signed-tag-import | git fast-import
126
127'
128
129test_expect_success 'signed-tags=abort' '
130
d492b31c 131 test_must_fail git fast-export --signed-tags=abort sign-your-name
f2dc849e
JS
132
133'
134
ee4bc371 135test_expect_success 'signed-tags=verbatim' '
f2dc849e 136
ee4bc371 137 git fast-export --signed-tags=verbatim sign-your-name > output &&
f2dc849e
JS
138 grep PGP output
139
140'
141
142test_expect_success 'signed-tags=strip' '
143
144 git fast-export --signed-tags=strip sign-your-name > output &&
145 ! grep PGP output
146
147'
148
cd16c59b
JK
149test_expect_success 'signed-tags=warn-strip' '
150 git fast-export --signed-tags=warn-strip sign-your-name >output 2>err &&
151 ! grep PGP output &&
152 test -s err
153'
154
03db4525
AG
155test_expect_success 'setup submodule' '
156
157 git checkout -f master &&
158 mkdir sub &&
4c367c6a
JH
159 (
160 cd sub &&
161 git init &&
162 echo test file > file &&
163 git add file &&
164 git commit -m sub_initial
165 ) &&
03db4525
AG
166 git submodule add "`pwd`/sub" sub &&
167 git commit -m initial &&
168 test_tick &&
4c367c6a
JH
169 (
170 cd sub &&
171 echo more data >> file &&
172 git add file &&
173 git commit -m sub_second
174 ) &&
03db4525
AG
175 git add sub &&
176 git commit -m second
177
178'
179
180test_expect_success 'submodule fast-export | fast-import' '
181
182 SUBENT1=$(git ls-tree master^ sub) &&
183 SUBENT2=$(git ls-tree master sub) &&
184 rm -rf new &&
185 mkdir new &&
186 git --git-dir=new/.git init &&
187 git fast-export --signed-tags=strip --all |
188 (cd new &&
189 git fast-import &&
190 test "$SUBENT1" = "$(git ls-tree refs/heads/master^ sub)" &&
191 test "$SUBENT2" = "$(git ls-tree refs/heads/master sub)" &&
192 git checkout master &&
193 git submodule init &&
194 git submodule update &&
195 cmp sub/file ../sub/file)
196
197'
198
91e80b98
JH
199GIT_AUTHOR_NAME='A U Thor'; export GIT_AUTHOR_NAME
200GIT_COMMITTER_NAME='C O Mitter'; export GIT_COMMITTER_NAME
ae7c5dce
AG
201
202test_expect_success 'setup copies' '
203
204 git config --unset i18n.commitencoding &&
205 git checkout -b copy rein &&
206 git mv file file3 &&
207 git commit -m move1 &&
208 test_tick &&
209 cp file2 file4 &&
210 git add file4 &&
211 git mv file2 file5 &&
212 git commit -m copy1 &&
213 test_tick &&
214 cp file3 file6 &&
215 git add file6 &&
216 git commit -m copy2 &&
217 test_tick &&
218 echo more text >> file6 &&
219 echo even more text >> file6 &&
220 git add file6 &&
221 git commit -m modify &&
222 test_tick &&
223 cp file6 file7 &&
224 echo test >> file7 &&
225 git add file7 &&
226 git commit -m copy_modify
227
228'
229
230test_expect_success 'fast-export -C -C | fast-import' '
231
232 ENTRY=$(git rev-parse --verify copy) &&
233 rm -rf new &&
234 mkdir new &&
235 git --git-dir=new/.git init &&
236 git fast-export -C -C --signed-tags=strip --all > output &&
6280dfdc 237 grep "^C file6 file7\$" output &&
ae7c5dce
AG
238 cat output |
239 (cd new &&
240 git fast-import &&
241 test $ENTRY = $(git rev-parse --verify refs/heads/copy))
242
243'
244
2075ffb5 245test_expect_success 'fast-export | fast-import when master is tagged' '
283b9532
MV
246
247 git tag -m msg last &&
248 git fast-export -C -C --signed-tags=strip --all > output &&
249 test $(grep -c "^tag " output) = 3
250
251'
252
4e46a8d6
JS
253cat > tag-content << EOF
254object $(git rev-parse HEAD)
255type commit
256tag rosten
257EOF
258
259test_expect_success 'cope with tagger-less tags' '
260
261 TAG=$(git hash-object -t tag -w tag-content) &&
262 git update-ref refs/tags/sonnenschein $TAG &&
263 git fast-export -C -C --signed-tags=strip --all > output &&
264 test $(grep -c "^tag " output) = 4 &&
265 ! grep "Unspecified Tagger" output &&
266 git fast-export -C -C --signed-tags=strip --all \
267 --fake-missing-tagger > output &&
268 test $(grep -c "^tag " output) = 4 &&
269 grep "Unspecified Tagger" output
270
271'
272
25e0ca5d
EN
273test_expect_success 'setup for limiting exports by PATH' '
274 mkdir limit-by-paths &&
4c367c6a
JH
275 (
276 cd limit-by-paths &&
277 git init &&
278 echo hi > there &&
279 git add there &&
280 git commit -m "First file" &&
281 echo foo > bar &&
282 git add bar &&
283 git commit -m "Second file" &&
284 git tag -a -m msg mytag &&
285 echo morefoo >> bar &&
286 git add bar &&
287 git commit -m "Change to second file"
288 )
25e0ca5d
EN
289'
290
291cat > limit-by-paths/expected << EOF
292blob
293mark :1
294data 3
295hi
296
297reset refs/tags/mytag
298commit refs/tags/mytag
299mark :2
300author A U Thor <author@example.com> 1112912713 -0700
301committer C O Mitter <committer@example.com> 1112912713 -0700
302data 11
303First file
304M 100644 :1 there
305
306EOF
307
308test_expect_success 'dropping tag of filtered out object' '
4c367c6a 309(
25e0ca5d
EN
310 cd limit-by-paths &&
311 git fast-export --tag-of-filtered-object=drop mytag -- there > output &&
9ff10fc8 312 test_cmp expected output
4c367c6a 313)
25e0ca5d
EN
314'
315
316cat >> limit-by-paths/expected << EOF
317tag mytag
318from :2
319tagger C O Mitter <committer@example.com> 1112912713 -0700
320data 4
321msg
322
323EOF
324
325test_expect_success 'rewriting tag of filtered out object' '
4c367c6a 326(
25e0ca5d
EN
327 cd limit-by-paths &&
328 git fast-export --tag-of-filtered-object=rewrite mytag -- there > output &&
9ff10fc8 329 test_cmp expected output
4c367c6a 330)
25e0ca5d
EN
331'
332
333cat > limit-by-paths/expected << EOF
334blob
335mark :1
336data 4
337foo
338
339blob
340mark :2
341data 3
342hi
343
344reset refs/heads/master
345commit refs/heads/master
346mark :3
347author A U Thor <author@example.com> 1112912713 -0700
348committer C O Mitter <committer@example.com> 1112912713 -0700
349data 12
350Second file
351M 100644 :1 bar
352M 100644 :2 there
353
354EOF
355
356test_expect_failure 'no exact-ref revisions included' '
4c367c6a
JH
357 (
358 cd limit-by-paths &&
359 git fast-export master~2..master~1 > output &&
9ff10fc8 360 test_cmp expected output
4c367c6a 361 )
25e0ca5d
EN
362'
363
4087a02e
EN
364test_expect_success 'path limiting with import-marks does not lose unmodified files' '
365 git checkout -b simple marks~2 &&
366 git fast-export --export-marks=marks simple -- file > /dev/null &&
367 echo more content >> file &&
368 test_tick &&
369 git commit -mnext file &&
370 git fast-export --import-marks=marks simple -- file file0 | grep file0
371'
372
7f40ab09
EN
373test_expect_success 'full-tree re-shows unmodified files' '
374 git checkout -f simple &&
375 test $(git fast-export --full-tree simple | grep -c file0) -eq 3
376'
377
41a5c70f
EFL
378test_expect_success 'set-up a few more tags for tag export tests' '
379 git checkout -f master &&
380 HEAD_TREE=`git show -s --pretty=raw HEAD | grep tree | sed "s/tree //"` &&
381 git tag tree_tag -m "tagging a tree" $HEAD_TREE &&
382 git tag -a tree_tag-obj -m "tagging a tree" $HEAD_TREE &&
383 git tag tag-obj_tag -m "tagging a tag" tree_tag-obj &&
384 git tag -a tag-obj_tag-obj -m "tagging a tag" tree_tag-obj
385'
386
02c48cd6
EN
387test_expect_success 'tree_tag' '
388 mkdir result &&
389 (cd result && git init) &&
390 git fast-export tree_tag > fe-stream &&
391 (cd result && git fast-import < ../fe-stream)
392'
393
41a5c70f 394# NEEDSWORK: not just check return status, but validate the output
c0582c53 395test_expect_success 'tree_tag-obj' 'git fast-export tree_tag-obj'
1982467d
EFL
396test_expect_success 'tag-obj_tag' 'git fast-export tag-obj_tag'
397test_expect_success 'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj'
41a5c70f 398
dd568581 399test_expect_success SYMLINKS 'directory becomes symlink' '
f15652d9
EN
400 git init dirtosymlink &&
401 git init result &&
402 (
403 cd dirtosymlink &&
404 mkdir foo &&
405 mkdir bar &&
406 echo hello > foo/world &&
407 echo hello > bar/world &&
408 git add foo/world bar/world &&
409 git commit -q -mone &&
410 git rm -r foo &&
411 ln -s bar foo &&
412 git add foo &&
413 git commit -q -mtwo
414 ) &&
415 (
416 cd dirtosymlink &&
417 git fast-export master -- foo |
418 (cd ../result && git fast-import --quiet)
419 ) &&
420 (cd result && git show master:foo)
421'
422
6280dfdc
JK
423test_expect_success 'fast-export quotes pathnames' '
424 git init crazy-paths &&
425 (cd crazy-paths &&
426 blob=`echo foo | git hash-object -w --stdin` &&
427 git update-index --add \
428 --cacheinfo 100644 $blob "$(printf "path with\\nnewline")" \
429 --cacheinfo 100644 $blob "path with \"quote\"" \
430 --cacheinfo 100644 $blob "path with \\backslash" \
431 --cacheinfo 100644 $blob "path with space" &&
432 git commit -m addition &&
7096b648 433 git ls-files -z -s | "$PERL_PATH" -0pe "s{\\t}{$&subdir/}" >index &&
6280dfdc
JK
434 git read-tree --empty &&
435 git update-index -z --index-info <index &&
436 git commit -m rename &&
437 git read-tree --empty &&
438 git commit -m deletion &&
ff59f6da 439 git fast-export -M HEAD >export.out &&
6280dfdc
JK
440 git rev-list HEAD >expect &&
441 git init result &&
442 cd result &&
443 git fast-import <../export.out &&
444 git rev-list HEAD >actual &&
445 test_cmp ../expect actual
446 )
447'
448
5d3698ff
FC
449test_expect_success 'test bidirectionality' '
450 >marks-cur &&
451 >marks-new &&
452 git init marks-test &&
453 git fast-export --export-marks=marks-cur --import-marks=marks-cur --branches | \
454 git --git-dir=marks-test/.git fast-import --export-marks=marks-new --import-marks=marks-new &&
455 (cd marks-test &&
456 git reset --hard &&
457 echo Wohlauf > file &&
458 git commit -a -m "back in time") &&
459 git --git-dir=marks-test/.git fast-export --export-marks=marks-new --import-marks=marks-new --branches | \
460 git fast-import --export-marks=marks-cur --import-marks=marks-cur
461'
462
49266e8a
FC
463cat > expected << EOF
464blob
465mark :13
466data 5
467bump
468
469commit refs/heads/master
470mark :14
471author A U Thor <author@example.com> 1112912773 -0700
472committer C O Mitter <committer@example.com> 1112912773 -0700
473data 5
474bump
475from :12
476M 100644 :13 file
477
478EOF
479
480test_expect_success 'avoid uninteresting refs' '
481 > tmp-marks &&
482 git fast-export --import-marks=tmp-marks \
483 --export-marks=tmp-marks master > /dev/null &&
484 git tag v1.0 &&
485 git branch uninteresting &&
486 echo bump > file &&
487 git commit -a -m bump &&
488 git fast-export --import-marks=tmp-marks \
489 --export-marks=tmp-marks ^uninteresting ^v1.0 master > actual &&
490 test_cmp expected actual
491'
492
f28e7c90
FC
493cat > expected << EOF
494reset refs/heads/master
495from :14
496
497EOF
498
499test_expect_success 'refs are updated even if no commits need to be exported' '
500 > tmp-marks &&
501 git fast-export --import-marks=tmp-marks \
502 --export-marks=tmp-marks master > /dev/null &&
503 git fast-export --import-marks=tmp-marks \
504 --export-marks=tmp-marks master > actual &&
505 test_cmp expected actual
506'
507
f2dc849e 508test_done