8c8e679468f4b191f93ca68a973d4d58fa1b72d2
[git/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 |
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
56 test_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) &&
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
69 test_expect_success 'iso-8859-1' '
70
71 git config i18n.commitencoding ISO8859-1 &&
72 # use author and committer name in ISO-8859-1 to match it.
73 . "$TEST_DIRECTORY"/t3901-8859-1.txt &&
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
83 '
84 test_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 &&
89 test $(wc -l < tmp-marks) -eq 3 &&
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 &&
104 test $(wc -l < tmp-marks) -eq 4
105
106 '
107
108 cat > signed-tag-import << EOF
109 tag sign-your-name
110 from $(git rev-parse HEAD)
111 tagger C O Mitter <committer@example.com> 1112911993 -0700
112 data 210
113 A message for a sign
114 -----BEGIN PGP SIGNATURE-----
115 Version: GnuPG v1.4.5 (GNU/Linux)
116
117 fakedsignaturefakedsignaturefakedsignaturefakedsignaturfakedsign
118 aturefakedsignaturefake=
119 =/59v
120 -----END PGP SIGNATURE-----
121 EOF
122
123 test_expect_success 'set up faked signed tag' '
124
125 cat signed-tag-import | git fast-import
126
127 '
128
129 test_expect_success 'signed-tags=abort' '
130
131 test_must_fail git fast-export --signed-tags=abort sign-your-name
132
133 '
134
135 test_expect_success 'signed-tags=verbatim' '
136
137 git fast-export --signed-tags=verbatim sign-your-name > output &&
138 grep PGP output
139
140 '
141
142 test_expect_success 'signed-tags=strip' '
143
144 git fast-export --signed-tags=strip sign-your-name > output &&
145 ! grep PGP output
146
147 '
148
149 test_expect_success 'setup submodule' '
150
151 git checkout -f master &&
152 mkdir sub &&
153 (
154 cd sub &&
155 git init &&
156 echo test file > file &&
157 git add file &&
158 git commit -m sub_initial
159 ) &&
160 git submodule add "`pwd`/sub" sub &&
161 git commit -m initial &&
162 test_tick &&
163 (
164 cd sub &&
165 echo more data >> file &&
166 git add file &&
167 git commit -m sub_second
168 ) &&
169 git add sub &&
170 git commit -m second
171
172 '
173
174 test_expect_success 'submodule fast-export | fast-import' '
175
176 SUBENT1=$(git ls-tree master^ sub) &&
177 SUBENT2=$(git ls-tree master sub) &&
178 rm -rf new &&
179 mkdir new &&
180 git --git-dir=new/.git init &&
181 git fast-export --signed-tags=strip --all |
182 (cd new &&
183 git fast-import &&
184 test "$SUBENT1" = "$(git ls-tree refs/heads/master^ sub)" &&
185 test "$SUBENT2" = "$(git ls-tree refs/heads/master sub)" &&
186 git checkout master &&
187 git submodule init &&
188 git submodule update &&
189 cmp sub/file ../sub/file)
190
191 '
192
193 GIT_AUTHOR_NAME='A U Thor'; export GIT_AUTHOR_NAME
194 GIT_COMMITTER_NAME='C O Mitter'; export GIT_COMMITTER_NAME
195
196 test_expect_success 'setup copies' '
197
198 git config --unset i18n.commitencoding &&
199 git checkout -b copy rein &&
200 git mv file file3 &&
201 git commit -m move1 &&
202 test_tick &&
203 cp file2 file4 &&
204 git add file4 &&
205 git mv file2 file5 &&
206 git commit -m copy1 &&
207 test_tick &&
208 cp file3 file6 &&
209 git add file6 &&
210 git commit -m copy2 &&
211 test_tick &&
212 echo more text >> file6 &&
213 echo even more text >> file6 &&
214 git add file6 &&
215 git commit -m modify &&
216 test_tick &&
217 cp file6 file7 &&
218 echo test >> file7 &&
219 git add file7 &&
220 git commit -m copy_modify
221
222 '
223
224 test_expect_success 'fast-export -C -C | fast-import' '
225
226 ENTRY=$(git rev-parse --verify copy) &&
227 rm -rf new &&
228 mkdir new &&
229 git --git-dir=new/.git init &&
230 git fast-export -C -C --signed-tags=strip --all > output &&
231 grep "^C \"file6\" \"file7\"\$" output &&
232 cat output |
233 (cd new &&
234 git fast-import &&
235 test $ENTRY = $(git rev-parse --verify refs/heads/copy))
236
237 '
238
239 test_expect_success 'fast-export | fast-import when master is tagged' '
240
241 git tag -m msg last &&
242 git fast-export -C -C --signed-tags=strip --all > output &&
243 test $(grep -c "^tag " output) = 3
244
245 '
246
247 cat > tag-content << EOF
248 object $(git rev-parse HEAD)
249 type commit
250 tag rosten
251 EOF
252
253 test_expect_success 'cope with tagger-less tags' '
254
255 TAG=$(git hash-object -t tag -w tag-content) &&
256 git update-ref refs/tags/sonnenschein $TAG &&
257 git fast-export -C -C --signed-tags=strip --all > output &&
258 test $(grep -c "^tag " output) = 4 &&
259 ! grep "Unspecified Tagger" output &&
260 git fast-export -C -C --signed-tags=strip --all \
261 --fake-missing-tagger > output &&
262 test $(grep -c "^tag " output) = 4 &&
263 grep "Unspecified Tagger" output
264
265 '
266
267 test_expect_success 'setup for limiting exports by PATH' '
268 mkdir limit-by-paths &&
269 (
270 cd limit-by-paths &&
271 git init &&
272 echo hi > there &&
273 git add there &&
274 git commit -m "First file" &&
275 echo foo > bar &&
276 git add bar &&
277 git commit -m "Second file" &&
278 git tag -a -m msg mytag &&
279 echo morefoo >> bar &&
280 git add bar &&
281 git commit -m "Change to second file"
282 )
283 '
284
285 cat > limit-by-paths/expected << EOF
286 blob
287 mark :1
288 data 3
289 hi
290
291 reset refs/tags/mytag
292 commit refs/tags/mytag
293 mark :2
294 author A U Thor <author@example.com> 1112912713 -0700
295 committer C O Mitter <committer@example.com> 1112912713 -0700
296 data 11
297 First file
298 M 100644 :1 there
299
300 EOF
301
302 test_expect_success 'dropping tag of filtered out object' '
303 (
304 cd limit-by-paths &&
305 git fast-export --tag-of-filtered-object=drop mytag -- there > output &&
306 test_cmp output expected
307 )
308 '
309
310 cat >> limit-by-paths/expected << EOF
311 tag mytag
312 from :2
313 tagger C O Mitter <committer@example.com> 1112912713 -0700
314 data 4
315 msg
316
317 EOF
318
319 test_expect_success 'rewriting tag of filtered out object' '
320 (
321 cd limit-by-paths &&
322 git fast-export --tag-of-filtered-object=rewrite mytag -- there > output &&
323 test_cmp output expected
324 )
325 '
326
327 cat > limit-by-paths/expected << EOF
328 blob
329 mark :1
330 data 4
331 foo
332
333 blob
334 mark :2
335 data 3
336 hi
337
338 reset refs/heads/master
339 commit refs/heads/master
340 mark :3
341 author A U Thor <author@example.com> 1112912713 -0700
342 committer C O Mitter <committer@example.com> 1112912713 -0700
343 data 12
344 Second file
345 M 100644 :1 bar
346 M 100644 :2 there
347
348 EOF
349
350 test_expect_failure 'no exact-ref revisions included' '
351 (
352 cd limit-by-paths &&
353 git fast-export master~2..master~1 > output &&
354 test_cmp output expected
355 )
356 '
357
358 test_expect_success 'path limiting with import-marks does not lose unmodified files' '
359 git checkout -b simple marks~2 &&
360 git fast-export --export-marks=marks simple -- file > /dev/null &&
361 echo more content >> file &&
362 test_tick &&
363 git commit -mnext file &&
364 git fast-export --import-marks=marks simple -- file file0 | grep file0
365 '
366
367 test_expect_success 'full-tree re-shows unmodified files' '
368 git checkout -f simple &&
369 test $(git fast-export --full-tree simple | grep -c file0) -eq 3
370 '
371
372 test_expect_success 'set-up a few more tags for tag export tests' '
373 git checkout -f master &&
374 HEAD_TREE=`git show -s --pretty=raw HEAD | grep tree | sed "s/tree //"` &&
375 git tag tree_tag -m "tagging a tree" $HEAD_TREE &&
376 git tag -a tree_tag-obj -m "tagging a tree" $HEAD_TREE &&
377 git tag tag-obj_tag -m "tagging a tag" tree_tag-obj &&
378 git tag -a tag-obj_tag-obj -m "tagging a tag" tree_tag-obj
379 '
380
381 test_expect_success 'tree_tag' '
382 mkdir result &&
383 (cd result && git init) &&
384 git fast-export tree_tag > fe-stream &&
385 (cd result && git fast-import < ../fe-stream)
386 '
387
388 # NEEDSWORK: not just check return status, but validate the output
389 test_expect_success 'tree_tag-obj' 'git fast-export tree_tag-obj'
390 test_expect_success 'tag-obj_tag' 'git fast-export tag-obj_tag'
391 test_expect_success 'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj'
392
393 test_expect_success SYMLINKS 'directory becomes symlink' '
394 git init dirtosymlink &&
395 git init result &&
396 (
397 cd dirtosymlink &&
398 mkdir foo &&
399 mkdir bar &&
400 echo hello > foo/world &&
401 echo hello > bar/world &&
402 git add foo/world bar/world &&
403 git commit -q -mone &&
404 git rm -r foo &&
405 ln -s bar foo &&
406 git add foo &&
407 git commit -q -mtwo
408 ) &&
409 (
410 cd dirtosymlink &&
411 git fast-export master -- foo |
412 (cd ../result && git fast-import --quiet)
413 ) &&
414 (cd result && git show master:foo)
415 '
416
417 test_done