git-apply: Fix removal of new trailing blank lines.
[git/jnareb-git.git] / t / t9300-fast-import.sh
blob8e958da5361f69e47a27833948eed0bd7dc8b32e
1 #!/bin/sh
3 # Copyright (c) 2007 Shawn Pearce
6 test_description='test git-fast-import utility'
7 . ./test-lib.sh
8 . ../diff-lib.sh ;# test-lib chdir's into trash
10 file2_data='file2
11 second line of EOF'
13 file3_data='EOF
14 in 3rd file
15 END'
17 file4_data=abcd
18 file4_len=4
20 file5_data='an inline file.
21 we should see it later.'
23 file6_data='#!/bin/sh
24 echo "$@"'
26 ###
27 ### series A
28 ###
30 test_tick
31 cat >input <<INPUT_END
32 blob
33 mark :2
34 data <<EOF
35 $file2_data
36 EOF
38 blob
39 mark :3
40 data <<END
41 $file3_data
42 END
44 blob
45 mark :4
46 data $file4_len
47 $file4_data
48 commit refs/heads/master
49 mark :5
50 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
51 data <<COMMIT
52 initial
53 COMMIT
55 M 644 :2 file2
56 M 644 :3 file3
57 M 755 :4 file4
59 INPUT_END
60 test_expect_success \
61 'A: create pack from stdin' \
62 'git-fast-import --export-marks=marks.out <input &&
63 git-whatchanged master'
64 test_expect_success \
65 'A: verify pack' \
66 'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
68 cat >expect <<EOF
69 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
70 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
72 initial
73 EOF
74 test_expect_success \
75 'A: verify commit' \
76 'git-cat-file commit master | sed 1d >actual &&
77 git diff expect actual'
79 cat >expect <<EOF
80 100644 blob file2
81 100644 blob file3
82 100755 blob file4
83 EOF
84 test_expect_success \
85 'A: verify tree' \
86 'git-cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
87 git diff expect actual'
89 echo "$file2_data" >expect
90 test_expect_success \
91 'A: verify file2' \
92 'git-cat-file blob master:file2 >actual && git diff expect actual'
94 echo "$file3_data" >expect
95 test_expect_success \
96 'A: verify file3' \
97 'git-cat-file blob master:file3 >actual && git diff expect actual'
99 printf "$file4_data" >expect
100 test_expect_success \
101 'A: verify file4' \
102 'git-cat-file blob master:file4 >actual && git diff expect actual'
104 cat >expect <<EOF
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' \
116 'git-fast-import \
117 --import-marks=marks.out \
118 --export-marks=marks.new \
119 </dev/null &&
120 git diff -u expect marks.new'
123 ### series B
126 test_tick
127 cat >input <<INPUT_END
128 commit refs/heads/branch
129 mark :1
130 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
131 data <<COMMIT
132 corrupt
133 COMMIT
135 from refs/heads/master
136 M 755 0000000000000000000000000000000000000001 zero1
138 INPUT_END
139 test_expect_failure \
140 'B: fail on invalid blob sha1' \
141 'git-fast-import <input'
142 rm -f .git/objects/pack_* .git/objects/index_*
145 ### series C
148 newf=`echo hi newf | git-hash-object -w --stdin`
149 oldf=`git-rev-parse --verify master:file2`
150 test_tick
151 cat >input <<INPUT_END
152 commit refs/heads/branch
153 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
154 data <<COMMIT
155 second
156 COMMIT
158 from refs/heads/master
159 M 644 $oldf file2/oldf
160 M 755 $newf file2/newf
161 D file3
163 INPUT_END
164 test_expect_success \
165 'C: incremental import create pack from stdin' \
166 'git-fast-import <input &&
167 git-whatchanged branch'
168 test_expect_success \
169 'C: verify pack' \
170 'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
171 test_expect_success \
172 'C: validate reuse existing blob' \
173 'test $newf = `git-rev-parse --verify branch:file2/newf`
174 test $oldf = `git-rev-parse --verify branch:file2/oldf`'
176 cat >expect <<EOF
177 parent `git-rev-parse --verify master^0`
178 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
179 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
181 second
183 test_expect_success \
184 'C: verify commit' \
185 'git-cat-file commit branch | sed 1d >actual &&
186 git diff expect actual'
188 cat >expect <<EOF
189 :000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
190 :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
191 :100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
193 git-diff-tree -M -r master branch >actual
194 test_expect_success \
195 'C: validate rename result' \
196 'compare_diff_raw expect actual'
199 ### series D
202 test_tick
203 cat >input <<INPUT_END
204 commit refs/heads/branch
205 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
206 data <<COMMIT
207 third
208 COMMIT
210 from refs/heads/branch^0
211 M 644 inline newdir/interesting
212 data <<EOF
213 $file5_data
216 M 755 inline newdir/exec.sh
217 data <<EOF
218 $file6_data
221 INPUT_END
222 test_expect_success \
223 'D: inline data in commit' \
224 'git-fast-import <input &&
225 git-whatchanged branch'
226 test_expect_success \
227 'D: verify pack' \
228 'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
230 cat >expect <<EOF
231 :000000 100755 0000000000000000000000000000000000000000 35a59026a33beac1569b1c7f66f3090ce9c09afc A newdir/exec.sh
232 :000000 100644 0000000000000000000000000000000000000000 046d0371e9220107917db0d0e030628de8a1de9b A newdir/interesting
234 git-diff-tree -M -r branch^ branch >actual
235 test_expect_success \
236 'D: validate new files added' \
237 'compare_diff_raw expect actual'
239 echo "$file5_data" >expect
240 test_expect_success \
241 'D: verify file5' \
242 'git-cat-file blob branch:newdir/interesting >actual &&
243 git diff expect actual'
245 echo "$file6_data" >expect
246 test_expect_success \
247 'D: verify file6' \
248 'git-cat-file blob branch:newdir/exec.sh >actual &&
249 git diff expect actual'
252 ### series E
255 cat >input <<INPUT_END
256 commit refs/heads/branch
257 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> Tue Feb 6 11:22:18 2007 -0500
258 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> Tue Feb 6 12:35:02 2007 -0500
259 data <<COMMIT
260 RFC 2822 type date
261 COMMIT
263 from refs/heads/branch^0
265 INPUT_END
266 test_expect_failure \
267 'E: rfc2822 date, --date-format=raw' \
268 'git-fast-import --date-format=raw <input'
269 test_expect_success \
270 'E: rfc2822 date, --date-format=rfc2822' \
271 'git-fast-import --date-format=rfc2822 <input'
272 test_expect_success \
273 'E: verify pack' \
274 'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
276 cat >expect <<EOF
277 author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 1170778938 -0500
278 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1170783302 -0500
280 RFC 2822 type date
282 test_expect_success \
283 'E: verify commit' \
284 'git-cat-file commit branch | sed 1,2d >actual &&
285 git diff expect actual'
288 ### series F
291 old_branch=`git-rev-parse --verify branch^0`
292 test_tick
293 cat >input <<INPUT_END
294 commit refs/heads/branch
295 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
296 data <<COMMIT
297 losing things already?
298 COMMIT
300 from refs/heads/branch~1
302 reset refs/heads/other
303 from refs/heads/branch
305 INPUT_END
306 test_expect_success \
307 'F: non-fast-forward update skips' \
308 'if git-fast-import <input
309 then
310 echo BAD gfi did not fail
311 return 1
312 else
313 if test $old_branch = `git-rev-parse --verify branch^0`
314 then
315 : branch unaffected and failure returned
316 return 0
317 else
318 echo BAD gfi changed branch $old_branch
319 return 1
323 test_expect_success \
324 'F: verify pack' \
325 'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
327 cat >expect <<EOF
328 tree `git-rev-parse branch~1^{tree}`
329 parent `git-rev-parse branch~1`
330 author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
331 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
333 losing things already?
335 test_expect_success \
336 'F: verify other commit' \
337 'git-cat-file commit other >actual &&
338 git diff expect actual'
341 ### series G
344 old_branch=`git-rev-parse --verify branch^0`
345 test_tick
346 cat >input <<INPUT_END
347 commit refs/heads/branch
348 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
349 data <<COMMIT
350 losing things already?
351 COMMIT
353 from refs/heads/branch~1
355 INPUT_END
356 test_expect_success \
357 'G: non-fast-forward update forced' \
358 'git-fast-import --force <input'
359 test_expect_success \
360 'G: verify pack' \
361 'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
362 test_expect_success \
363 'G: branch changed, but logged' \
364 'test $old_branch != `git-rev-parse --verify branch^0` &&
365 test $old_branch = `git-rev-parse --verify branch@{1}`'
368 ### series H
371 test_tick
372 cat >input <<INPUT_END
373 commit refs/heads/H
374 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
375 data <<COMMIT
376 third
377 COMMIT
379 from refs/heads/branch^0
380 M 644 inline i-will-die
381 data <<EOF
382 this file will never exist.
385 deleteall
386 M 644 inline h/e/l/lo
387 data <<EOF
388 $file5_data
391 INPUT_END
392 test_expect_success \
393 'H: deletall, add 1' \
394 'git-fast-import <input &&
395 git-whatchanged H'
396 test_expect_success \
397 'H: verify pack' \
398 'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
400 cat >expect <<EOF
401 :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file2/newf
402 :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file2/oldf
403 :100755 000000 85df50785d62d3b05ab03d9cbf7e4a0b49449730 0000000000000000000000000000000000000000 D file4
404 :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting h/e/l/lo
405 :100755 000000 e74b7d465e52746be2b4bae983670711e6e66657 0000000000000000000000000000000000000000 D newdir/exec.sh
407 git-diff-tree -M -r H^ H >actual
408 test_expect_success \
409 'H: validate old files removed, new files added' \
410 'compare_diff_raw expect actual'
412 echo "$file5_data" >expect
413 test_expect_success \
414 'H: verify file' \
415 'git-cat-file blob H:h/e/l/lo >actual &&
416 git diff expect actual'
419 ### series I
422 cat >input <<INPUT_END
423 commit refs/heads/export-boundary
424 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
425 data <<COMMIT
426 we have a border. its only 40 characters wide.
427 COMMIT
429 from refs/heads/branch
431 INPUT_END
432 test_expect_success \
433 'I: export-pack-edges' \
434 'git-fast-import --export-pack-edges=edges.list <input'
436 cat >expect <<EOF
437 .git/objects/pack/pack-.pack: `git-rev-parse --verify export-boundary`
439 test_expect_success \
440 'I: verify edge list' \
441 'sed -e s/pack-.*pack/pack-.pack/ edges.list >actual &&
442 git diff expect actual'
445 ### series J
448 cat >input <<INPUT_END
449 commit refs/heads/J
450 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
451 data <<COMMIT
452 create J
453 COMMIT
455 from refs/heads/branch
457 reset refs/heads/J
459 commit refs/heads/J
460 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
461 data <<COMMIT
462 initialize J
463 COMMIT
465 INPUT_END
466 test_expect_success \
467 'J: reset existing branch creates empty commit' \
468 'git-fast-import <input'
469 test_expect_success \
470 'J: branch has 1 commit, empty tree' \
471 'test 1 = `git-rev-list J | wc -l` &&
472 test 0 = `git ls-tree J | wc -l`'
475 ### series K
478 cat >input <<INPUT_END
479 commit refs/heads/K
480 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
481 data <<COMMIT
482 create K
483 COMMIT
485 from refs/heads/branch
487 commit refs/heads/K
488 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
489 data <<COMMIT
490 redo K
491 COMMIT
493 from refs/heads/branch^1
495 INPUT_END
496 test_expect_success \
497 'K: reinit branch with from' \
498 'git-fast-import <input'
499 test_expect_success \
500 'K: verify K^1 = branch^1' \
501 'test `git-rev-parse --verify branch^1` \
502 = `git-rev-parse --verify K^1`'
505 ### series L
508 cat >input <<INPUT_END
509 blob
510 mark :1
511 data <<EOF
512 some data
515 blob
516 mark :2
517 data <<EOF
518 other data
521 commit refs/heads/L
522 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
523 data <<COMMIT
524 create L
525 COMMIT
527 M 644 :1 b.
528 M 644 :1 b/other
529 M 644 :1 ba
531 commit refs/heads/L
532 committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
533 data <<COMMIT
534 update L
535 COMMIT
537 M 644 :2 b.
538 M 644 :2 b/other
539 M 644 :2 ba
540 INPUT_END
542 cat >expect <<EXPECT_END
543 :100644 100644 4268632... 55d3a52... M b.
544 :040000 040000 0ae5cac... 443c768... M b
545 :100644 100644 4268632... 55d3a52... M ba
546 EXPECT_END
548 test_expect_success \
549 'L: verify internal tree sorting' \
550 'git-fast-import <input &&
551 git-diff --raw L^ L >output &&
552 git diff expect output'
554 test_done