Merge commit 'v1.6.3.2' into devel
[4msysgit-hv.git] / t / t9200-git-cvsexportcommit.sh
blob229662e8651d3c40838c03d954270e887e061271
1 #!/bin/sh
3 # Copyright (c) Robin Rosenberg
5 test_description='Test export of commits to CVS'
7 . ./test-lib.sh
9 say "CVS does not work on MinGW, skipping tests."
10 test_done
11 exit 0
13 if ! test_have_prereq PERL; then
14 say 'skipping git cvsexportcommit tests, perl not available'
15 test_done
18 cvs >/dev/null 2>&1
19 if test $? -ne 1
20 then
21 say 'skipping git cvsexportcommit tests, cvs not found'
22 test_done
25 CVSROOT=$(pwd)/cvsroot
26 CVSWORK=$(pwd)/cvswork
27 GIT_DIR=$(pwd)/.git
28 export CVSROOT CVSWORK GIT_DIR
30 rm -rf "$CVSROOT" "$CVSWORK"
31 mkdir "$CVSROOT" &&
32 cvs init &&
33 cvs -Q co -d "$CVSWORK" . &&
34 echo >empty &&
35 git add empty &&
36 git commit -q -a -m "Initial" 2>/dev/null ||
37 exit 1
39 check_entries () {
40 # $1 == directory, $2 == expected
41 grep '^/' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
42 if test -z "$2"
43 then
44 >expected
45 else
46 printf '%s\n' "$2" | tr '|' '\012' >expected
48 test_cmp expected actual
51 test_expect_success \
52 'New file' \
53 'mkdir A B C D E F &&
54 echo hello1 >A/newfile1.txt &&
55 echo hello2 >B/newfile2.txt &&
56 cp "$TEST_DIRECTORY"/test9200a.png C/newfile3.png &&
57 cp "$TEST_DIRECTORY"/test9200a.png D/newfile4.png &&
58 git add A/newfile1.txt &&
59 git add B/newfile2.txt &&
60 git add C/newfile3.png &&
61 git add D/newfile4.png &&
62 git commit -a -m "Test: New file" &&
63 id=$(git rev-list --max-count=1 HEAD) &&
64 (cd "$CVSWORK" &&
65 git cvsexportcommit -c $id &&
66 check_entries A "newfile1.txt/1.1/" &&
67 check_entries B "newfile2.txt/1.1/" &&
68 check_entries C "newfile3.png/1.1/-kb" &&
69 check_entries D "newfile4.png/1.1/-kb" &&
70 diff A/newfile1.txt ../A/newfile1.txt &&
71 diff B/newfile2.txt ../B/newfile2.txt &&
72 diff C/newfile3.png ../C/newfile3.png &&
73 diff D/newfile4.png ../D/newfile4.png
76 test_expect_success \
77 'Remove two files, add two and update two' \
78 'echo Hello1 >>A/newfile1.txt &&
79 rm -f B/newfile2.txt &&
80 rm -f C/newfile3.png &&
81 echo Hello5 >E/newfile5.txt &&
82 cp "$TEST_DIRECTORY"/test9200b.png D/newfile4.png &&
83 cp "$TEST_DIRECTORY"/test9200a.png F/newfile6.png &&
84 git add E/newfile5.txt &&
85 git add F/newfile6.png &&
86 git commit -a -m "Test: Remove, add and update" &&
87 id=$(git rev-list --max-count=1 HEAD) &&
88 (cd "$CVSWORK" &&
89 git cvsexportcommit -c $id &&
90 check_entries A "newfile1.txt/1.2/" &&
91 check_entries B "" &&
92 check_entries C "" &&
93 check_entries D "newfile4.png/1.2/-kb" &&
94 check_entries E "newfile5.txt/1.1/" &&
95 check_entries F "newfile6.png/1.1/-kb" &&
96 diff A/newfile1.txt ../A/newfile1.txt &&
97 diff D/newfile4.png ../D/newfile4.png &&
98 diff E/newfile5.txt ../E/newfile5.txt &&
99 diff F/newfile6.png ../F/newfile6.png
102 # Should fail (but only on the git cvsexportcommit stage)
103 test_expect_success \
104 'Fail to change binary more than one generation old' \
105 'cat F/newfile6.png >>D/newfile4.png &&
106 git commit -a -m "generatiion 1" &&
107 cat F/newfile6.png >>D/newfile4.png &&
108 git commit -a -m "generation 2" &&
109 id=$(git rev-list --max-count=1 HEAD) &&
110 (cd "$CVSWORK" &&
111 test_must_fail git cvsexportcommit -c $id
114 #test_expect_success \
115 # 'Fail to remove binary file more than one generation old' \
116 # 'git reset --hard HEAD^ &&
117 # cat F/newfile6.png >>D/newfile4.png &&
118 # git commit -a -m "generation 2 (again)" &&
119 # rm -f D/newfile4.png &&
120 # git commit -a -m "generation 3" &&
121 # id=$(git rev-list --max-count=1 HEAD) &&
122 # (cd "$CVSWORK" &&
123 # test_must_fail git cvsexportcommit -c $id
124 # )'
126 # We reuse the state from two tests back here
128 # This test is here because a patch for only binary files will
129 # fail with gnu patch, so cvsexportcommit must handle that.
130 test_expect_success \
131 'Remove only binary files' \
132 'git reset --hard HEAD^^ &&
133 rm -f D/newfile4.png &&
134 git commit -a -m "test: remove only a binary file" &&
135 id=$(git rev-list --max-count=1 HEAD) &&
136 (cd "$CVSWORK" &&
137 git cvsexportcommit -c $id &&
138 check_entries A "newfile1.txt/1.2/" &&
139 check_entries B "" &&
140 check_entries C "" &&
141 check_entries D "" &&
142 check_entries E "newfile5.txt/1.1/" &&
143 check_entries F "newfile6.png/1.1/-kb" &&
144 diff A/newfile1.txt ../A/newfile1.txt &&
145 diff E/newfile5.txt ../E/newfile5.txt &&
146 diff F/newfile6.png ../F/newfile6.png
149 test_expect_success \
150 'Remove only a text file' \
151 'rm -f A/newfile1.txt &&
152 git commit -a -m "test: remove only a binary file" &&
153 id=$(git rev-list --max-count=1 HEAD) &&
154 (cd "$CVSWORK" &&
155 git cvsexportcommit -c $id &&
156 check_entries A "" &&
157 check_entries B "" &&
158 check_entries C "" &&
159 check_entries D "" &&
160 check_entries E "newfile5.txt/1.1/" &&
161 check_entries F "newfile6.png/1.1/-kb" &&
162 diff E/newfile5.txt ../E/newfile5.txt &&
163 diff F/newfile6.png ../F/newfile6.png
166 test_expect_success \
167 'New file with spaces in file name' \
168 'mkdir "G g" &&
169 echo ok then >"G g/with spaces.txt" &&
170 git add "G g/with spaces.txt" && \
171 cp "$TEST_DIRECTORY"/test9200a.png "G g/with spaces.png" && \
172 git add "G g/with spaces.png" &&
173 git commit -a -m "With spaces" &&
174 id=$(git rev-list --max-count=1 HEAD) &&
175 (cd "$CVSWORK" &&
176 git cvsexportcommit -c $id &&
177 check_entries "G g" "with spaces.png/1.1/-kb|with spaces.txt/1.1/"
180 test_expect_success \
181 'Update file with spaces in file name' \
182 'echo Ok then >>"G g/with spaces.txt" &&
183 cat "$TEST_DIRECTORY"/test9200a.png >>"G g/with spaces.png" && \
184 git add "G g/with spaces.png" &&
185 git commit -a -m "Update with spaces" &&
186 id=$(git rev-list --max-count=1 HEAD) &&
187 (cd "$CVSWORK" &&
188 git cvsexportcommit -c $id
189 check_entries "G g" "with spaces.png/1.2/-kb|with spaces.txt/1.2/"
192 # Some filesystems mangle pathnames with UTF-8 characters --
193 # check and skip
194 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/å/ä/ö" &&
195 mkdir -p "tst/$p" &&
196 date >"tst/$p/day" &&
197 found=$(find tst -type f -print) &&
198 test "z$found" = "ztst/$p/day" &&
199 rm -fr tst
200 then
202 # This test contains UTF-8 characters
203 test_expect_success \
204 'File with non-ascii file name' \
205 '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/å/ä/ö &&
206 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 &&
207 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 &&
208 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 &&
209 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 &&
210 git commit -a -m "Går det så går det" && \
211 id=$(git rev-list --max-count=1 HEAD) &&
212 (cd "$CVSWORK" &&
213 git cvsexportcommit -v -c $id &&
214 check_entries \
215 "Å/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/å/ä/ö" \
216 "gårdetsågårdet.png/1.1/-kb|gårdetsågårdet.txt/1.1/"
221 rm -fr tst
223 test_expect_success \
224 'Mismatching patch should fail' \
225 'date >>"E/newfile5.txt" &&
226 git add "E/newfile5.txt" &&
227 git commit -a -m "Update one" &&
228 date >>"E/newfile5.txt" &&
229 git add "E/newfile5.txt" &&
230 git commit -a -m "Update two" &&
231 id=$(git rev-list --max-count=1 HEAD) &&
232 (cd "$CVSWORK" &&
233 test_must_fail git cvsexportcommit -c $id
236 if ! test "$(git config --bool core.filemode)" = false
237 then
238 test_set_prereq FILEMODE
241 test_expect_success FILEMODE \
242 'Retain execute bit' \
243 'mkdir G &&
244 echo executeon >G/on &&
245 chmod +x G/on &&
246 echo executeoff >G/off &&
247 git add G/on &&
248 git add G/off &&
249 git commit -a -m "Execute test" &&
250 (cd "$CVSWORK" &&
251 git cvsexportcommit -c HEAD
252 test -x G/on &&
253 ! test -x G/off
256 test_expect_success '-w option should work with relative GIT_DIR' '
257 mkdir W &&
258 echo foobar >W/file1.txt &&
259 echo bazzle >W/file2.txt &&
260 git add W/file1.txt &&
261 git add W/file2.txt &&
262 git commit -m "More updates" &&
263 id=$(git rev-list --max-count=1 HEAD) &&
264 (cd "$GIT_DIR" &&
265 GIT_DIR=. git cvsexportcommit -w "$CVSWORK" -c $id &&
266 check_entries "$CVSWORK/W" "file1.txt/1.1/|file2.txt/1.1/" &&
267 test_cmp "$CVSWORK/W/file1.txt" ../W/file1.txt &&
268 test_cmp "$CVSWORK/W/file2.txt" ../W/file2.txt
272 test_expect_success 'check files before directories' '
274 echo Notes > release-notes &&
275 git add release-notes &&
276 git commit -m "Add release notes" release-notes &&
277 id=$(git rev-parse HEAD) &&
278 git cvsexportcommit -w "$CVSWORK" -c $id &&
280 echo new > DS &&
281 echo new > E/DS &&
282 echo modified > release-notes &&
283 git add DS E/DS release-notes &&
284 git commit -m "Add two files with the same basename" &&
285 id=$(git rev-parse HEAD) &&
286 git cvsexportcommit -w "$CVSWORK" -c $id &&
287 check_entries "$CVSWORK/E" "DS/1.1/|newfile5.txt/1.1/" &&
288 check_entries "$CVSWORK" "DS/1.1/|release-notes/1.2/" &&
289 test_cmp "$CVSWORK/DS" DS &&
290 test_cmp "$CVSWORK/E/DS" E/DS &&
291 test_cmp "$CVSWORK/release-notes" release-notes
295 test_expect_success 'commit a file with leading spaces in the name' '
297 echo space > " space" &&
298 git add " space" &&
299 git commit -m "Add a file with a leading space" &&
300 id=$(git rev-parse HEAD) &&
301 git cvsexportcommit -w "$CVSWORK" -c $id &&
302 check_entries "$CVSWORK" " space/1.1/|DS/1.1/|release-notes/1.2/" &&
303 test_cmp "$CVSWORK/ space" " space"
307 test_expect_success 'use the same checkout for Git and CVS' '
309 (mkdir shared &&
310 cd shared &&
311 unset GIT_DIR &&
312 cvs co . &&
313 git init &&
314 git add " space" &&
315 git commit -m "fake initial commit" &&
316 echo Hello >> " space" &&
317 git commit -m "Another change" " space" &&
318 git cvsexportcommit -W -p -u -c HEAD &&
319 grep Hello " space" &&
320 git diff-files)
324 test_done