]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9200-git-cvsexportcommit.sh
The third batch
[thirdparty/git.git] / t / t9200-git-cvsexportcommit.sh
CommitLineData
5ab9cc86 1#!/bin/sh
fe142b3a
RR
2#
3# Copyright (c) Robin Rosenberg
4#
ab5a4231 5test_description='Test export of commits to CVS'
fe142b3a
RR
6
7. ./test-lib.sh
8
1b19ccd2 9if ! test_have_prereq PERL; then
fadb5156 10 skip_all='skipping git cvsexportcommit tests, perl not available'
1b19ccd2
JK
11 test_done
12fi
13
fe142b3a
RR
14cvs >/dev/null 2>&1
15if test $? -ne 1
16then
fadb5156 17 skip_all='skipping git cvsexportcommit tests, cvs not found'
fe142b3a 18 test_done
fe142b3a
RR
19fi
20
a78d9258
ÆAB
21if ! test_have_prereq NOT_ROOT; then
22 skip_all='When cvs is compiled with CVS_BADROOT commits as root fail'
23 test_done
24fi
25
e342acc6 26CVSROOT=$PWD/tmpcvsroot
4397c653
SS
27CVSWORK=$PWD/cvswork
28GIT_DIR=$PWD/.git
e32139aa
EW
29export CVSROOT CVSWORK GIT_DIR
30
fe142b3a 31rm -rf "$CVSROOT" "$CVSWORK"
8666df02 32
fe142b3a 33cvs init &&
8666df02 34test -d "$CVSROOT" &&
fe142b3a 35cvs -Q co -d "$CVSWORK" . &&
fe142b3a
RR
36echo >empty &&
37git add empty &&
e32139aa 38git commit -q -a -m "Initial" 2>/dev/null ||
fe142b3a
RR
39exit 1
40
c4eaed49
JH
41check_entries () {
42 # $1 == directory, $2 == expected
3b1442d5 43 sed -ne '/^\//p' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
c4eaed49
JH
44 if test -z "$2"
45 then
1c5e94f4 46 test_must_be_empty actual
c4eaed49
JH
47 else
48 printf '%s\n' "$2" | tr '|' '\012' >expected
1c5e94f4 49 test_cmp expected actual
c4eaed49 50 fi
c4eaed49
JH
51}
52
7dac6347
JC
53test_expect_success 'New file' '
54 mkdir A B C D E F &&
55 echo hello1 >A/newfile1.txt &&
56 echo hello2 >B/newfile2.txt &&
57 cp "$TEST_DIRECTORY"/test-binary-1.png C/newfile3.png &&
58 cp "$TEST_DIRECTORY"/test-binary-1.png D/newfile4.png &&
59 git add A/newfile1.txt &&
60 git add B/newfile2.txt &&
61 git add C/newfile3.png &&
62 git add D/newfile4.png &&
63 git commit -a -m "Test: New file" &&
64 id=$(git rev-list --max-count=1 HEAD) &&
65 (cd "$CVSWORK" &&
66 git cvsexportcommit -c $id &&
67 check_entries A "newfile1.txt/1.1/" &&
68 check_entries B "newfile2.txt/1.1/" &&
69 check_entries C "newfile3.png/1.1/-kb" &&
70 check_entries D "newfile4.png/1.1/-kb" &&
71 test_cmp A/newfile1.txt ../A/newfile1.txt &&
72 test_cmp B/newfile2.txt ../B/newfile2.txt &&
73 test_cmp C/newfile3.png ../C/newfile3.png &&
74 test_cmp D/newfile4.png ../D/newfile4.png
75 )
76'
fe142b3a 77
7dac6347
JC
78test_expect_success 'Remove two files, add two and update two' '
79 echo Hello1 >>A/newfile1.txt &&
80 rm -f B/newfile2.txt &&
81 rm -f C/newfile3.png &&
82 echo Hello5 >E/newfile5.txt &&
83 cp "$TEST_DIRECTORY"/test-binary-2.png D/newfile4.png &&
84 cp "$TEST_DIRECTORY"/test-binary-1.png F/newfile6.png &&
85 git add E/newfile5.txt &&
86 git add F/newfile6.png &&
87 git commit -a -m "Test: Remove, add and update" &&
88 id=$(git rev-list --max-count=1 HEAD) &&
89 (cd "$CVSWORK" &&
90 git cvsexportcommit -c $id &&
91 check_entries A "newfile1.txt/1.2/" &&
92 check_entries B "" &&
93 check_entries C "" &&
94 check_entries D "newfile4.png/1.2/-kb" &&
95 check_entries E "newfile5.txt/1.1/" &&
96 check_entries F "newfile6.png/1.1/-kb" &&
97 test_cmp A/newfile1.txt ../A/newfile1.txt &&
98 test_cmp D/newfile4.png ../D/newfile4.png &&
99 test_cmp E/newfile5.txt ../E/newfile5.txt &&
100 test_cmp F/newfile6.png ../F/newfile6.png
101 )
102'
fe142b3a 103
5190d73d 104# Should fail (but only on the git cvsexportcommit stage)
fe142b3a
RR
105test_expect_success \
106 'Fail to change binary more than one generation old' \
107 'cat F/newfile6.png >>D/newfile4.png &&
108 git commit -a -m "generatiion 1" &&
109 cat F/newfile6.png >>D/newfile4.png &&
110 git commit -a -m "generation 2" &&
111 id=$(git rev-list --max-count=1 HEAD) &&
112 (cd "$CVSWORK" &&
d492b31c 113 test_must_fail git cvsexportcommit -c $id
fe142b3a
RR
114 )'
115
e86ad71f
RR
116#test_expect_success \
117# 'Fail to remove binary file more than one generation old' \
118# 'git reset --hard HEAD^ &&
119# cat F/newfile6.png >>D/newfile4.png &&
120# git commit -a -m "generation 2 (again)" &&
121# rm -f D/newfile4.png &&
122# git commit -a -m "generation 3" &&
123# id=$(git rev-list --max-count=1 HEAD) &&
124# (cd "$CVSWORK" &&
d492b31c 125# test_must_fail git cvsexportcommit -c $id
e86ad71f 126# )'
fe142b3a
RR
127
128# We reuse the state from two tests back here
129
130# This test is here because a patch for only binary files will
131# fail with gnu patch, so cvsexportcommit must handle that.
7dac6347
JC
132test_expect_success 'Remove only binary files' '
133 git reset --hard HEAD^^ &&
134 rm -f D/newfile4.png &&
135 git commit -a -m "test: remove only a binary file" &&
136 id=$(git rev-list --max-count=1 HEAD) &&
137 (cd "$CVSWORK" &&
138 git cvsexportcommit -c $id &&
139 check_entries A "newfile1.txt/1.2/" &&
140 check_entries B "" &&
141 check_entries C "" &&
142 check_entries D "" &&
143 check_entries E "newfile5.txt/1.1/" &&
144 check_entries F "newfile6.png/1.1/-kb" &&
145 test_cmp A/newfile1.txt ../A/newfile1.txt &&
146 test_cmp E/newfile5.txt ../E/newfile5.txt &&
147 test_cmp F/newfile6.png ../F/newfile6.png
148 )
149'
fe142b3a 150
7dac6347
JC
151test_expect_success 'Remove only a text file' '
152 rm -f A/newfile1.txt &&
153 git commit -a -m "test: remove only a binary file" &&
154 id=$(git rev-list --max-count=1 HEAD) &&
155 (cd "$CVSWORK" &&
156 git cvsexportcommit -c $id &&
157 check_entries A "" &&
158 check_entries B "" &&
159 check_entries C "" &&
160 check_entries D "" &&
161 check_entries E "newfile5.txt/1.1/" &&
162 check_entries F "newfile6.png/1.1/-kb" &&
163 test_cmp E/newfile5.txt ../E/newfile5.txt &&
164 test_cmp F/newfile6.png ../F/newfile6.png
165 )
166'
fe142b3a 167
7dac6347
JC
168test_expect_success 'New file with spaces in file name' '
169 mkdir "G g" &&
170 echo ok then >"G g/with spaces.txt" &&
171 git add "G g/with spaces.txt" && \
172 cp "$TEST_DIRECTORY"/test-binary-1.png "G g/with spaces.png" && \
173 git add "G g/with spaces.png" &&
174 git commit -a -m "With spaces" &&
175 id=$(git rev-list --max-count=1 HEAD) &&
176 (cd "$CVSWORK" &&
177 git cvsexportcommit -c $id &&
178 check_entries "G g" "with spaces.png/1.1/-kb|with spaces.txt/1.1/"
179 )
180'
e86ad71f 181
7dac6347
JC
182test_expect_success 'Update file with spaces in file name' '
183 echo Ok then >>"G g/with spaces.txt" &&
184 cat "$TEST_DIRECTORY"/test-binary-1.png >>"G g/with spaces.png" && \
185 git add "G g/with spaces.png" &&
186 git commit -a -m "Update with spaces" &&
187 id=$(git rev-list --max-count=1 HEAD) &&
188 (cd "$CVSWORK" &&
189 git cvsexportcommit -c $id &&
190 check_entries "G g" "with spaces.png/1.2/-kb|with spaces.txt/1.2/"
191 )
192'
e86ad71f 193
133f0810
JH
194# Some filesystems mangle pathnames with UTF-8 characters --
195# check and skip
196if 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/å/ä/ö" &&
197 mkdir -p "tst/$p" &&
198 date >"tst/$p/day" &&
199 found=$(find tst -type f -print) &&
200 test "z$found" = "ztst/$p/day" &&
201 rm -fr tst
202then
203
1a91ebf9 204# This test contains UTF-8 characters
7dac6347
JC
205test_expect_success !MINGW 'File with non-ascii file name' '
206 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/å/ä/ö &&
207 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 &&
208 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 &&
209 cp "$TEST_DIRECTORY"/test-binary-1.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 &&
210 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 &&
211 git commit -a -m "Går det så går det" && \
212 id=$(git rev-list --max-count=1 HEAD) &&
213 (cd "$CVSWORK" &&
214 git cvsexportcommit -v -c $id &&
215 check_entries \
216 "Å/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/å/ä/ö" \
217 "gårdetsågårdet.png/1.1/-kb|gårdetsågårdet.txt/1.1/"
218 )
219'
e86ad71f 220
133f0810
JH
221fi
222
223rm -fr tst
224
7dac6347
JC
225test_expect_success 'Mismatching patch should fail' '
226 date >>"E/newfile5.txt" &&
227 git add "E/newfile5.txt" &&
228 git commit -a -m "Update one" &&
229 date >>"E/newfile5.txt" &&
230 git add "E/newfile5.txt" &&
231 git commit -a -m "Update two" &&
232 id=$(git rev-list --max-count=1 HEAD) &&
233 (cd "$CVSWORK" &&
234 test_must_fail git cvsexportcommit -c $id
235 )
236'
237
238test_expect_success FILEMODE '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" &&
247 git cvsexportcommit -c HEAD &&
248 test -x G/on &&
249 ! test -x G/off
250 )
251'
7c0f7028 252
a7237594 253test_expect_success '-w option should work with relative GIT_DIR' '
7dac6347
JC
254 mkdir W &&
255 echo foobar >W/file1.txt &&
256 echo bazzle >W/file2.txt &&
257 git add W/file1.txt &&
258 git add W/file2.txt &&
259 git commit -m "More updates" &&
260 id=$(git rev-list --max-count=1 HEAD) &&
261 (cd "$GIT_DIR" &&
262 GIT_DIR=. git cvsexportcommit -w "$CVSWORK" -c $id &&
263 check_entries "$CVSWORK/W" "file1.txt/1.1/|file2.txt/1.1/" &&
264 test_cmp "$CVSWORK/W/file1.txt" ../W/file1.txt &&
265 test_cmp "$CVSWORK/W/file2.txt" ../W/file2.txt
266 )
ab5a4231
JH
267'
268
fef3a7cc
JS
269test_expect_success 'check files before directories' '
270
271 echo Notes > release-notes &&
272 git add release-notes &&
273 git commit -m "Add release notes" release-notes &&
274 id=$(git rev-parse HEAD) &&
275 git cvsexportcommit -w "$CVSWORK" -c $id &&
276
277 echo new > DS &&
278 echo new > E/DS &&
279 echo modified > release-notes &&
280 git add DS E/DS release-notes &&
281 git commit -m "Add two files with the same basename" &&
282 id=$(git rev-parse HEAD) &&
283 git cvsexportcommit -w "$CVSWORK" -c $id &&
284 check_entries "$CVSWORK/E" "DS/1.1/|newfile5.txt/1.1/" &&
285 check_entries "$CVSWORK" "DS/1.1/|release-notes/1.2/" &&
82ebb0b6
JK
286 test_cmp "$CVSWORK/DS" DS &&
287 test_cmp "$CVSWORK/E/DS" E/DS &&
288 test_cmp "$CVSWORK/release-notes" release-notes
fef3a7cc
JS
289
290'
291
3de4a443 292test_expect_success 're-commit a removed filename which remains in CVS attic' '
7dac6347
JC
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" &&
3de4a443 304 git cvsexportcommit -w "$CVSWORK" -c HEAD &&
7dac6347
JC
305 (cd "$CVSWORK" && cvs -Q update -d) &&
306 test -f "$CVSWORK/attic_gremlin"
3de4a443
MR
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
312test_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
324test_expect_success 'use the same checkout for Git and CVS' '
325
326 (mkdir shared &&
327 cd shared &&
1f5ad6b1 328 sane_unset GIT_DIR &&
d775734c
JS
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 341test_done