3 # Copyright (c) 2007 Shawn Pearce
6 test_description
='test git-fast-import utility'
8 . ..
/diff-lib.sh
;# test-lib chdir's into trash
10 say
"git-fast-import has not been taken care of, skipping test."
24 file5_data
='an inline file.
25 we should see it later.'
35 cat >input
<<INPUT_END
52 commit refs/heads/master
54 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
65 'A: create pack from stdin' \
66 'git-fast-import --export-marks=marks.out <input &&
67 git whatchanged master'
70 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
73 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
74 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
80 'git cat-file commit master | sed 1d >actual &&
81 git diff expect actual'
90 'git cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
91 git diff expect actual'
93 echo "$file2_data" >expect
96 'git cat-file blob master:file2 >actual && git diff expect actual'
98 echo "$file3_data" >expect
101 'git cat-file blob master:file3 >actual && git diff expect actual'
103 printf "$file4_data" >expect
104 test_expect_success \
106 'git cat-file blob master:file4 >actual && git diff expect actual'
109 :2 `git rev-parse --verify master:file2`
110 :3 `git rev-parse --verify master:file3`
111 :4 `git rev-parse --verify master:file4`
112 :5 `git rev-parse --verify master^0`
114 test_expect_success \
115 'A: verify marks output' \
116 'git diff expect marks.out'
118 test_expect_success \
119 'A: verify marks import' \
121 --import-marks=marks.out \
122 --export-marks=marks.new \
124 git diff -u expect marks.new'
127 cat >input
<<INPUT_END
128 commit refs/heads/verify--import-marks
129 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
135 M 755 :2 copy-of-file2
138 test_expect_success \
139 'A: verify marks import does not crash' \
140 'git-fast-import --import-marks=marks.out <input &&
141 git whatchanged verify--import-marks'
142 test_expect_success \
144 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
146 :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2
148 git diff-tree
-M -r master verify--import-marks
>actual
149 test_expect_success \
151 'compare_diff_raw expect actual &&
152 test `git rev-parse --verify master:file2` \
153 = `git rev-parse --verify verify--import-marks:copy-of-file2`'
160 cat >input
<<INPUT_END
161 commit refs/heads/branch
163 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
168 from refs/heads/master
169 M 755 0000000000000000000000000000000000000001 zero1
172 test_expect_failure \
173 'B: fail on invalid blob sha1' \
174 'git-fast-import <input'
175 rm -f .git
/objects
/pack_
* .git
/objects
/index_
*
181 newf
=`echo hi newf | git-hash-object -w --stdin`
182 oldf
=`git rev-parse --verify master:file2`
184 cat >input
<<INPUT_END
185 commit refs/heads/branch
186 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
191 from refs/heads/master
192 M 644 $oldf file2/oldf
193 M 755 $newf file2/newf
197 test_expect_success \
198 'C: incremental import create pack from stdin' \
199 'git-fast-import <input &&
200 git whatchanged branch'
201 test_expect_success \
203 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
204 test_expect_success \
205 'C: validate reuse existing blob' \
206 'test $newf = `git rev-parse --verify branch:file2/newf`
207 test $oldf = `git rev-parse --verify branch:file2/oldf`'
210 parent `git rev-parse --verify master^0`
211 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
212 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
216 test_expect_success \
218 'git cat-file commit branch | sed 1d >actual &&
219 git diff expect actual'
222 :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
223 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
224 :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
226 git diff-tree
-M -r master branch
>actual
227 test_expect_success \
228 'C: validate rename result' \
229 'compare_diff_raw expect actual'
236 cat >input
<<INPUT_END
237 commit refs/heads/branch
238 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
243 from refs/heads/branch^0
244 M 644 inline newdir/interesting
249 M 755 inline newdir/exec.sh
255 test_expect_success \
256 'D: inline data in commit' \
257 'git-fast-import <input &&
258 git whatchanged branch'
259 test_expect_success \
261 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
264 :000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A newdir/exec.sh
265 :000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A newdir/interesting
267 git diff-tree
-M -r branch^ branch
>actual
268 test_expect_success \
269 'D: validate new files added' \
270 'compare_diff_raw expect actual'
272 echo "$file5_data" >expect
273 test_expect_success \
275 'git cat-file blob branch:newdir/interesting >actual &&
276 git diff expect actual'
278 echo "$file6_data" >expect
279 test_expect_success \
281 'git cat-file blob branch:newdir/exec.sh >actual &&
282 git diff expect actual'
288 cat >input
<<INPUT_END
289 commit refs/heads/branch
290 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
291 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
296 from refs/heads/branch^0
299 test_expect_failure \
300 'E: rfc2822 date, --date-format=raw' \
301 'git-fast-import --date-format=raw <input'
302 test_expect_success \
303 'E: rfc2822 date, --date-format=rfc2822' \
304 'git-fast-import --date-format=rfc2822 <input'
305 test_expect_success \
307 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
310 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
311 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
315 test_expect_success \
317 'git cat-file commit branch | sed 1,2d >actual &&
318 git diff expect actual'
324 old_branch
=`git rev-parse --verify branch^0`
326 cat >input
<<INPUT_END
327 commit refs/heads/branch
328 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
330 losing things already?
333 from refs/heads/branch~1
335 reset refs/heads/other
336 from refs/heads/branch
339 test_expect_success \
340 'F: non-fast-forward update skips' \
341 'if git-fast-import <input
343 echo BAD gfi did not fail
346 if test $old_branch = `git rev-parse --verify branch^0`
348 : branch unaffected and failure returned
351 echo BAD gfi changed branch $old_branch
356 test_expect_success \
358 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
361 tree `git rev-parse branch~1^{tree}`
362 parent `git rev-parse branch~1`
363 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
364 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
366 losing things already?
368 test_expect_success \
369 'F: verify other commit' \
370 'git cat-file commit other >actual &&
371 git diff expect actual'
377 old_branch
=`git rev-parse --verify branch^0`
379 cat >input
<<INPUT_END
380 commit refs/heads/branch
381 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
383 losing things already?
386 from refs/heads/branch~1
389 test_expect_success \
390 'G: non-fast-forward update forced' \
391 'git-fast-import --force <input'
392 test_expect_success \
394 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
395 test_expect_success \
396 'G: branch changed, but logged' \
397 'test $old_branch != `git rev-parse --verify branch^0` &&
398 test $old_branch = `git rev-parse --verify branch@{1}`'
405 cat >input
<<INPUT_END
407 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
412 from refs/heads/branch^0
413 M 644 inline i-will-die
415 this file will never exist.
419 M 644 inline h/e/l/lo
425 test_expect_success \
426 'H: deletall, add 1' \
427 'git-fast-import <input &&
429 test_expect_success \
431 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
434 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf
435 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf
436 :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4
437 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo
438 :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh
440 git diff-tree
-M -r H^ H
>actual
441 test_expect_success \
442 'H: validate old files removed, new files added' \
443 'compare_diff_raw expect actual'
445 echo "$file5_data" >expect
446 test_expect_success \
448 'git cat-file blob H:h/e/l/lo >actual &&
449 git diff expect actual'
455 cat >input
<<INPUT_END
456 commit refs/heads/export-boundary
457 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
459 we have a border. its only 40 characters wide.
462 from refs/heads/branch
465 test_expect_success \
466 'I: export-pack-edges' \
467 'git-fast-import --export-pack-edges=edges.list <input'
470 .git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
472 test_expect_success \
473 'I: verify edge list' \
474 'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
475 git diff expect actual'
481 cat >input
<<INPUT_END
483 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
488 from refs/heads/branch
493 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
499 test_expect_success \
500 'J: reset existing branch creates empty commit' \
501 'git-fast-import <input'
502 test_expect_success \
503 'J: branch has 1 commit, empty tree' \
504 'test 1 = `git rev-list J | wc -l` &&
505 test 0 = `git ls-tree J | wc -l`'
511 cat >input
<<INPUT_END
513 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
518 from refs/heads/branch
521 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
526 from refs/heads/branch^1
529 test_expect_success \
530 'K: reinit branch with from' \
531 'git-fast-import <input'
532 test_expect_success \
533 'K: verify K^1 = branch^1' \
534 'test `git rev-parse --verify branch^1` \
535 = `git rev-parse --verify K^1`'
541 cat >input
<<INPUT_END
555 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
565 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
575 cat >expect
<<EXPECT_END
576 :100644 100644 4268632... 55d3a52... M b.
577 :040000 040000 0ae5cac... 443c768... M b
578 :100644 100644 4268632... 55d3a52... M ba
581 test_expect_success \
582 'L: verify internal tree sorting' \
583 'git-fast-import <input &&
584 git diff --raw L^ L >output &&
585 git diff expect output'
592 cat >input
<<INPUT_END
594 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
599 from refs/heads/branch^0
600 R file2/newf file2/n.e.w.f
605 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f
607 test_expect_success \
608 'M: rename file in same subdirectory' \
609 'git-fast-import <input &&
610 git diff-tree -M -r M1^ M1 >actual &&
611 compare_diff_raw expect actual'
613 cat >input
<<INPUT_END
615 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
620 from refs/heads/branch^0
621 R file2/newf i/am/new/to/you
626 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you
628 test_expect_success \
629 'M: rename file to new subdirectory' \
630 'git-fast-import <input &&
631 git diff-tree -M -r M2^ M2 >actual &&
632 compare_diff_raw expect actual'
634 cat >input
<<INPUT_END
636 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
647 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you
649 test_expect_success \
650 'M: rename subdirectory to new subdirectory' \
651 'git-fast-import <input &&
652 git diff-tree -M -r M3^ M3 >actual &&
653 compare_diff_raw expect actual'
660 cat >input
<<INPUT_END
662 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
667 from refs/heads/branch^0
668 C file2/newf file2/n.e.w.f
673 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f
675 test_expect_success \
676 'N: copy file in same subdirectory' \
677 'git-fast-import <input &&
678 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
679 compare_diff_raw expect actual'
681 cat >input
<<INPUT_END
683 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
688 from refs/heads/branch^0
692 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
694 modify directory copy
697 M 644 inline file3/file5
705 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
706 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
707 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
709 test_expect_success \
710 'N: copy then modify subdirectory' \
711 'git-fast-import <input &&
712 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
713 compare_diff_raw expect actual'
715 cat >input
<<INPUT_END
717 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
722 from refs/heads/branch^0
723 M 644 inline file2/file5
733 test_expect_success \
734 'N: copy dirty subdirectory' \
735 'git-fast-import <input &&
736 test `git-rev-parse N2^{tree}` = `git-rev-parse N3^{tree}`'