]>
Commit | Line | Data |
---|---|---|
5ab9cc86 | 1 | #!/bin/sh |
fe142b3a RR |
2 | # |
3 | # Copyright (c) Robin Rosenberg | |
4 | # | |
ab5a4231 | 5 | test_description='Test export of commits to CVS' |
fe142b3a RR |
6 | |
7 | . ./test-lib.sh | |
535d9742 | 8 | . "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh |
fe142b3a | 9 | |
1b19ccd2 | 10 | if ! test_have_prereq PERL; then |
fadb5156 | 11 | skip_all='skipping git cvsexportcommit tests, perl not available' |
1b19ccd2 JK |
12 | test_done |
13 | fi | |
14 | ||
fe142b3a RR |
15 | cvs >/dev/null 2>&1 |
16 | if test $? -ne 1 | |
17 | then | |
fadb5156 | 18 | skip_all='skipping git cvsexportcommit tests, cvs not found' |
fe142b3a | 19 | test_done |
fe142b3a RR |
20 | fi |
21 | ||
e32139aa EW |
22 | CVSROOT=$(pwd)/cvsroot |
23 | CVSWORK=$(pwd)/cvswork | |
24 | GIT_DIR=$(pwd)/.git | |
25 | export CVSROOT CVSWORK GIT_DIR | |
26 | ||
fe142b3a RR |
27 | rm -rf "$CVSROOT" "$CVSWORK" |
28 | mkdir "$CVSROOT" && | |
29 | cvs init && | |
30 | cvs -Q co -d "$CVSWORK" . && | |
fe142b3a RR |
31 | echo >empty && |
32 | git add empty && | |
e32139aa | 33 | git commit -q -a -m "Initial" 2>/dev/null || |
fe142b3a RR |
34 | exit 1 |
35 | ||
c4eaed49 JH |
36 | check_entries () { |
37 | # $1 == directory, $2 == expected | |
38 | grep '^/' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual | |
39 | if test -z "$2" | |
40 | then | |
41 | >expected | |
42 | else | |
43 | printf '%s\n' "$2" | tr '|' '\012' >expected | |
44 | fi | |
82ebb0b6 | 45 | test_cmp expected actual |
c4eaed49 JH |
46 | } |
47 | ||
fe142b3a RR |
48 | test_expect_success \ |
49 | 'New file' \ | |
50 | 'mkdir A B C D E F && | |
51 | echo hello1 >A/newfile1.txt && | |
52 | echo hello2 >B/newfile2.txt && | |
bfdbee98 JH |
53 | cp "$TEST_DIRECTORY"/test9200a.png C/newfile3.png && |
54 | cp "$TEST_DIRECTORY"/test9200a.png D/newfile4.png && | |
fe142b3a RR |
55 | git add A/newfile1.txt && |
56 | git add B/newfile2.txt && | |
57 | git add C/newfile3.png && | |
58 | git add D/newfile4.png && | |
59 | git commit -a -m "Test: New file" && | |
60 | id=$(git rev-list --max-count=1 HEAD) && | |
61 | (cd "$CVSWORK" && | |
62 | git cvsexportcommit -c $id && | |
c4eaed49 JH |
63 | check_entries A "newfile1.txt/1.1/" && |
64 | check_entries B "newfile2.txt/1.1/" && | |
65 | check_entries C "newfile3.png/1.1/-kb" && | |
66 | check_entries D "newfile4.png/1.1/-kb" && | |
4fdf71be GV |
67 | test_cmp A/newfile1.txt ../A/newfile1.txt && |
68 | test_cmp B/newfile2.txt ../B/newfile2.txt && | |
69 | test_cmp C/newfile3.png ../C/newfile3.png && | |
70 | test_cmp D/newfile4.png ../D/newfile4.png | |
fe142b3a RR |
71 | )' |
72 | ||
73 | test_expect_success \ | |
74 | 'Remove two files, add two and update two' \ | |
75 | 'echo Hello1 >>A/newfile1.txt && | |
76 | rm -f B/newfile2.txt && | |
77 | rm -f C/newfile3.png && | |
78 | echo Hello5 >E/newfile5.txt && | |
bfdbee98 JH |
79 | cp "$TEST_DIRECTORY"/test9200b.png D/newfile4.png && |
80 | cp "$TEST_DIRECTORY"/test9200a.png F/newfile6.png && | |
fe142b3a RR |
81 | git add E/newfile5.txt && |
82 | git add F/newfile6.png && | |
83 | git commit -a -m "Test: Remove, add and update" && | |
84 | id=$(git rev-list --max-count=1 HEAD) && | |
85 | (cd "$CVSWORK" && | |
86 | git cvsexportcommit -c $id && | |
c4eaed49 JH |
87 | check_entries A "newfile1.txt/1.2/" && |
88 | check_entries B "" && | |
89 | check_entries C "" && | |
90 | check_entries D "newfile4.png/1.2/-kb" && | |
91 | check_entries E "newfile5.txt/1.1/" && | |
92 | check_entries F "newfile6.png/1.1/-kb" && | |
4fdf71be GV |
93 | test_cmp A/newfile1.txt ../A/newfile1.txt && |
94 | test_cmp D/newfile4.png ../D/newfile4.png && | |
95 | test_cmp E/newfile5.txt ../E/newfile5.txt && | |
96 | test_cmp F/newfile6.png ../F/newfile6.png | |
fe142b3a RR |
97 | )' |
98 | ||
5190d73d | 99 | # Should fail (but only on the git cvsexportcommit stage) |
fe142b3a RR |
100 | test_expect_success \ |
101 | 'Fail to change binary more than one generation old' \ | |
102 | 'cat F/newfile6.png >>D/newfile4.png && | |
103 | git commit -a -m "generatiion 1" && | |
104 | cat F/newfile6.png >>D/newfile4.png && | |
105 | git commit -a -m "generation 2" && | |
106 | id=$(git rev-list --max-count=1 HEAD) && | |
107 | (cd "$CVSWORK" && | |
d492b31c | 108 | test_must_fail git cvsexportcommit -c $id |
fe142b3a RR |
109 | )' |
110 | ||
e86ad71f RR |
111 | #test_expect_success \ |
112 | # 'Fail to remove binary file more than one generation old' \ | |
113 | # 'git reset --hard HEAD^ && | |
114 | # cat F/newfile6.png >>D/newfile4.png && | |
115 | # git commit -a -m "generation 2 (again)" && | |
116 | # rm -f D/newfile4.png && | |
117 | # git commit -a -m "generation 3" && | |
118 | # id=$(git rev-list --max-count=1 HEAD) && | |
119 | # (cd "$CVSWORK" && | |
d492b31c | 120 | # test_must_fail git cvsexportcommit -c $id |
e86ad71f | 121 | # )' |
fe142b3a RR |
122 | |
123 | # We reuse the state from two tests back here | |
124 | ||
125 | # This test is here because a patch for only binary files will | |
126 | # fail with gnu patch, so cvsexportcommit must handle that. | |
127 | test_expect_success \ | |
128 | 'Remove only binary files' \ | |
e86ad71f | 129 | 'git reset --hard HEAD^^ && |
fe142b3a RR |
130 | rm -f D/newfile4.png && |
131 | git commit -a -m "test: remove only a binary file" && | |
132 | id=$(git rev-list --max-count=1 HEAD) && | |
133 | (cd "$CVSWORK" && | |
134 | git cvsexportcommit -c $id && | |
c4eaed49 JH |
135 | check_entries A "newfile1.txt/1.2/" && |
136 | check_entries B "" && | |
137 | check_entries C "" && | |
138 | check_entries D "" && | |
139 | check_entries E "newfile5.txt/1.1/" && | |
140 | check_entries F "newfile6.png/1.1/-kb" && | |
4fdf71be GV |
141 | test_cmp A/newfile1.txt ../A/newfile1.txt && |
142 | test_cmp E/newfile5.txt ../E/newfile5.txt && | |
143 | test_cmp F/newfile6.png ../F/newfile6.png | |
fe142b3a RR |
144 | )' |
145 | ||
146 | test_expect_success \ | |
147 | 'Remove only a text file' \ | |
148 | 'rm -f A/newfile1.txt && | |
149 | git commit -a -m "test: remove only a binary file" && | |
150 | id=$(git rev-list --max-count=1 HEAD) && | |
151 | (cd "$CVSWORK" && | |
152 | git cvsexportcommit -c $id && | |
c4eaed49 JH |
153 | check_entries A "" && |
154 | check_entries B "" && | |
155 | check_entries C "" && | |
156 | check_entries D "" && | |
157 | check_entries E "newfile5.txt/1.1/" && | |
158 | check_entries F "newfile6.png/1.1/-kb" && | |
4fdf71be GV |
159 | test_cmp E/newfile5.txt ../E/newfile5.txt && |
160 | test_cmp F/newfile6.png ../F/newfile6.png | |
fe142b3a RR |
161 | )' |
162 | ||
e86ad71f RR |
163 | test_expect_success \ |
164 | 'New file with spaces in file name' \ | |
165 | 'mkdir "G g" && | |
166 | echo ok then >"G g/with spaces.txt" && | |
167 | git add "G g/with spaces.txt" && \ | |
bfdbee98 | 168 | cp "$TEST_DIRECTORY"/test9200a.png "G g/with spaces.png" && \ |
e86ad71f RR |
169 | git add "G g/with spaces.png" && |
170 | git commit -a -m "With spaces" && | |
171 | id=$(git rev-list --max-count=1 HEAD) && | |
172 | (cd "$CVSWORK" && | |
5190d73d | 173 | git cvsexportcommit -c $id && |
c4eaed49 | 174 | check_entries "G g" "with spaces.png/1.1/-kb|with spaces.txt/1.1/" |
e86ad71f RR |
175 | )' |
176 | ||
177 | test_expect_success \ | |
178 | 'Update file with spaces in file name' \ | |
179 | 'echo Ok then >>"G g/with spaces.txt" && | |
bfdbee98 | 180 | cat "$TEST_DIRECTORY"/test9200a.png >>"G g/with spaces.png" && \ |
e86ad71f RR |
181 | git add "G g/with spaces.png" && |
182 | git commit -a -m "Update with spaces" && | |
183 | id=$(git rev-list --max-count=1 HEAD) && | |
184 | (cd "$CVSWORK" && | |
5190d73d | 185 | git cvsexportcommit -c $id |
c4eaed49 | 186 | check_entries "G g" "with spaces.png/1.2/-kb|with spaces.txt/1.2/" |
e86ad71f RR |
187 | )' |
188 | ||
133f0810 JH |
189 | # Some filesystems mangle pathnames with UTF-8 characters -- |
190 | # check and skip | |
191 | if p="Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö" && | |
192 | mkdir -p "tst/$p" && | |
193 | date >"tst/$p/day" && | |
194 | found=$(find tst -type f -print) && | |
195 | test "z$found" = "ztst/$p/day" && | |
196 | rm -fr tst | |
197 | then | |
198 | ||
1a91ebf9 | 199 | # This test contains UTF-8 characters |
e86ad71f RR |
200 | test_expect_success \ |
201 | 'File with non-ascii file name' \ | |
1a91ebf9 JH |
202 | 'mkdir -p Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö && |
203 | echo Foo >Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.txt && | |
204 | git add Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.txt && | |
bfdbee98 | 205 | cp "$TEST_DIRECTORY"/test9200a.png Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.png && |
1a91ebf9 JH |
206 | git add Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.png && |
207 | git commit -a -m "Går det så går det" && \ | |
e86ad71f RR |
208 | id=$(git rev-list --max-count=1 HEAD) && |
209 | (cd "$CVSWORK" && | |
5190d73d | 210 | git cvsexportcommit -v -c $id && |
c4eaed49 JH |
211 | check_entries \ |
212 | "Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö" \ | |
213 | "gårdetsågårdet.png/1.1/-kb|gårdetsågårdet.txt/1.1/" | |
e86ad71f RR |
214 | )' |
215 | ||
133f0810 JH |
216 | fi |
217 | ||
218 | rm -fr tst | |
219 | ||
e86ad71f RR |
220 | test_expect_success \ |
221 | 'Mismatching patch should fail' \ | |
222 | 'date >>"E/newfile5.txt" && | |
223 | git add "E/newfile5.txt" && | |
224 | git commit -a -m "Update one" && | |
225 | date >>"E/newfile5.txt" && | |
226 | git add "E/newfile5.txt" && | |
227 | git commit -a -m "Update two" && | |
228 | id=$(git rev-list --max-count=1 HEAD) && | |
229 | (cd "$CVSWORK" && | |
5190d73d | 230 | test_must_fail git cvsexportcommit -c $id |
e86ad71f RR |
231 | )' |
232 | ||
872f349e | 233 | test_expect_success FILEMODE \ |
e86ad71f RR |
234 | 'Retain execute bit' \ |
235 | 'mkdir G && | |
236 | echo executeon >G/on && | |
237 | chmod +x G/on && | |
238 | echo executeoff >G/off && | |
239 | git add G/on && | |
240 | git add G/off && | |
241 | git commit -a -m "Execute test" && | |
242 | (cd "$CVSWORK" && | |
5190d73d | 243 | git cvsexportcommit -c HEAD |
e86ad71f RR |
244 | test -x G/on && |
245 | ! test -x G/off | |
246 | )' | |
7c0f7028 | 247 | |
a7237594 | 248 | test_expect_success '-w option should work with relative GIT_DIR' ' |
ab5a4231 JH |
249 | mkdir W && |
250 | echo foobar >W/file1.txt && | |
251 | echo bazzle >W/file2.txt && | |
252 | git add W/file1.txt && | |
253 | git add W/file2.txt && | |
254 | git commit -m "More updates" && | |
255 | id=$(git rev-list --max-count=1 HEAD) && | |
256 | (cd "$GIT_DIR" && | |
257 | GIT_DIR=. git cvsexportcommit -w "$CVSWORK" -c $id && | |
258 | check_entries "$CVSWORK/W" "file1.txt/1.1/|file2.txt/1.1/" && | |
82ebb0b6 JK |
259 | test_cmp "$CVSWORK/W/file1.txt" ../W/file1.txt && |
260 | test_cmp "$CVSWORK/W/file2.txt" ../W/file2.txt | |
ab5a4231 JH |
261 | ) |
262 | ' | |
263 | ||
fef3a7cc JS |
264 | test_expect_success 'check files before directories' ' |
265 | ||
266 | echo Notes > release-notes && | |
267 | git add release-notes && | |
268 | git commit -m "Add release notes" release-notes && | |
269 | id=$(git rev-parse HEAD) && | |
270 | git cvsexportcommit -w "$CVSWORK" -c $id && | |
271 | ||
272 | echo new > DS && | |
273 | echo new > E/DS && | |
274 | echo modified > release-notes && | |
275 | git add DS E/DS release-notes && | |
276 | git commit -m "Add two files with the same basename" && | |
277 | id=$(git rev-parse HEAD) && | |
278 | git cvsexportcommit -w "$CVSWORK" -c $id && | |
279 | check_entries "$CVSWORK/E" "DS/1.1/|newfile5.txt/1.1/" && | |
280 | check_entries "$CVSWORK" "DS/1.1/|release-notes/1.2/" && | |
82ebb0b6 JK |
281 | test_cmp "$CVSWORK/DS" DS && |
282 | test_cmp "$CVSWORK/E/DS" E/DS && | |
283 | test_cmp "$CVSWORK/release-notes" release-notes | |
fef3a7cc JS |
284 | |
285 | ' | |
286 | ||
3de4a443 MR |
287 | test_expect_success 're-commit a removed filename which remains in CVS attic' ' |
288 | ||
289 | (cd "$CVSWORK" && | |
290 | echo >attic_gremlin && | |
291 | cvs -Q add attic_gremlin && | |
292 | cvs -Q ci -m "added attic_gremlin" && | |
293 | rm attic_gremlin && | |
294 | cvs -Q rm attic_gremlin && | |
295 | cvs -Q ci -m "removed attic_gremlin") && | |
296 | ||
297 | echo > attic_gremlin && | |
298 | git add attic_gremlin && | |
299 | git commit -m "Added attic_gremlin" && | |
300 | git cvsexportcommit -w "$CVSWORK" -c HEAD && | |
301 | (cd "$CVSWORK"; cvs -Q update -d) && | |
302 | test -f "$CVSWORK/attic_gremlin" | |
303 | ' | |
304 | ||
305 | # the state of the CVS sandbox may be indeterminate for ' space' | |
306 | # after this test on some platforms / with some versions of CVS | |
307 | # consider adding new tests above this point | |
fef3a7cc JS |
308 | test_expect_success 'commit a file with leading spaces in the name' ' |
309 | ||
310 | echo space > " space" && | |
311 | git add " space" && | |
312 | git commit -m "Add a file with a leading space" && | |
313 | id=$(git rev-parse HEAD) && | |
314 | git cvsexportcommit -w "$CVSWORK" -c $id && | |
3de4a443 | 315 | check_entries "$CVSWORK" " space/1.1/|DS/1.1/|attic_gremlin/1.3/|release-notes/1.2/" && |
82ebb0b6 | 316 | test_cmp "$CVSWORK/ space" " space" |
fef3a7cc JS |
317 | |
318 | ' | |
319 | ||
d775734c JS |
320 | test_expect_success 'use the same checkout for Git and CVS' ' |
321 | ||
322 | (mkdir shared && | |
323 | cd shared && | |
324 | unset GIT_DIR && | |
325 | cvs co . && | |
326 | git init && | |
327 | git add " space" && | |
328 | git commit -m "fake initial commit" && | |
329 | echo Hello >> " space" && | |
330 | git commit -m "Another change" " space" && | |
331 | git cvsexportcommit -W -p -u -c HEAD && | |
332 | grep Hello " space" && | |
333 | git diff-files) | |
334 | ||
335 | ' | |
336 | ||
fe142b3a | 337 | test_done |