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