blob: 409b48e244224629a11ced5d9cbd99fd81f167ae [file] [log] [blame]
Johannes Schindelinf2dc8492007-12-02 14:14:13 +00001#!/bin/sh
2#
3# Copyright (c) 2007 Johannes E. Schindelin
4#
5
Nanako Shiraishieaa2a6f2008-09-10 06:25:25 +09006test_description='git fast-export'
Johannes Schindelina881baa2020-11-18 23:44:42 +00007GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00008export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
Johannes Schindelinf2dc8492007-12-02 14:14:13 +000010. ./test-lib.sh
11
12test_expect_success 'setup' '
13
Elijah Newrenebeec7d2009-03-25 17:53:23 -060014 echo break it > file0 &&
15 git add file0 &&
16 test_tick &&
Johannes Schindelinf2dc8492007-12-02 14:14:13 +000017 echo Wohlauf > file &&
18 git add file &&
19 test_tick &&
20 git commit -m initial &&
21 echo die Luft > file &&
22 echo geht frisch > file2 &&
23 git add file file2 &&
24 test_tick &&
25 git commit -m second &&
26 echo und > file2 &&
27 test_tick &&
28 git commit -m third file2 &&
29 test_tick &&
30 git tag rein &&
31 git checkout -b wer HEAD^ &&
Jonathan Niedera48fcd82010-10-30 20:46:54 -050032 echo lange > file2 &&
Johannes Schindelinf2dc8492007-12-02 14:14:13 +000033 test_tick &&
34 git commit -m sitzt file2 &&
35 test_tick &&
36 git tag -a -m valentin muss &&
Johannes Schindelina881baa2020-11-18 23:44:42 +000037 git merge -s ours main
Johannes Schindelinf2dc8492007-12-02 14:14:13 +000038
39'
40
41test_expect_success 'fast-export | fast-import' '
42
Johannes Schindelina881baa2020-11-18 23:44:42 +000043 MAIN=$(git rev-parse --verify main) &&
Johannes Schindelinf2dc8492007-12-02 14:14:13 +000044 REIN=$(git rev-parse --verify rein) &&
45 WER=$(git rev-parse --verify wer) &&
46 MUSS=$(git rev-parse --verify muss) &&
47 mkdir new &&
48 git --git-dir=new/.git init &&
Pratik Karkia4d4e322018-03-27 23:16:37 +054549 git fast-export --all >actual &&
Johannes Schindelinf2dc8492007-12-02 14:14:13 +000050 (cd new &&
51 git fast-import &&
Johannes Schindelina881baa2020-11-18 23:44:42 +000052 test $MAIN = $(git rev-parse --verify refs/heads/main) &&
Johannes Schindelinf2dc8492007-12-02 14:14:13 +000053 test $REIN = $(git rev-parse --verify refs/tags/rein) &&
54 test $WER = $(git rev-parse --verify refs/heads/wer) &&
Pratik Karkia4d4e322018-03-27 23:16:37 +054555 test $MUSS = $(git rev-parse --verify refs/tags/muss)) <actual
Johannes Schindelinf2dc8492007-12-02 14:14:13 +000056
57'
58
Elijah Newrenaf2abd82019-09-24 18:39:58 -070059test_expect_success 'fast-export ^muss^{commit} muss' '
60 git fast-export --tag-of-filtered-object=rewrite ^muss^{commit} muss >actual &&
61 cat >expected <<-EOF &&
62 tag muss
63 from $(git rev-parse --verify muss^{commit})
64 $(git cat-file tag muss | grep tagger)
65 data 9
66 valentin
67
68 EOF
69 test_cmp expected actual
70'
71
Elijah Newrena1638cf2019-10-03 13:27:07 -070072test_expect_success 'fast-export --mark-tags ^muss^{commit} muss' '
73 git fast-export --mark-tags --tag-of-filtered-object=rewrite ^muss^{commit} muss >actual &&
74 cat >expected <<-EOF &&
75 tag muss
76 mark :1
77 from $(git rev-parse --verify muss^{commit})
78 $(git cat-file tag muss | grep tagger)
79 data 9
80 valentin
81
82 EOF
83 test_cmp expected actual
84'
85
Johannes Schindelina881baa2020-11-18 23:44:42 +000086test_expect_success 'fast-export main~2..main' '
Johannes Schindelinf2dc8492007-12-02 14:14:13 +000087
Johannes Schindelina881baa2020-11-18 23:44:42 +000088 git fast-export main~2..main >actual &&
89 sed "s/main/partial/" actual |
Johannes Schindelinf2dc8492007-12-02 14:14:13 +000090 (cd new &&
91 git fast-import &&
Johannes Schindelina881baa2020-11-18 23:44:42 +000092 test $MAIN != $(git rev-parse --verify refs/heads/partial) &&
93 git diff --exit-code main partial &&
94 git diff --exit-code main^ partial^ &&
Stephan Beyerd492b312008-07-12 17:47:52 +020095 test_must_fail git rev-parse partial~2)
Johannes Schindelinf2dc8492007-12-02 14:14:13 +000096
97'
98
Johannes Schindelina881baa2020-11-18 23:44:42 +000099test_expect_success 'fast-export --reference-excluded-parents main~2..main' '
Elijah Newren530ca192018-11-15 23:59:54 -0800100
Johannes Schindelina881baa2020-11-18 23:44:42 +0000101 git fast-export --reference-excluded-parents main~2..main >actual &&
102 grep commit.refs/heads/main actual >commit-count &&
Elijah Newren530ca192018-11-15 23:59:54 -0800103 test_line_count = 2 commit-count &&
Johannes Schindelina881baa2020-11-18 23:44:42 +0000104 sed "s/main/rewrite/" actual |
Elijah Newren530ca192018-11-15 23:59:54 -0800105 (cd new &&
106 git fast-import &&
Johannes Schindelina881baa2020-11-18 23:44:42 +0000107 test $MAIN = $(git rev-parse --verify refs/heads/rewrite))
Elijah Newren530ca192018-11-15 23:59:54 -0800108'
109
Elijah Newrena965bb32018-11-15 23:59:56 -0800110test_expect_success 'fast-export --show-original-ids' '
111
Johannes Schindelina881baa2020-11-18 23:44:42 +0000112 git fast-export --show-original-ids main >output &&
Elijah Newrena965bb32018-11-15 23:59:56 -0800113 grep ^original-oid output| sed -e s/^original-oid.// | sort >actual &&
Johannes Schindelina881baa2020-11-18 23:44:42 +0000114 git rev-list --objects main muss >objects-and-names &&
Elijah Newrena965bb32018-11-15 23:59:56 -0800115 awk "{print \$1}" objects-and-names | sort >commits-trees-blobs &&
116 comm -23 actual commits-trees-blobs >unfound &&
117 test_must_be_empty unfound
118'
119
120test_expect_success 'fast-export --show-original-ids | git fast-import' '
121
Johannes Schindelina881baa2020-11-18 23:44:42 +0000122 git fast-export --show-original-ids main muss | git fast-import --quiet &&
123 test $MAIN = $(git rev-parse --verify refs/heads/main) &&
Elijah Newrena965bb32018-11-15 23:59:56 -0800124 test $MUSS = $(git rev-parse --verify refs/tags/muss)
125'
126
Elijah Newrene80001f2019-05-13 21:31:02 -0700127test_expect_success 'reencoding iso-8859-7' '
Johannes Schindelinf2dc8492007-12-02 14:14:13 +0000128
Elijah Newren32615ce2019-05-13 21:30:58 -0700129 test_when_finished "git reset --hard HEAD~1" &&
130 test_config i18n.commitencoding iso-8859-7 &&
Johannes Schindelinf2dc8492007-12-02 14:14:13 +0000131 test_tick &&
132 echo rosten >file &&
Elijah Newren32615ce2019-05-13 21:30:58 -0700133 git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file &&
Elijah Newrene80001f2019-05-13 21:31:02 -0700134 git fast-export --reencode=yes wer^..wer >iso-8859-7.fi &&
Elijah Newren32615ce2019-05-13 21:30:58 -0700135 sed "s/wer/i18n/" iso-8859-7.fi |
Johannes Schindelinf2dc8492007-12-02 14:14:13 +0000136 (cd new &&
137 git fast-import &&
brian m. carlson831279d2020-07-29 23:14:13 +0000138 # The commit object, if not re-encoded, would be 200 bytes plus hash.
Elijah Newren32615ce2019-05-13 21:30:58 -0700139 # Removing the "encoding iso-8859-7\n" header drops 20 bytes.
140 # Re-encoding the Pi character from \xF0 (\360) in iso-8859-7
141 # to \xCF\x80 (\317\200) in UTF-8 adds a byte. Check for
142 # the expected size.
brian m. carlson831279d2020-07-29 23:14:13 +0000143 test $(($(test_oid hexsz) + 181)) -eq "$(git cat-file -s i18n)" &&
Elijah Newren32615ce2019-05-13 21:30:58 -0700144 # ...and for the expected translation of bytes.
Pratik Karkia4d4e322018-03-27 23:16:37 +0545145 git cat-file commit i18n >actual &&
Elijah Newren32615ce2019-05-13 21:30:58 -0700146 grep $(printf "\317\200") actual &&
147 # Also make sure the commit does not have the "encoding" header
148 ! grep ^encoding actual)
Johannes Schindelinf2dc8492007-12-02 14:14:13 +0000149'
Elijah Newren32615ce2019-05-13 21:30:58 -0700150
Elijah Newrene80001f2019-05-13 21:31:02 -0700151test_expect_success 'aborting on iso-8859-7' '
152
153 test_when_finished "git reset --hard HEAD~1" &&
154 test_config i18n.commitencoding iso-8859-7 &&
155 echo rosten >file &&
156 git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file &&
157 test_must_fail git fast-export --reencode=abort wer^..wer >iso-8859-7.fi
158'
159
160test_expect_success 'preserving iso-8859-7' '
161
162 test_when_finished "git reset --hard HEAD~1" &&
163 test_config i18n.commitencoding iso-8859-7 &&
164 echo rosten >file &&
165 git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file &&
166 git fast-export --reencode=no wer^..wer >iso-8859-7.fi &&
167 sed "s/wer/i18n-no-recoding/" iso-8859-7.fi |
168 (cd new &&
169 git fast-import &&
brian m. carlson831279d2020-07-29 23:14:13 +0000170 # The commit object, if not re-encoded, is 200 bytes plus hash.
Elijah Newrene80001f2019-05-13 21:31:02 -0700171 # Removing the "encoding iso-8859-7\n" header would drops 20
172 # bytes. Re-encoding the Pi character from \xF0 (\360) in
173 # iso-8859-7 to \xCF\x80 (\317\200) in UTF-8 adds a byte.
174 # Check for the expected size...
brian m. carlson831279d2020-07-29 23:14:13 +0000175 test $(($(test_oid hexsz) + 200)) -eq "$(git cat-file -s i18n-no-recoding)" &&
Elijah Newrene80001f2019-05-13 21:31:02 -0700176 # ...as well as the expected byte.
177 git cat-file commit i18n-no-recoding >actual &&
178 grep $(printf "\360") actual &&
179 # Also make sure the commit has the "encoding" header
180 grep ^encoding actual)
181'
182
Elijah Newrenccbfc962019-05-13 21:31:00 -0700183test_expect_success 'encoding preserved if reencoding fails' '
184
185 test_when_finished "git reset --hard HEAD~1" &&
186 test_config i18n.commitencoding iso-8859-7 &&
187 echo rosten >file &&
188 git commit -s -F "$TEST_DIRECTORY/t9350/broken-iso-8859-7-commit-message.txt" file &&
Elijah Newrene80001f2019-05-13 21:31:02 -0700189 git fast-export --reencode=yes wer^..wer >iso-8859-7.fi &&
Elijah Newrenccbfc962019-05-13 21:31:00 -0700190 sed "s/wer/i18n-invalid/" iso-8859-7.fi |
191 (cd new &&
192 git fast-import &&
193 git cat-file commit i18n-invalid >actual &&
194 # Make sure the commit still has the encoding header
195 grep ^encoding actual &&
196 # Verify that the commit has the expected size; i.e.
197 # that no bytes were re-encoded to a different encoding.
brian m. carlson831279d2020-07-29 23:14:13 +0000198 test $(($(test_oid hexsz) + 212)) -eq "$(git cat-file -s i18n-invalid)" &&
Elijah Newrenccbfc962019-05-13 21:31:00 -0700199 # ...and check for the original special bytes
200 grep $(printf "\360") actual &&
201 grep $(printf "\377") actual)
202'
203
Pieter de Biedf6a7ff2008-06-11 13:17:04 +0200204test_expect_success 'import/export-marks' '
205
Johannes Schindelina881baa2020-11-18 23:44:42 +0000206 git checkout -b marks main &&
Pieter de Biedf6a7ff2008-06-11 13:17:04 +0200207 git fast-export --export-marks=tmp-marks HEAD &&
208 test -s tmp-marks &&
Stefano Lattarini3fb04592012-04-11 13:24:01 +0200209 test_line_count = 3 tmp-marks &&
Pratik Karkia4d4e322018-03-27 23:16:37 +0545210 git fast-export --import-marks=tmp-marks \
211 --export-marks=tmp-marks HEAD >actual &&
212 test $(grep ^commit actual | wc -l) -eq 0 &&
Pieter de Biedf6a7ff2008-06-11 13:17:04 +0200213 echo change > file &&
214 git commit -m "last commit" file &&
Pratik Karkia4d4e322018-03-27 23:16:37 +0545215 git fast-export --import-marks=tmp-marks \
216 --export-marks=tmp-marks HEAD >actual &&
217 test $(grep ^commit\ actual | wc -l) -eq 1 &&
Stefano Lattarini3fb04592012-04-11 13:24:01 +0200218 test_line_count = 4 tmp-marks
Pieter de Biedf6a7ff2008-06-11 13:17:04 +0200219
220'
Johannes Schindelinf2dc8492007-12-02 14:14:13 +0000221
222cat > signed-tag-import << EOF
223tag sign-your-name
224from $(git rev-parse HEAD)
225tagger C O Mitter <committer@example.com> 1112911993 -0700
226data 210
227A message for a sign
228-----BEGIN PGP SIGNATURE-----
229Version: GnuPG v1.4.5 (GNU/Linux)
230
231fakedsignaturefakedsignaturefakedsignaturefakedsignaturfakedsign
232aturefakedsignaturefake=
233=/59v
234-----END PGP SIGNATURE-----
235EOF
236
237test_expect_success 'set up faked signed tag' '
238
239 cat signed-tag-import | git fast-import
240
241'
242
243test_expect_success 'signed-tags=abort' '
244
Stephan Beyerd492b312008-07-12 17:47:52 +0200245 test_must_fail git fast-export --signed-tags=abort sign-your-name
Johannes Schindelinf2dc8492007-12-02 14:14:13 +0000246
247'
248
Johannes Schindelinee4bc372007-12-03 22:44:39 +0000249test_expect_success 'signed-tags=verbatim' '
Johannes Schindelinf2dc8492007-12-02 14:14:13 +0000250
Johannes Schindelinee4bc372007-12-03 22:44:39 +0000251 git fast-export --signed-tags=verbatim sign-your-name > output &&
Johannes Schindelinf2dc8492007-12-02 14:14:13 +0000252 grep PGP output
253
254'
255
256test_expect_success 'signed-tags=strip' '
257
258 git fast-export --signed-tags=strip sign-your-name > output &&
259 ! grep PGP output
260
261'
262
John Keepingcd16c592013-04-14 11:57:06 +0100263test_expect_success 'signed-tags=warn-strip' '
264 git fast-export --signed-tags=warn-strip sign-your-name >output 2>err &&
265 ! grep PGP output &&
266 test -s err
267'
268
Alexander Gavrilov03db4522008-07-19 16:21:24 +0400269test_expect_success 'setup submodule' '
270
Johannes Schindelina881baa2020-11-18 23:44:42 +0000271 git checkout -f main &&
Alexander Gavrilov03db4522008-07-19 16:21:24 +0400272 mkdir sub &&
Junio C Hamano4c367c62010-03-28 17:42:11 -0700273 (
274 cd sub &&
275 git init &&
276 echo test file > file &&
277 git add file &&
278 git commit -m sub_initial
279 ) &&
Elia Pintoc7b793a2016-01-12 11:49:36 +0000280 git submodule add "$(pwd)/sub" sub &&
Alexander Gavrilov03db4522008-07-19 16:21:24 +0400281 git commit -m initial &&
282 test_tick &&
Junio C Hamano4c367c62010-03-28 17:42:11 -0700283 (
284 cd sub &&
285 echo more data >> file &&
286 git add file &&
287 git commit -m sub_second
288 ) &&
Alexander Gavrilov03db4522008-07-19 16:21:24 +0400289 git add sub &&
290 git commit -m second
291
292'
293
294test_expect_success 'submodule fast-export | fast-import' '
295
Johannes Schindelina881baa2020-11-18 23:44:42 +0000296 SUBENT1=$(git ls-tree main^ sub) &&
297 SUBENT2=$(git ls-tree main sub) &&
Alexander Gavrilov03db4522008-07-19 16:21:24 +0400298 rm -rf new &&
299 mkdir new &&
300 git --git-dir=new/.git init &&
Pratik Karkia4d4e322018-03-27 23:16:37 +0545301 git fast-export --signed-tags=strip --all >actual &&
Alexander Gavrilov03db4522008-07-19 16:21:24 +0400302 (cd new &&
303 git fast-import &&
Johannes Schindelina881baa2020-11-18 23:44:42 +0000304 test "$SUBENT1" = "$(git ls-tree refs/heads/main^ sub)" &&
305 test "$SUBENT2" = "$(git ls-tree refs/heads/main sub)" &&
306 git checkout main &&
Alexander Gavrilov03db4522008-07-19 16:21:24 +0400307 git submodule init &&
308 git submodule update &&
Pratik Karkia4d4e322018-03-27 23:16:37 +0545309 cmp sub/file ../sub/file) <actual
Alexander Gavrilov03db4522008-07-19 16:21:24 +0400310
311'
312
Junio C Hamano91e80b92009-02-18 11:17:27 -0800313GIT_AUTHOR_NAME='A U Thor'; export GIT_AUTHOR_NAME
314GIT_COMMITTER_NAME='C O Mitter'; export GIT_COMMITTER_NAME
Alexander Gavrilovae7c5dc2008-07-27 00:52:54 +0400315
316test_expect_success 'setup copies' '
317
Alexander Gavrilovae7c5dc2008-07-27 00:52:54 +0400318 git checkout -b copy rein &&
319 git mv file file3 &&
320 git commit -m move1 &&
321 test_tick &&
322 cp file2 file4 &&
323 git add file4 &&
324 git mv file2 file5 &&
325 git commit -m copy1 &&
326 test_tick &&
327 cp file3 file6 &&
328 git add file6 &&
329 git commit -m copy2 &&
330 test_tick &&
331 echo more text >> file6 &&
332 echo even more text >> file6 &&
333 git add file6 &&
334 git commit -m modify &&
335 test_tick &&
336 cp file6 file7 &&
337 echo test >> file7 &&
338 git add file7 &&
339 git commit -m copy_modify
340
341'
342
343test_expect_success 'fast-export -C -C | fast-import' '
344
345 ENTRY=$(git rev-parse --verify copy) &&
346 rm -rf new &&
347 mkdir new &&
348 git --git-dir=new/.git init &&
349 git fast-export -C -C --signed-tags=strip --all > output &&
Jonathan Tanb3e8ca82017-09-20 16:55:02 -0700350 grep "^C file2 file4\$" output &&
Alexander Gavrilovae7c5dc2008-07-27 00:52:54 +0400351 cat output |
352 (cd new &&
353 git fast-import &&
354 test $ENTRY = $(git rev-parse --verify refs/heads/copy))
355
356'
357
Johannes Schindelina881baa2020-11-18 23:44:42 +0000358test_expect_success 'fast-export | fast-import when main is tagged' '
Miklos Vajna283b9532008-11-22 19:22:48 +0100359
360 git tag -m msg last &&
361 git fast-export -C -C --signed-tags=strip --all > output &&
362 test $(grep -c "^tag " output) = 3
363
364'
365
Johannes Schindelin4e46a8d2008-12-20 01:00:27 +0100366cat > tag-content << EOF
367object $(git rev-parse HEAD)
368type commit
369tag rosten
370EOF
371
372test_expect_success 'cope with tagger-less tags' '
373
374 TAG=$(git hash-object -t tag -w tag-content) &&
375 git update-ref refs/tags/sonnenschein $TAG &&
376 git fast-export -C -C --signed-tags=strip --all > output &&
377 test $(grep -c "^tag " output) = 4 &&
378 ! grep "Unspecified Tagger" output &&
379 git fast-export -C -C --signed-tags=strip --all \
380 --fake-missing-tagger > output &&
381 test $(grep -c "^tag " output) = 4 &&
382 grep "Unspecified Tagger" output
383
384'
385
Elijah Newren25e0ca52009-06-25 22:48:32 -0600386test_expect_success 'setup for limiting exports by PATH' '
387 mkdir limit-by-paths &&
Junio C Hamano4c367c62010-03-28 17:42:11 -0700388 (
389 cd limit-by-paths &&
390 git init &&
391 echo hi > there &&
392 git add there &&
393 git commit -m "First file" &&
394 echo foo > bar &&
395 git add bar &&
396 git commit -m "Second file" &&
397 git tag -a -m msg mytag &&
398 echo morefoo >> bar &&
399 git add bar &&
400 git commit -m "Change to second file"
401 )
Elijah Newren25e0ca52009-06-25 22:48:32 -0600402'
403
404cat > limit-by-paths/expected << EOF
405blob
406mark :1
407data 3
408hi
409
410reset refs/tags/mytag
411commit refs/tags/mytag
412mark :2
413author A U Thor <author@example.com> 1112912713 -0700
414committer C O Mitter <committer@example.com> 1112912713 -0700
415data 11
416First file
417M 100644 :1 there
418
419EOF
420
421test_expect_success 'dropping tag of filtered out object' '
Junio C Hamano4c367c62010-03-28 17:42:11 -0700422(
Elijah Newren25e0ca52009-06-25 22:48:32 -0600423 cd limit-by-paths &&
424 git fast-export --tag-of-filtered-object=drop mytag -- there > output &&
Felipe Contreras9ff10fc2012-11-28 23:11:09 +0100425 test_cmp expected output
Junio C Hamano4c367c62010-03-28 17:42:11 -0700426)
Elijah Newren25e0ca52009-06-25 22:48:32 -0600427'
428
429cat >> limit-by-paths/expected << EOF
430tag mytag
431from :2
432tagger C O Mitter <committer@example.com> 1112912713 -0700
433data 4
434msg
435
436EOF
437
438test_expect_success 'rewriting tag of filtered out object' '
Junio C Hamano4c367c62010-03-28 17:42:11 -0700439(
Elijah Newren25e0ca52009-06-25 22:48:32 -0600440 cd limit-by-paths &&
441 git fast-export --tag-of-filtered-object=rewrite mytag -- there > output &&
Felipe Contreras9ff10fc2012-11-28 23:11:09 +0100442 test_cmp expected output
Junio C Hamano4c367c62010-03-28 17:42:11 -0700443)
Elijah Newren25e0ca52009-06-25 22:48:32 -0600444'
445
Elijah Newren1f30c902018-11-15 23:59:50 -0800446test_expect_success 'rewrite tag predating pathspecs to nothing' '
447 test_create_repo rewrite_tag_predating_pathspecs &&
448 (
449 cd rewrite_tag_predating_pathspecs &&
450
451 test_commit initial &&
452
453 git tag -a -m "Some old tag" v0.0.0.0.0.0.1 &&
454
455 test_commit bar &&
456
457 git fast-export --tag-of-filtered-object=rewrite --all -- bar.t >output &&
458 grep from.$ZERO_OID output
459 )
460'
461
Elijah Newren25e0ca52009-06-25 22:48:32 -0600462cat > limit-by-paths/expected << EOF
463blob
464mark :1
465data 4
466foo
467
468blob
469mark :2
470data 3
471hi
472
Johannes Schindelina881baa2020-11-18 23:44:42 +0000473reset refs/heads/main
474commit refs/heads/main
Elijah Newren25e0ca52009-06-25 22:48:32 -0600475mark :3
476author A U Thor <author@example.com> 1112912713 -0700
477committer C O Mitter <committer@example.com> 1112912713 -0700
478data 12
479Second file
480M 100644 :1 bar
481M 100644 :2 there
482
483EOF
484
485test_expect_failure 'no exact-ref revisions included' '
Junio C Hamano4c367c62010-03-28 17:42:11 -0700486 (
487 cd limit-by-paths &&
Johannes Schindelina881baa2020-11-18 23:44:42 +0000488 git fast-export main~2..main~1 > output &&
Felipe Contreras9ff10fc2012-11-28 23:11:09 +0100489 test_cmp expected output
Junio C Hamano4c367c62010-03-28 17:42:11 -0700490 )
Elijah Newren25e0ca52009-06-25 22:48:32 -0600491'
492
Elijah Newren4087a022010-07-17 11:00:50 -0600493test_expect_success 'path limiting with import-marks does not lose unmodified files' '
494 git checkout -b simple marks~2 &&
495 git fast-export --export-marks=marks simple -- file > /dev/null &&
496 echo more content >> file &&
497 test_tick &&
498 git commit -mnext file &&
Pratik Karkia4d4e322018-03-27 23:16:37 +0545499 git fast-export --import-marks=marks simple -- file file0 >actual &&
500 grep file0 actual
Elijah Newren4087a022010-07-17 11:00:50 -0600501'
502
Elijah Newrencd137622018-11-15 23:59:52 -0800503test_expect_success 'avoid corrupt stream with non-existent mark' '
504 test_create_repo avoid_non_existent_mark &&
505 (
506 cd avoid_non_existent_mark &&
507
508 test_commit important-path &&
509
510 test_commit ignored &&
511
512 git branch A &&
513 git branch B &&
514
515 echo foo >>important-path.t &&
516 git add important-path.t &&
517 test_commit more changes &&
518
519 git fast-export --all -- important-path.t | git fast-import --force
520 )
521'
522
Elijah Newren7f40ab02010-07-17 11:00:51 -0600523test_expect_success 'full-tree re-shows unmodified files' '
524 git checkout -f simple &&
Pratik Karkia4d4e322018-03-27 23:16:37 +0545525 git fast-export --full-tree simple >actual &&
526 test $(grep -c file0 actual) -eq 3
Elijah Newren7f40ab02010-07-17 11:00:51 -0600527'
528
Erik Faye-Lund41a5c702009-03-23 12:53:06 +0000529test_expect_success 'set-up a few more tags for tag export tests' '
Johannes Schindelina881baa2020-11-18 23:44:42 +0000530 git checkout -f main &&
Elia Pintoc7b793a2016-01-12 11:49:36 +0000531 HEAD_TREE=$(git show -s --pretty=raw HEAD | grep tree | sed "s/tree //") &&
Erik Faye-Lund41a5c702009-03-23 12:53:06 +0000532 git tag tree_tag -m "tagging a tree" $HEAD_TREE &&
533 git tag -a tree_tag-obj -m "tagging a tree" $HEAD_TREE &&
534 git tag tag-obj_tag -m "tagging a tag" tree_tag-obj &&
535 git tag -a tag-obj_tag-obj -m "tagging a tag" tree_tag-obj
536'
537
Elijah Newren02c48cd2009-06-25 22:48:28 -0600538test_expect_success 'tree_tag' '
539 mkdir result &&
540 (cd result && git init) &&
541 git fast-export tree_tag > fe-stream &&
542 (cd result && git fast-import < ../fe-stream)
543'
544
Erik Faye-Lund41a5c702009-03-23 12:53:06 +0000545# NEEDSWORK: not just check return status, but validate the output
Elijah Newren8d7d33c2019-10-03 13:27:08 -0700546# Note that these tests DO NOTHING other than print a warning that
Elijah Newren7a40cf12019-11-05 17:07:24 +0000547# they are omitting the one tag we asked them to export (because the
Elijah Newren8d7d33c2019-10-03 13:27:08 -0700548# tags resolve to a tree). They exist just to make sure we do not
549# abort but instead just warn.
Erik Faye-Lundc0582c52009-03-23 12:53:08 +0000550test_expect_success 'tree_tag-obj' 'git fast-export tree_tag-obj'
Erik Faye-Lund19824672009-03-23 12:53:09 +0000551test_expect_success 'tag-obj_tag' 'git fast-export tag-obj_tag'
552test_expect_success 'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj'
Erik Faye-Lund41a5c702009-03-23 12:53:06 +0000553
Elijah Newren8d7d33c2019-10-03 13:27:08 -0700554test_expect_success 'handling tags of blobs' '
Johannes Schindelina881baa2020-11-18 23:44:42 +0000555 git tag -a -m "Tag of a blob" blobtag $(git rev-parse main:file) &&
Elijah Newren8d7d33c2019-10-03 13:27:08 -0700556 git fast-export blobtag >actual &&
557 cat >expect <<-EOF &&
558 blob
559 mark :1
560 data 9
561 die Luft
562
563 tag blobtag
564 from :1
565 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
566 data 14
567 Tag of a blob
568
569 EOF
570 test_cmp expect actual
571'
572
Elijah Newren941790d2019-10-03 13:27:09 -0700573test_expect_success 'handling nested tags' '
Elijah Newren8d7d33c2019-10-03 13:27:08 -0700574 git tag -a -m "This is a nested tag" nested muss &&
575 git fast-export --mark-tags nested >output &&
576 grep "^from $ZERO_OID$" output &&
577 grep "^tag nested$" output >tag_lines &&
578 test_line_count = 2 tag_lines
579'
580
Johannes Sixt889c6f02013-06-07 22:53:28 +0200581test_expect_success 'directory becomes symlink' '
Elijah Newrenf15652d2010-07-09 07:10:51 -0600582 git init dirtosymlink &&
583 git init result &&
584 (
585 cd dirtosymlink &&
586 mkdir foo &&
587 mkdir bar &&
588 echo hello > foo/world &&
589 echo hello > bar/world &&
590 git add foo/world bar/world &&
591 git commit -q -mone &&
592 git rm -r foo &&
Johannes Sixt889c6f02013-06-07 22:53:28 +0200593 test_ln_s_add bar foo &&
Elijah Newrenf15652d2010-07-09 07:10:51 -0600594 git commit -q -mtwo
595 ) &&
596 (
597 cd dirtosymlink &&
Johannes Schindelina881baa2020-11-18 23:44:42 +0000598 git fast-export main -- foo |
Elijah Newrenf15652d2010-07-09 07:10:51 -0600599 (cd ../result && git fast-import --quiet)
600 ) &&
Johannes Schindelina881baa2020-11-18 23:44:42 +0000601 (cd result && git show main:foo)
Elijah Newrenf15652d2010-07-09 07:10:51 -0600602'
603
Jeff King6280dfd2011-08-05 16:36:22 -0600604test_expect_success 'fast-export quotes pathnames' '
605 git init crazy-paths &&
Johannes Schindeline1d911d2019-09-12 14:54:05 +0200606 test_config -C crazy-paths core.protectNTFS false &&
Jeff King6280dfd2011-08-05 16:36:22 -0600607 (cd crazy-paths &&
Elia Pintoc7b793a2016-01-12 11:49:36 +0000608 blob=$(echo foo | git hash-object -w --stdin) &&
Johannes Schindelin35edce22019-09-09 15:43:35 +0200609 git -c core.protectNTFS=false update-index --add \
Jeff King6280dfd2011-08-05 16:36:22 -0600610 --cacheinfo 100644 $blob "$(printf "path with\\nnewline")" \
611 --cacheinfo 100644 $blob "path with \"quote\"" \
612 --cacheinfo 100644 $blob "path with \\backslash" \
613 --cacheinfo 100644 $blob "path with space" &&
614 git commit -m addition &&
Jeff King94221d22013-10-28 21:23:03 -0400615 git ls-files -z -s | perl -0pe "s{\\t}{$&subdir/}" >index &&
Jeff King6280dfd2011-08-05 16:36:22 -0600616 git read-tree --empty &&
617 git update-index -z --index-info <index &&
618 git commit -m rename &&
619 git read-tree --empty &&
620 git commit -m deletion &&
Jay Soffianff59f6d2012-06-27 17:58:01 -0400621 git fast-export -M HEAD >export.out &&
Jeff King6280dfd2011-08-05 16:36:22 -0600622 git rev-list HEAD >expect &&
623 git init result &&
624 cd result &&
625 git fast-import <../export.out &&
626 git rev-list HEAD >actual &&
627 test_cmp ../expect actual
628 )
629'
630
Felipe Contreras5d3698f2012-11-24 04:17:01 +0100631test_expect_success 'test bidirectionality' '
Felipe Contreras5d3698f2012-11-24 04:17:01 +0100632 git init marks-test &&
Elijah Newren208d6922019-10-03 13:27:06 -0700633 git fast-export --export-marks=marks-cur --import-marks-if-exists=marks-cur --branches | \
634 git --git-dir=marks-test/.git fast-import --export-marks=marks-new --import-marks-if-exists=marks-new &&
Felipe Contreras5d3698f2012-11-24 04:17:01 +0100635 (cd marks-test &&
636 git reset --hard &&
637 echo Wohlauf > file &&
638 git commit -a -m "back in time") &&
Elijah Newren208d6922019-10-03 13:27:06 -0700639 git --git-dir=marks-test/.git fast-export --export-marks=marks-new --import-marks-if-exists=marks-new --branches | \
640 git fast-import --export-marks=marks-cur --import-marks-if-exists=marks-cur
Felipe Contreras5d3698f2012-11-24 04:17:01 +0100641'
642
Felipe Contreras49266e82012-11-28 23:23:59 +0100643cat > expected << EOF
644blob
645mark :13
646data 5
647bump
648
Johannes Schindelina881baa2020-11-18 23:44:42 +0000649commit refs/heads/main
Felipe Contreras49266e82012-11-28 23:23:59 +0100650mark :14
651author A U Thor <author@example.com> 1112912773 -0700
652committer C O Mitter <committer@example.com> 1112912773 -0700
653data 5
654bump
655from :12
656M 100644 :13 file
657
658EOF
659
660test_expect_success 'avoid uninteresting refs' '
661 > tmp-marks &&
662 git fast-export --import-marks=tmp-marks \
Johannes Schindelina881baa2020-11-18 23:44:42 +0000663 --export-marks=tmp-marks main > /dev/null &&
Felipe Contreras49266e82012-11-28 23:23:59 +0100664 git tag v1.0 &&
665 git branch uninteresting &&
666 echo bump > file &&
667 git commit -a -m bump &&
668 git fast-export --import-marks=tmp-marks \
Johannes Schindelina881baa2020-11-18 23:44:42 +0000669 --export-marks=tmp-marks ^uninteresting ^v1.0 main > actual &&
Felipe Contreras49266e82012-11-28 23:23:59 +0100670 test_cmp expected actual
671'
672
Felipe Contrerasf28e7c92012-11-28 23:24:00 +0100673cat > expected << EOF
Johannes Schindelina881baa2020-11-18 23:44:42 +0000674reset refs/heads/main
Felipe Contrerasf28e7c92012-11-28 23:24:00 +0100675from :14
676
677EOF
678
679test_expect_success 'refs are updated even if no commits need to be exported' '
680 > tmp-marks &&
681 git fast-export --import-marks=tmp-marks \
Johannes Schindelina881baa2020-11-18 23:44:42 +0000682 --export-marks=tmp-marks main > /dev/null &&
Felipe Contrerasf28e7c92012-11-28 23:24:00 +0100683 git fast-export --import-marks=tmp-marks \
Johannes Schindelina881baa2020-11-18 23:44:42 +0000684 --export-marks=tmp-marks main > actual &&
Felipe Contrerasf28e7c92012-11-28 23:24:00 +0100685 test_cmp expected actual
686'
687
Felipe Contreras03e90102014-04-20 13:59:24 -0500688test_expect_success 'use refspec' '
Johannes Schindelina881baa2020-11-18 23:44:42 +0000689 git fast-export --refspec refs/heads/main:refs/heads/foobar main >actual2 &&
Pratik Karkia4d4e322018-03-27 23:16:37 +0545690 grep "^commit " actual2 | sort | uniq >actual &&
Felipe Contreras03e90102014-04-20 13:59:24 -0500691 echo "commit refs/heads/foobar" > expected &&
692 test_cmp expected actual
693'
694
Elijah Newrenfdf31b62018-11-15 23:59:53 -0800695test_expect_success 'delete ref because entire history excluded' '
Felipe Contreras60ed2642014-04-20 13:59:28 -0500696 git branch to-delete &&
Elijah Newrenfdf31b62018-11-15 23:59:53 -0800697 git fast-export to-delete ^to-delete >actual &&
698 cat >expected <<-EOF &&
699 reset refs/heads/to-delete
brian m. carlson831279d2020-07-29 23:14:13 +0000700 from $ZERO_OID
Elijah Newrenfdf31b62018-11-15 23:59:53 -0800701
702 EOF
703 test_cmp expected actual
704'
705
706test_expect_success 'delete refspec' '
707 git fast-export --refspec :refs/heads/to-delete >actual &&
708 cat >expected <<-EOF &&
Felipe Contreras60ed2642014-04-20 13:59:28 -0500709 reset refs/heads/to-delete
brian m. carlson831279d2020-07-29 23:14:13 +0000710 from $ZERO_OID
Felipe Contreras60ed2642014-04-20 13:59:28 -0500711
712 EOF
713 test_cmp expected actual
714'
715
Jonathan Tanb3e8ca82017-09-20 16:55:02 -0700716test_expect_success 'when using -C, do not declare copy when source of copy is also modified' '
717 test_create_repo src &&
718 echo a_line >src/file.txt &&
719 git -C src add file.txt &&
720 git -C src commit -m 1st_commit &&
721
722 cp src/file.txt src/file2.txt &&
723 echo another_line >>src/file.txt &&
724 git -C src add file.txt file2.txt &&
725 git -C src commit -m 2nd_commit &&
726
727 test_create_repo dst &&
Pratik Karkia4d4e322018-03-27 23:16:37 +0545728 git -C src fast-export --all -C >actual &&
729 git -C dst fast-import <actual &&
Jonathan Tanb3e8ca82017-09-20 16:55:02 -0700730 git -C src show >expected &&
731 git -C dst show >actual &&
732 test_cmp expected actual
733'
734
Martin Ågrenbe011bb2018-04-21 00:12:31 +0200735test_expect_success 'merge commit gets exported with --import-marks' '
736 test_create_repo merging &&
737 (
738 cd merging &&
739 test_commit initial &&
740 git checkout -b topic &&
741 test_commit on-topic &&
Johannes Schindelina881baa2020-11-18 23:44:42 +0000742 git checkout main &&
743 test_commit on-main &&
Martin Ågrenbe011bb2018-04-21 00:12:31 +0200744 test_tick &&
745 git merge --no-ff -m Yeah topic &&
746
747 echo ":1 $(git rev-parse HEAD^^)" >marks &&
Johannes Schindelina881baa2020-11-18 23:44:42 +0000748 git fast-export --import-marks=marks main >out &&
Martin Ågrenbe011bb2018-04-21 00:12:31 +0200749 grep Yeah out
750 )
751'
752
Johannes Schindelinf2dc8492007-12-02 14:14:13 +0000753test_done