]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9350-fast-export.sh
Merge branch 'es/add-doc-list-short-form-of-all-in-synopsis'
[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'
a881baa2 7GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
8export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
f2dc849e
JS
10. ./test-lib.sh
11
12test_expect_success 'setup' '
13
ebeec7db
EN
14 echo break it > file0 &&
15 git add file0 &&
16 test_tick &&
f2dc849e
JS
17 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^ &&
a48fcd83 32 echo lange > file2 &&
f2dc849e
JS
33 test_tick &&
34 git commit -m sitzt file2 &&
35 test_tick &&
36 git tag -a -m valentin muss &&
a881baa2 37 git merge -s ours main
f2dc849e
JS
38
39'
40
41test_expect_success 'fast-export | fast-import' '
42
a881baa2 43 MAIN=$(git rev-parse --verify main) &&
f2dc849e
JS
44 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 &&
a4d4e32a 49 git fast-export --all >actual &&
f2dc849e
JS
50 (cd new &&
51 git fast-import &&
a881baa2 52 test $MAIN = $(git rev-parse --verify refs/heads/main) &&
f2dc849e
JS
53 test $REIN = $(git rev-parse --verify refs/tags/rein) &&
54 test $WER = $(git rev-parse --verify refs/heads/wer) &&
a4d4e32a 55 test $MUSS = $(git rev-parse --verify refs/tags/muss)) <actual
f2dc849e
JS
56
57'
58
af2abd87
EN
59test_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
a1638cfe
EN
72test_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
a881baa2 86test_expect_success 'fast-export main~2..main' '
f2dc849e 87
a881baa2
JS
88 git fast-export main~2..main >actual &&
89 sed "s/main/partial/" actual |
f2dc849e
JS
90 (cd new &&
91 git fast-import &&
a881baa2
JS
92 test $MAIN != $(git rev-parse --verify refs/heads/partial) &&
93 git diff --exit-code main partial &&
94 git diff --exit-code main^ partial^ &&
d492b31c 95 test_must_fail git rev-parse partial~2)
f2dc849e
JS
96
97'
98
a881baa2 99test_expect_success 'fast-export --reference-excluded-parents main~2..main' '
530ca19c 100
a881baa2
JS
101 git fast-export --reference-excluded-parents main~2..main >actual &&
102 grep commit.refs/heads/main actual >commit-count &&
530ca19c 103 test_line_count = 2 commit-count &&
a881baa2 104 sed "s/main/rewrite/" actual |
530ca19c
EN
105 (cd new &&
106 git fast-import &&
a881baa2 107 test $MAIN = $(git rev-parse --verify refs/heads/rewrite))
530ca19c
EN
108'
109
a965bb31
EN
110test_expect_success 'fast-export --show-original-ids' '
111
a881baa2 112 git fast-export --show-original-ids main >output &&
a965bb31 113 grep ^original-oid output| sed -e s/^original-oid.// | sort >actual &&
a881baa2 114 git rev-list --objects main muss >objects-and-names &&
a965bb31
EN
115 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
a881baa2
JS
122 git fast-export --show-original-ids main muss | git fast-import --quiet &&
123 test $MAIN = $(git rev-parse --verify refs/heads/main) &&
a965bb31
EN
124 test $MUSS = $(git rev-parse --verify refs/tags/muss)
125'
126
e80001f8 127test_expect_success 'reencoding iso-8859-7' '
f2dc849e 128
32615ce7
EN
129 test_when_finished "git reset --hard HEAD~1" &&
130 test_config i18n.commitencoding iso-8859-7 &&
f2dc849e
JS
131 test_tick &&
132 echo rosten >file &&
32615ce7 133 git commit -s -F "$TEST_DIRECTORY/t9350/simple-iso-8859-7-commit-message.txt" file &&
e80001f8 134 git fast-export --reencode=yes wer^..wer >iso-8859-7.fi &&
32615ce7 135 sed "s/wer/i18n/" iso-8859-7.fi |
f2dc849e
JS
136 (cd new &&
137 git fast-import &&
831279d3 138 # The commit object, if not re-encoded, would be 200 bytes plus hash.
32615ce7
EN
139 # 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.
831279d3 143 test $(($(test_oid hexsz) + 181)) -eq "$(git cat-file -s i18n)" &&
32615ce7 144 # ...and for the expected translation of bytes.
a4d4e32a 145 git cat-file commit i18n >actual &&
32615ce7
EN
146 grep $(printf "\317\200") actual &&
147 # Also make sure the commit does not have the "encoding" header
148 ! grep ^encoding actual)
df6a7ff7 149'
32615ce7 150
e80001f8
EN
151test_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 &&
831279d3 170 # The commit object, if not re-encoded, is 200 bytes plus hash.
e80001f8
EN
171 # 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...
831279d3 175 test $(($(test_oid hexsz) + 200)) -eq "$(git cat-file -s i18n-no-recoding)" &&
e80001f8
EN
176 # ...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
ccbfc96d
EN
183test_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 &&
e80001f8 189 git fast-export --reencode=yes wer^..wer >iso-8859-7.fi &&
ccbfc96d
EN
190 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.
831279d3 198 test $(($(test_oid hexsz) + 212)) -eq "$(git cat-file -s i18n-invalid)" &&
ccbfc96d
EN
199 # ...and check for the original special bytes
200 grep $(printf "\360") actual &&
201 grep $(printf "\377") actual)
202'
203
df6a7ff7
PB
204test_expect_success 'import/export-marks' '
205
a881baa2 206 git checkout -b marks main &&
df6a7ff7
PB
207 git fast-export --export-marks=tmp-marks HEAD &&
208 test -s tmp-marks &&
3fb0459b 209 test_line_count = 3 tmp-marks &&
a4d4e32a
PK
210 git fast-export --import-marks=tmp-marks \
211 --export-marks=tmp-marks HEAD >actual &&
212 test $(grep ^commit actual | wc -l) -eq 0 &&
df6a7ff7
PB
213 echo change > file &&
214 git commit -m "last commit" file &&
a4d4e32a
PK
215 git fast-export --import-marks=tmp-marks \
216 --export-marks=tmp-marks HEAD >actual &&
217 test $(grep ^commit\ actual | wc -l) -eq 1 &&
3fb0459b 218 test_line_count = 4 tmp-marks
df6a7ff7 219
f2dc849e
JS
220'
221
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
d492b31c 245 test_must_fail git fast-export --signed-tags=abort sign-your-name
f2dc849e
JS
246
247'
248
ee4bc371 249test_expect_success 'signed-tags=verbatim' '
f2dc849e 250
ee4bc371 251 git fast-export --signed-tags=verbatim sign-your-name > output &&
f2dc849e
JS
252 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
cd16c59b
JK
263test_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
03db4525
AG
269test_expect_success 'setup submodule' '
270
f4a32a55 271 test_config_global protocol.file.allow always &&
a881baa2 272 git checkout -f main &&
03db4525 273 mkdir sub &&
4c367c6a
JH
274 (
275 cd sub &&
276 git init &&
277 echo test file > file &&
278 git add file &&
279 git commit -m sub_initial
280 ) &&
c7b793a1 281 git submodule add "$(pwd)/sub" sub &&
03db4525
AG
282 git commit -m initial &&
283 test_tick &&
4c367c6a
JH
284 (
285 cd sub &&
286 echo more data >> file &&
287 git add file &&
288 git commit -m sub_second
289 ) &&
03db4525
AG
290 git add sub &&
291 git commit -m second
292
293'
294
295test_expect_success 'submodule fast-export | fast-import' '
296
f4a32a55 297 test_config_global protocol.file.allow always &&
a881baa2
JS
298 SUBENT1=$(git ls-tree main^ sub) &&
299 SUBENT2=$(git ls-tree main sub) &&
03db4525
AG
300 rm -rf new &&
301 mkdir new &&
302 git --git-dir=new/.git init &&
a4d4e32a 303 git fast-export --signed-tags=strip --all >actual &&
03db4525
AG
304 (cd new &&
305 git fast-import &&
a881baa2
JS
306 test "$SUBENT1" = "$(git ls-tree refs/heads/main^ sub)" &&
307 test "$SUBENT2" = "$(git ls-tree refs/heads/main sub)" &&
308 git checkout main &&
03db4525
AG
309 git submodule init &&
310 git submodule update &&
a4d4e32a 311 cmp sub/file ../sub/file) <actual
03db4525
AG
312
313'
314
91e80b98
JH
315GIT_AUTHOR_NAME='A U Thor'; export GIT_AUTHOR_NAME
316GIT_COMMITTER_NAME='C O Mitter'; export GIT_COMMITTER_NAME
ae7c5dce
AG
317
318test_expect_success 'setup copies' '
319
ae7c5dce
AG
320 git checkout -b copy rein &&
321 git mv file file3 &&
322 git commit -m move1 &&
323 test_tick &&
324 cp file2 file4 &&
325 git add file4 &&
326 git mv file2 file5 &&
327 git commit -m copy1 &&
328 test_tick &&
329 cp file3 file6 &&
330 git add file6 &&
331 git commit -m copy2 &&
332 test_tick &&
333 echo more text >> file6 &&
334 echo even more text >> file6 &&
335 git add file6 &&
336 git commit -m modify &&
337 test_tick &&
338 cp file6 file7 &&
339 echo test >> file7 &&
340 git add file7 &&
341 git commit -m copy_modify
342
343'
344
345test_expect_success 'fast-export -C -C | fast-import' '
346
347 ENTRY=$(git rev-parse --verify copy) &&
348 rm -rf new &&
349 mkdir new &&
350 git --git-dir=new/.git init &&
351 git fast-export -C -C --signed-tags=strip --all > output &&
b3e8ca89 352 grep "^C file2 file4\$" output &&
ae7c5dce
AG
353 cat output |
354 (cd new &&
355 git fast-import &&
356 test $ENTRY = $(git rev-parse --verify refs/heads/copy))
357
358'
359
a881baa2 360test_expect_success 'fast-export | fast-import when main is tagged' '
283b9532
MV
361
362 git tag -m msg last &&
363 git fast-export -C -C --signed-tags=strip --all > output &&
364 test $(grep -c "^tag " output) = 3
365
366'
367
4e46a8d6
JS
368cat > tag-content << EOF
369object $(git rev-parse HEAD)
370type commit
371tag rosten
372EOF
373
374test_expect_success 'cope with tagger-less tags' '
375
34959d80 376 TAG=$(git hash-object --literally -t tag -w tag-content) &&
4e46a8d6
JS
377 git update-ref refs/tags/sonnenschein $TAG &&
378 git fast-export -C -C --signed-tags=strip --all > output &&
379 test $(grep -c "^tag " output) = 4 &&
380 ! grep "Unspecified Tagger" output &&
381 git fast-export -C -C --signed-tags=strip --all \
382 --fake-missing-tagger > output &&
383 test $(grep -c "^tag " output) = 4 &&
384 grep "Unspecified Tagger" output
385
386'
387
25e0ca5d
EN
388test_expect_success 'setup for limiting exports by PATH' '
389 mkdir limit-by-paths &&
4c367c6a
JH
390 (
391 cd limit-by-paths &&
392 git init &&
393 echo hi > there &&
394 git add there &&
395 git commit -m "First file" &&
396 echo foo > bar &&
397 git add bar &&
398 git commit -m "Second file" &&
399 git tag -a -m msg mytag &&
400 echo morefoo >> bar &&
401 git add bar &&
402 git commit -m "Change to second file"
403 )
25e0ca5d
EN
404'
405
406cat > limit-by-paths/expected << EOF
407blob
408mark :1
409data 3
410hi
411
412reset refs/tags/mytag
413commit refs/tags/mytag
414mark :2
415author A U Thor <author@example.com> 1112912713 -0700
416committer C O Mitter <committer@example.com> 1112912713 -0700
417data 11
418First file
419M 100644 :1 there
420
421EOF
422
423test_expect_success 'dropping tag of filtered out object' '
4c367c6a 424(
25e0ca5d
EN
425 cd limit-by-paths &&
426 git fast-export --tag-of-filtered-object=drop mytag -- there > output &&
9ff10fc8 427 test_cmp expected output
4c367c6a 428)
25e0ca5d
EN
429'
430
431cat >> limit-by-paths/expected << EOF
432tag mytag
433from :2
434tagger C O Mitter <committer@example.com> 1112912713 -0700
435data 4
436msg
437
438EOF
439
440test_expect_success 'rewriting tag of filtered out object' '
4c367c6a 441(
25e0ca5d
EN
442 cd limit-by-paths &&
443 git fast-export --tag-of-filtered-object=rewrite mytag -- there > output &&
9ff10fc8 444 test_cmp expected output
4c367c6a 445)
25e0ca5d
EN
446'
447
1f30c904
EN
448test_expect_success 'rewrite tag predating pathspecs to nothing' '
449 test_create_repo rewrite_tag_predating_pathspecs &&
450 (
451 cd rewrite_tag_predating_pathspecs &&
452
453 test_commit initial &&
454
455 git tag -a -m "Some old tag" v0.0.0.0.0.0.1 &&
456
457 test_commit bar &&
458
459 git fast-export --tag-of-filtered-object=rewrite --all -- bar.t >output &&
460 grep from.$ZERO_OID output
461 )
462'
463
25e0ca5d
EN
464cat > limit-by-paths/expected << EOF
465blob
466mark :1
467data 4
468foo
469
470blob
471mark :2
472data 3
473hi
474
a881baa2
JS
475reset refs/heads/main
476commit refs/heads/main
25e0ca5d
EN
477mark :3
478author A U Thor <author@example.com> 1112912713 -0700
479committer C O Mitter <committer@example.com> 1112912713 -0700
480data 12
481Second file
482M 100644 :1 bar
483M 100644 :2 there
484
485EOF
486
487test_expect_failure 'no exact-ref revisions included' '
4c367c6a
JH
488 (
489 cd limit-by-paths &&
a881baa2 490 git fast-export main~2..main~1 > output &&
9ff10fc8 491 test_cmp expected output
4c367c6a 492 )
25e0ca5d
EN
493'
494
4087a02e
EN
495test_expect_success 'path limiting with import-marks does not lose unmodified files' '
496 git checkout -b simple marks~2 &&
497 git fast-export --export-marks=marks simple -- file > /dev/null &&
498 echo more content >> file &&
499 test_tick &&
500 git commit -mnext file &&
a4d4e32a
PK
501 git fast-export --import-marks=marks simple -- file file0 >actual &&
502 grep file0 actual
4087a02e
EN
503'
504
d1c25272
RS
505test_expect_success 'path limiting works' '
506 git fast-export simple -- file >actual &&
507 sed -ne "s/^M .* //p" <actual | sort -u >actual.files &&
508 echo file >expect &&
509 test_cmp expect actual.files
510'
511
cd13762d
EN
512test_expect_success 'avoid corrupt stream with non-existent mark' '
513 test_create_repo avoid_non_existent_mark &&
514 (
515 cd avoid_non_existent_mark &&
516
517 test_commit important-path &&
518
519 test_commit ignored &&
520
521 git branch A &&
522 git branch B &&
523
524 echo foo >>important-path.t &&
525 git add important-path.t &&
526 test_commit more changes &&
527
528 git fast-export --all -- important-path.t | git fast-import --force
529 )
530'
531
7f40ab09
EN
532test_expect_success 'full-tree re-shows unmodified files' '
533 git checkout -f simple &&
a4d4e32a
PK
534 git fast-export --full-tree simple >actual &&
535 test $(grep -c file0 actual) -eq 3
7f40ab09
EN
536'
537
41a5c70f 538test_expect_success 'set-up a few more tags for tag export tests' '
a881baa2 539 git checkout -f main &&
c7b793a1 540 HEAD_TREE=$(git show -s --pretty=raw HEAD | grep tree | sed "s/tree //") &&
41a5c70f
EFL
541 git tag tree_tag -m "tagging a tree" $HEAD_TREE &&
542 git tag -a tree_tag-obj -m "tagging a tree" $HEAD_TREE &&
543 git tag tag-obj_tag -m "tagging a tag" tree_tag-obj &&
544 git tag -a tag-obj_tag-obj -m "tagging a tag" tree_tag-obj
545'
546
02c48cd6
EN
547test_expect_success 'tree_tag' '
548 mkdir result &&
549 (cd result && git init) &&
550 git fast-export tree_tag > fe-stream &&
551 (cd result && git fast-import < ../fe-stream)
552'
553
41a5c70f 554# NEEDSWORK: not just check return status, but validate the output
8d7d33c1 555# Note that these tests DO NOTHING other than print a warning that
7a40cf15 556# they are omitting the one tag we asked them to export (because the
8d7d33c1
EN
557# tags resolve to a tree). They exist just to make sure we do not
558# abort but instead just warn.
c0582c53 559test_expect_success 'tree_tag-obj' 'git fast-export tree_tag-obj'
1982467d
EFL
560test_expect_success 'tag-obj_tag' 'git fast-export tag-obj_tag'
561test_expect_success 'tag-obj_tag-obj' 'git fast-export tag-obj_tag-obj'
41a5c70f 562
8d7d33c1 563test_expect_success 'handling tags of blobs' '
a881baa2 564 git tag -a -m "Tag of a blob" blobtag $(git rev-parse main:file) &&
8d7d33c1
EN
565 git fast-export blobtag >actual &&
566 cat >expect <<-EOF &&
567 blob
568 mark :1
569 data 9
570 die Luft
571
572 tag blobtag
573 from :1
574 tagger $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
575 data 14
576 Tag of a blob
577
578 EOF
579 test_cmp expect actual
580'
581
941790d7 582test_expect_success 'handling nested tags' '
8d7d33c1
EN
583 git tag -a -m "This is a nested tag" nested muss &&
584 git fast-export --mark-tags nested >output &&
585 grep "^from $ZERO_OID$" output &&
586 grep "^tag nested$" output >tag_lines &&
587 test_line_count = 2 tag_lines
588'
589
889c6f0e 590test_expect_success 'directory becomes symlink' '
f15652d9
EN
591 git init dirtosymlink &&
592 git init result &&
593 (
594 cd dirtosymlink &&
595 mkdir foo &&
596 mkdir bar &&
597 echo hello > foo/world &&
598 echo hello > bar/world &&
599 git add foo/world bar/world &&
600 git commit -q -mone &&
601 git rm -r foo &&
889c6f0e 602 test_ln_s_add bar foo &&
f15652d9
EN
603 git commit -q -mtwo
604 ) &&
605 (
606 cd dirtosymlink &&
a881baa2 607 git fast-export main -- foo |
f15652d9
EN
608 (cd ../result && git fast-import --quiet)
609 ) &&
a881baa2 610 (cd result && git show main:foo)
f15652d9
EN
611'
612
6280dfdc
JK
613test_expect_success 'fast-export quotes pathnames' '
614 git init crazy-paths &&
e1d911dd 615 test_config -C crazy-paths core.protectNTFS false &&
6280dfdc 616 (cd crazy-paths &&
c7b793a1 617 blob=$(echo foo | git hash-object -w --stdin) &&
35edce20 618 git -c core.protectNTFS=false update-index --add \
6280dfdc
JK
619 --cacheinfo 100644 $blob "$(printf "path with\\nnewline")" \
620 --cacheinfo 100644 $blob "path with \"quote\"" \
621 --cacheinfo 100644 $blob "path with \\backslash" \
622 --cacheinfo 100644 $blob "path with space" &&
623 git commit -m addition &&
94221d22 624 git ls-files -z -s | perl -0pe "s{\\t}{$&subdir/}" >index &&
6280dfdc
JK
625 git read-tree --empty &&
626 git update-index -z --index-info <index &&
627 git commit -m rename &&
628 git read-tree --empty &&
629 git commit -m deletion &&
ff59f6da 630 git fast-export -M HEAD >export.out &&
6280dfdc
JK
631 git rev-list HEAD >expect &&
632 git init result &&
633 cd result &&
634 git fast-import <../export.out &&
635 git rev-list HEAD >actual &&
636 test_cmp ../expect actual
637 )
638'
639
5d3698ff 640test_expect_success 'test bidirectionality' '
5d3698ff 641 git init marks-test &&
208d6924
EN
642 git fast-export --export-marks=marks-cur --import-marks-if-exists=marks-cur --branches | \
643 git --git-dir=marks-test/.git fast-import --export-marks=marks-new --import-marks-if-exists=marks-new &&
5d3698ff
FC
644 (cd marks-test &&
645 git reset --hard &&
646 echo Wohlauf > file &&
647 git commit -a -m "back in time") &&
208d6924
EN
648 git --git-dir=marks-test/.git fast-export --export-marks=marks-new --import-marks-if-exists=marks-new --branches | \
649 git fast-import --export-marks=marks-cur --import-marks-if-exists=marks-cur
5d3698ff
FC
650'
651
49266e8a
FC
652cat > expected << EOF
653blob
654mark :13
655data 5
656bump
657
a881baa2 658commit refs/heads/main
49266e8a
FC
659mark :14
660author A U Thor <author@example.com> 1112912773 -0700
661committer C O Mitter <committer@example.com> 1112912773 -0700
662data 5
663bump
664from :12
665M 100644 :13 file
666
667EOF
668
669test_expect_success 'avoid uninteresting refs' '
670 > tmp-marks &&
671 git fast-export --import-marks=tmp-marks \
a881baa2 672 --export-marks=tmp-marks main > /dev/null &&
49266e8a
FC
673 git tag v1.0 &&
674 git branch uninteresting &&
675 echo bump > file &&
676 git commit -a -m bump &&
677 git fast-export --import-marks=tmp-marks \
a881baa2 678 --export-marks=tmp-marks ^uninteresting ^v1.0 main > actual &&
49266e8a
FC
679 test_cmp expected actual
680'
681
f28e7c90 682cat > expected << EOF
a881baa2 683reset refs/heads/main
f28e7c90
FC
684from :14
685
686EOF
687
688test_expect_success 'refs are updated even if no commits need to be exported' '
689 > tmp-marks &&
690 git fast-export --import-marks=tmp-marks \
a881baa2 691 --export-marks=tmp-marks main > /dev/null &&
f28e7c90 692 git fast-export --import-marks=tmp-marks \
a881baa2 693 --export-marks=tmp-marks main > actual &&
f28e7c90
FC
694 test_cmp expected actual
695'
696
03e9010c 697test_expect_success 'use refspec' '
a881baa2 698 git fast-export --refspec refs/heads/main:refs/heads/foobar main >actual2 &&
a4d4e32a 699 grep "^commit " actual2 | sort | uniq >actual &&
03e9010c
FC
700 echo "commit refs/heads/foobar" > expected &&
701 test_cmp expected actual
702'
703
fdf31b63 704test_expect_success 'delete ref because entire history excluded' '
60ed2643 705 git branch to-delete &&
fdf31b63
EN
706 git fast-export to-delete ^to-delete >actual &&
707 cat >expected <<-EOF &&
708 reset refs/heads/to-delete
831279d3 709 from $ZERO_OID
fdf31b63
EN
710
711 EOF
712 test_cmp expected actual
713'
714
715test_expect_success 'delete refspec' '
716 git fast-export --refspec :refs/heads/to-delete >actual &&
717 cat >expected <<-EOF &&
60ed2643 718 reset refs/heads/to-delete
831279d3 719 from $ZERO_OID
60ed2643
FC
720
721 EOF
722 test_cmp expected actual
723'
724
b3e8ca89
JT
725test_expect_success 'when using -C, do not declare copy when source of copy is also modified' '
726 test_create_repo src &&
727 echo a_line >src/file.txt &&
728 git -C src add file.txt &&
729 git -C src commit -m 1st_commit &&
730
731 cp src/file.txt src/file2.txt &&
732 echo another_line >>src/file.txt &&
733 git -C src add file.txt file2.txt &&
734 git -C src commit -m 2nd_commit &&
735
736 test_create_repo dst &&
a4d4e32a
PK
737 git -C src fast-export --all -C >actual &&
738 git -C dst fast-import <actual &&
b3e8ca89
JT
739 git -C src show >expected &&
740 git -C dst show >actual &&
741 test_cmp expected actual
742'
743
be011bbe
744test_expect_success 'merge commit gets exported with --import-marks' '
745 test_create_repo merging &&
746 (
747 cd merging &&
748 test_commit initial &&
749 git checkout -b topic &&
750 test_commit on-topic &&
a881baa2
JS
751 git checkout main &&
752 test_commit on-main &&
be011bbe
753 test_tick &&
754 git merge --no-ff -m Yeah topic &&
755
756 echo ":1 $(git rev-parse HEAD^^)" >marks &&
a881baa2 757 git fast-export --import-marks=marks main >out &&
be011bbe
758 grep Yeah out
759 )
760'
761
726a228d
WS
762
763test_expect_success 'fast-export --first-parent outputs all revisions output by revision walk' '
764 git init first-parent &&
765 (
766 cd first-parent &&
767 test_commit A &&
768 git checkout -b topic1 &&
769 test_commit B &&
770 git checkout main &&
771 git merge --no-ff topic1 &&
772
773 git checkout -b topic2 &&
774 test_commit C &&
775 git checkout main &&
776 git merge --no-ff topic2 &&
777
778 test_commit D &&
779
780 git fast-export main -- --first-parent >first-parent-export &&
781 git fast-export main -- --first-parent --reverse >first-parent-reverse-export &&
782 test_cmp first-parent-export first-parent-reverse-export &&
783
784 git init import &&
785 git -C import fast-import <first-parent-export &&
786
787 git log --format="%ad %s" --first-parent main >expected &&
788 git -C import log --format="%ad %s" --all >actual &&
789 test_cmp expected actual &&
790 test_line_count = 4 actual
791 )
792'
793
93851746
JK
794test_expect_success 'fast-export handles --end-of-options' '
795 git update-ref refs/heads/nodash HEAD &&
796 git update-ref refs/heads/--dashes HEAD &&
797 git fast-export --end-of-options nodash >expect &&
798 git fast-export --end-of-options --dashes >actual.raw &&
799 # fix up lines which mention the ref for comparison
800 sed s/--dashes/nodash/ <actual.raw >actual &&
801 test_cmp expect actual
802'
803
f2dc849e 804test_done