3 # Copyright (c) 2007 Shawn Pearce
6 test_description
='test git-fast-import utility'
8 . ..
/diff-lib.sh
;# test-lib chdir's into trash
20 file5_data
='an inline file.
21 we should see it later.'
31 cat >input
<<INPUT_END
48 commit refs/heads/master
50 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
61 'A: create pack from stdin' \
62 'git-fast-import --export-marks=marks.out <input &&
63 git whatchanged master'
66 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
69 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
70 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
76 'git cat-file commit master | sed 1d >actual &&
77 git diff expect actual'
86 'git cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
87 git diff expect actual'
89 echo "$file2_data" >expect
92 'git cat-file blob master:file2 >actual && git diff expect actual'
94 echo "$file3_data" >expect
97 'git cat-file blob master:file3 >actual && git diff expect actual'
99 printf "$file4_data" >expect
100 test_expect_success \
102 'git cat-file blob master:file4 >actual && git diff expect actual'
105 :2 `git rev-parse --verify master:file2`
106 :3 `git rev-parse --verify master:file3`
107 :4 `git rev-parse --verify master:file4`
108 :5 `git rev-parse --verify master^0`
110 test_expect_success \
111 'A: verify marks output' \
112 'git diff expect marks.out'
114 test_expect_success \
115 'A: verify marks import' \
117 --import-marks=marks.out \
118 --export-marks=marks.new \
120 git diff -u expect marks.new'
123 cat >input
<<INPUT_END
124 commit refs/heads/verify--import-marks
125 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
131 M 755 :2 copy-of-file2
134 test_expect_success \
135 'A: verify marks import does not crash' \
136 'git-fast-import --import-marks=marks.out <input &&
137 git whatchanged verify--import-marks'
138 test_expect_success \
140 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
142 :000000 100755 0000000000000000000000000000000000000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 A copy-of-file2
144 git diff-tree
-M -r master verify--import-marks
>actual
145 test_expect_success \
147 'compare_diff_raw expect actual &&
148 test `git rev-parse --verify master:file2` \
149 = `git rev-parse --verify verify--import-marks:copy-of-file2`'
156 cat >input
<<INPUT_END
157 commit refs/heads/branch
159 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
164 from refs/heads/master
165 M 755 0000000000000000000000000000000000000001 zero1
168 test_expect_failure \
169 'B: fail on invalid blob sha1' \
170 'git-fast-import <input'
171 rm -f .git
/objects
/pack_
* .git
/objects
/index_
*
177 newf
=`echo hi newf | git-hash-object -w --stdin`
178 oldf
=`git rev-parse --verify master:file2`
180 cat >input
<<INPUT_END
181 commit refs/heads/branch
182 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
187 from refs/heads/master
188 M 644 $oldf file2/oldf
189 M 755 $newf file2/newf
193 test_expect_success \
194 'C: incremental import create pack from stdin' \
195 'git-fast-import <input &&
196 git whatchanged branch'
197 test_expect_success \
199 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
200 test_expect_success \
201 'C: validate reuse existing blob' \
202 'test $newf = `git rev-parse --verify branch:file2/newf`
203 test $oldf = `git rev-parse --verify branch:file2/oldf`'
206 parent `git rev-parse --verify master^0`
207 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
208 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
212 test_expect_success \
214 'git cat-file commit branch | sed 1d >actual &&
215 git diff expect actual'
218 :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
219 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
220 :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
222 git diff-tree
-M -r master branch
>actual
223 test_expect_success \
224 'C: validate rename result' \
225 'compare_diff_raw expect actual'
232 cat >input
<<INPUT_END
233 commit refs/heads/branch
234 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
239 from refs/heads/branch^0
240 M 644 inline newdir/interesting
245 M 755 inline newdir/exec.sh
251 test_expect_success \
252 'D: inline data in commit' \
253 'git-fast-import <input &&
254 git whatchanged branch'
255 test_expect_success \
257 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
260 :000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A newdir/exec.sh
261 :000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A newdir/interesting
263 git diff-tree
-M -r branch^ branch
>actual
264 test_expect_success \
265 'D: validate new files added' \
266 'compare_diff_raw expect actual'
268 echo "$file5_data" >expect
269 test_expect_success \
271 'git cat-file blob branch:newdir/interesting >actual &&
272 git diff expect actual'
274 echo "$file6_data" >expect
275 test_expect_success \
277 'git cat-file blob branch:newdir/exec.sh >actual &&
278 git diff expect actual'
284 cat >input
<<INPUT_END
285 commit refs/heads/branch
286 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
287 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
292 from refs/heads/branch^0
295 test_expect_failure \
296 'E: rfc2822 date, --date-format=raw' \
297 'git-fast-import --date-format=raw <input'
298 test_expect_success \
299 'E: rfc2822 date, --date-format=rfc2822' \
300 'git-fast-import --date-format=rfc2822 <input'
301 test_expect_success \
303 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
306 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
307 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
311 test_expect_success \
313 'git cat-file commit branch | sed 1,2d >actual &&
314 git diff expect actual'
320 old_branch
=`git rev-parse --verify branch^0`
322 cat >input
<<INPUT_END
323 commit refs/heads/branch
324 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
326 losing things already?
329 from refs/heads/branch~1
331 reset refs/heads/other
332 from refs/heads/branch
335 test_expect_success \
336 'F: non-fast-forward update skips' \
337 'if git-fast-import <input
339 echo BAD gfi did not fail
342 if test $old_branch = `git rev-parse --verify branch^0`
344 : branch unaffected and failure returned
347 echo BAD gfi changed branch $old_branch
352 test_expect_success \
354 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
357 tree `git rev-parse branch~1^{tree}`
358 parent `git rev-parse branch~1`
359 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
360 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
362 losing things already?
364 test_expect_success \
365 'F: verify other commit' \
366 'git cat-file commit other >actual &&
367 git diff expect actual'
373 old_branch
=`git rev-parse --verify branch^0`
375 cat >input
<<INPUT_END
376 commit refs/heads/branch
377 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
379 losing things already?
382 from refs/heads/branch~1
385 test_expect_success \
386 'G: non-fast-forward update forced' \
387 'git-fast-import --force <input'
388 test_expect_success \
390 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
391 test_expect_success \
392 'G: branch changed, but logged' \
393 'test $old_branch != `git rev-parse --verify branch^0` &&
394 test $old_branch = `git rev-parse --verify branch@{1}`'
401 cat >input
<<INPUT_END
403 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
408 from refs/heads/branch^0
409 M 644 inline i-will-die
411 this file will never exist.
415 M 644 inline h/e/l/lo
421 test_expect_success \
422 'H: deletall, add 1' \
423 'git-fast-import <input &&
425 test_expect_success \
427 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done'
430 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf
431 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf
432 :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4
433 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo
434 :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh
436 git diff-tree
-M -r H^ H
>actual
437 test_expect_success \
438 'H: validate old files removed, new files added' \
439 'compare_diff_raw expect actual'
441 echo "$file5_data" >expect
442 test_expect_success \
444 'git cat-file blob H:h/e/l/lo >actual &&
445 git diff expect actual'
451 cat >input
<<INPUT_END
452 commit refs/heads/export-boundary
453 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
455 we have a border. its only 40 characters wide.
458 from refs/heads/branch
461 test_expect_success \
462 'I: export-pack-edges' \
463 'git-fast-import --export-pack-edges=edges.list <input'
466 .git/objects/pack/pack-.pack: `git rev-parse --verify export-boundary`
468 test_expect_success \
469 'I: verify edge list' \
470 'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
471 git diff expect actual'
477 cat >input
<<INPUT_END
479 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
484 from refs/heads/branch
489 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
495 test_expect_success \
496 'J: reset existing branch creates empty commit' \
497 'git-fast-import <input'
498 test_expect_success \
499 'J: branch has 1 commit, empty tree' \
500 'test 1 = `git rev-list J | wc -l` &&
501 test 0 = `git ls-tree J | wc -l`'
507 cat >input
<<INPUT_END
509 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
514 from refs/heads/branch
517 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
522 from refs/heads/branch^1
525 test_expect_success \
526 'K: reinit branch with from' \
527 'git-fast-import <input'
528 test_expect_success \
529 'K: verify K^1 = branch^1' \
530 'test `git rev-parse --verify branch^1` \
531 = `git rev-parse --verify K^1`'
537 cat >input
<<INPUT_END
551 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
561 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
571 cat >expect
<<EXPECT_END
572 :100644 100644 4268632... 55d3a52... M b.
573 :040000 040000 0ae5cac... 443c768... M b
574 :100644 100644 4268632... 55d3a52... M ba
577 test_expect_success \
578 'L: verify internal tree sorting' \
579 'git-fast-import <input &&
580 git diff --raw L^ L >output &&
581 git diff expect output'
588 cat >input
<<INPUT_END
590 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
595 from refs/heads/branch^0
596 R file2/newf file2/n.e.w.f
601 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf file2/n.e.w.f
603 test_expect_success \
604 'M: rename file in same subdirectory' \
605 'git-fast-import <input &&
606 git diff-tree -M -r M1^ M1 >actual &&
607 compare_diff_raw expect actual'
609 cat >input
<<INPUT_END
611 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
616 from refs/heads/branch^0
617 R file2/newf i/am/new/to/you
622 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 file2/newf i/am/new/to/you
624 test_expect_success \
625 'M: rename file to new subdirectory' \
626 'git-fast-import <input &&
627 git diff-tree -M -r M2^ M2 >actual &&
628 compare_diff_raw expect actual'
630 cat >input
<<INPUT_END
632 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
643 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you other/sub/am/new/to/you
645 test_expect_success \
646 'M: rename subdirectory to new subdirectory' \
647 'git-fast-import <input &&
648 git diff-tree -M -r M3^ M3 >actual &&
649 compare_diff_raw expect actual'
656 cat >input
<<INPUT_END
658 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
663 from refs/heads/branch^0
664 C file2/newf file2/n.e.w.f
669 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file2/n.e.w.f
671 test_expect_success \
672 'N: copy file in same subdirectory' \
673 'git-fast-import <input &&
674 git diff-tree -C --find-copies-harder -r N1^ N1 >actual &&
675 compare_diff_raw expect actual'
677 cat >input
<<INPUT_END
679 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
684 from refs/heads/branch^0
688 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
690 modify directory copy
693 M 644 inline file3/file5
701 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting file3/file5
702 :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf
703 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf
705 test_expect_success \
706 'N: copy then modify subdirectory' \
707 'git-fast-import <input &&
708 git diff-tree -C --find-copies-harder -r N2^^ N2 >actual &&
709 compare_diff_raw expect actual'
711 cat >input
<<INPUT_END
713 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
718 from refs/heads/branch^0
719 M 644 inline file2/file5
729 test_expect_success \
730 'N: copy dirty subdirectory' \
731 'git-fast-import <input &&
732 test `git-rev-parse N2^{tree}` = `git-rev-parse N3^{tree}`'