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