Reduce value duplication in t9300-fast-import.
[git/git.git] / t / t9300-fast-import.sh
CommitLineData
50aee995
SP
1#!/bin/sh
2#
3# Copyright (c) 2007 Shawn Pearce
4#
5
6test_description='test git-fast-import utility'
7. ./test-lib.sh
8. ../diff-lib.sh ;# test-lib chdir's into trash
9
8232dc42
SP
10file2_data='file2
11second line of EOF'
12
13file3_data='EOF
14in 3rd file
15 END'
16
17file4_data=abcd
18file4_len=4
19
50aee995
SP
20###
21### series A
22###
23
24test_tick
25cat >input <<INPUT_END
26blob
27mark :2
28data <<EOF
8232dc42 29$file2_data
50aee995
SP
30EOF
31
32blob
33mark :3
34data <<END
8232dc42 35$file3_data
50aee995
SP
36END
37
38blob
39mark :4
8232dc42
SP
40data $file4_len
41$file4_data
50aee995
SP
42commit refs/heads/master
43mark :5
44committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
45data <<COMMIT
46initial
47COMMIT
48
49M 644 :2 file2
50M 644 :3 file3
51M 755 :4 file4
52
53INPUT_END
54test_expect_success \
55 'A: create pack from stdin' \
56 'git-fast-import --export-marks=marks.out <input &&
57 git-whatchanged master'
58test_expect_success \
59 'A: verify pack' \
60 'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
61
62cat >expect <<EOF
63author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
64committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
65
66initial
67EOF
68test_expect_success \
69 'A: verify commit' \
70 'git-cat-file commit master | sed 1d >actual &&
71 diff -u expect actual'
72
73cat >expect <<EOF
74100644 blob file2
75100644 blob file3
76100755 blob file4
77EOF
78test_expect_success \
79 'A: verify tree' \
80 'git-cat-file -p master^{tree} | sed "s/ [0-9a-f]* / /" >actual &&
81 diff -u expect actual'
82
8232dc42 83echo "$file2_data" >expect
50aee995
SP
84test_expect_success \
85 'A: verify file2' \
86 'git-cat-file blob master:file2 >actual && diff -u expect actual'
87
8232dc42 88echo "$file3_data" >expect
50aee995
SP
89test_expect_success \
90 'A: verify file3' \
91 'git-cat-file blob master:file3 >actual && diff -u expect actual'
92
8232dc42 93printf "$file4_data" >expect
50aee995
SP
94test_expect_success \
95 'A: verify file4' \
96 'git-cat-file blob master:file4 >actual && diff -u expect actual'
97
98cat >expect <<EOF
99:2 `git-rev-parse --verify master:file2`
100:3 `git-rev-parse --verify master:file3`
101:4 `git-rev-parse --verify master:file4`
102:5 `git-rev-parse --verify master^0`
103EOF
104test_expect_success \
105 'A: verify marks output' \
106 'diff -u expect marks.out'
107
108###
109### series B
110###
111
112test_tick
113cat >input <<INPUT_END
114commit refs/heads/branch
115mark :1
116committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
117data <<COMMIT
118corrupt
119COMMIT
120
121from refs/heads/master
122M 755 0000000000000000000000000000000000000001 zero1
123
124INPUT_END
125test_expect_failure \
126 'B: fail on invalid blob sha1' \
127 'git-fast-import <input'
128rm -f .git/objects/pack_* .git/objects/index_*
129
130###
131### series C
132###
133
134newf=`echo hi newf | git-hash-object -w --stdin`
135oldf=`git-rev-parse --verify master:file2`
136test_tick
137cat >input <<INPUT_END
138commit refs/heads/branch
139committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
140data <<COMMIT
141second
142COMMIT
143
144from refs/heads/master
145M 644 $oldf file2/oldf
146M 755 $newf file2/newf
147D file3
148
149INPUT_END
150test_expect_success \
151 'C: incremental import create pack from stdin' \
152 'git-fast-import <input &&
153 git-whatchanged branch'
154test_expect_success \
155 'C: verify pack' \
156 'for p in .git/objects/pack/*.pack;do git-verify-pack $p||exit;done'
157test_expect_success \
158 'C: validate reuse existing blob' \
159 'test $newf = `git-rev-parse --verify branch:file2/newf`
160 test $oldf = `git-rev-parse --verify branch:file2/oldf`'
161
162cat >expect <<EOF
163parent `git-rev-parse --verify master^0`
164author $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
165committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
166
167second
168EOF
169test_expect_success \
170 'C: verify commit' \
171 'git-cat-file commit branch | sed 1d >actual &&
172 diff -u expect actual'
173
174cat >expect <<EOF
175:000000 100755 0000000000000000000000000000000000000000 f1fb5da718392694d0076d677d6d0e364c79b0bc A file2/newf
176:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2 file2/oldf
177:100644 000000 0d92e9f3374ae2947c23aa477cbc68ce598135f1 0000000000000000000000000000000000000000 D file3
178EOF
179git-diff-tree -M -r master branch >actual
180test_expect_success \
181 'C: validate rename result' \
182 'compare_diff_raw expect actual'
183
184test_done