Merge commit 'junio/next' into next
[git/platforms/storm.git] / t / t9200-git-cvsexportcommit.sh
blob55df4da7f0265f2e529ba77986e72023c186ece9
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 cvs >/dev/null 2>&1
14 if test $? -ne 1
15 then
16 test_expect_success 'skipping git-cvsexportcommit tests, cvs not found' :
17 test_done
18 exit
21 CVSROOT=$(pwd)/cvsroot
22 CVSWORK=$(pwd)/cvswork
23 GIT_DIR=$(pwd)/.git
24 export CVSROOT CVSWORK GIT_DIR
26 rm -rf "$CVSROOT" "$CVSWORK"
27 mkdir "$CVSROOT" &&
28 cvs init &&
29 cvs -Q co -d "$CVSWORK" . &&
30 echo >empty &&
31 git add empty &&
32 git commit -q -a -m "Initial" 2>/dev/null ||
33 exit 1
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
44 test_cmp expected actual
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 &&
52 cp ../test9200a.png C/newfile3.png &&
53 cp ../test9200a.png D/newfile4.png &&
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 &&
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" &&
66 diff A/newfile1.txt ../A/newfile1.txt &&
67 diff B/newfile2.txt ../B/newfile2.txt &&
68 diff C/newfile3.png ../C/newfile3.png &&
69 diff D/newfile4.png ../D/newfile4.png
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 &&
78 cp ../test9200b.png D/newfile4.png &&
79 cp ../test9200a.png F/newfile6.png &&
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 &&
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" &&
92 diff A/newfile1.txt ../A/newfile1.txt &&
93 diff D/newfile4.png ../D/newfile4.png &&
94 diff E/newfile5.txt ../E/newfile5.txt &&
95 diff F/newfile6.png ../F/newfile6.png
98 # Should fail (but only on the git-cvsexportcommit stage)
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" &&
107 ! git cvsexportcommit -c $id
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" &&
119 # ! git cvsexportcommit -c $id
120 # )'
122 # We reuse the state from two tests back here
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' \
128 'git reset --hard HEAD^^ &&
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 &&
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" &&
140 diff A/newfile1.txt ../A/newfile1.txt &&
141 diff E/newfile5.txt ../E/newfile5.txt &&
142 diff F/newfile6.png ../F/newfile6.png
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 &&
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" &&
158 diff E/newfile5.txt ../E/newfile5.txt &&
159 diff F/newfile6.png ../F/newfile6.png
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" && \
167 cp ../test9200a.png "G g/with spaces.png" && \
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" &&
172 git-cvsexportcommit -c $id &&
173 check_entries "G g" "with spaces.png/1.1/-kb|with spaces.txt/1.1/"
176 test_expect_success \
177 'Update file with spaces in file name' \
178 'echo Ok then >>"G g/with spaces.txt" &&
179 cat ../test9200a.png >>"G g/with spaces.png" && \
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" &&
184 git-cvsexportcommit -c $id
185 check_entries "G g" "with spaces.png/1.2/-kb|with spaces.txt/1.2/"
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
198 # This test contains UTF-8 characters
199 test_expect_success \
200 'File with non-ascii file name' \
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 &&
204 cp ../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 &&
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" && \
207 id=$(git rev-list --max-count=1 HEAD) &&
208 (cd "$CVSWORK" &&
209 git-cvsexportcommit -v -c $id &&
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/"
217 rm -fr tst
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" &&
229 ! git-cvsexportcommit -c $id
232 case "$(git config --bool core.filemode)" in
233 false)
236 test_expect_success \
237 'Retain execute bit' \
238 'mkdir G &&
239 echo executeon >G/on &&
240 chmod +x G/on &&
241 echo executeoff >G/off &&
242 git add G/on &&
243 git add G/off &&
244 git commit -a -m "Execute test" &&
245 (cd "$CVSWORK" &&
246 git-cvsexportcommit -c HEAD
247 test -x G/on &&
248 ! test -x G/off
251 esac
253 test_expect_success '-w option should work with relative GIT_DIR' '
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
269 test_expect_success 'check files before directories' '
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 &&
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/" &&
286 test_cmp "$CVSWORK/DS" DS &&
287 test_cmp "$CVSWORK/E/DS" E/DS &&
288 test_cmp "$CVSWORK/release-notes" release-notes
292 test_expect_success 'commit a file with leading spaces in the name' '
294 echo space > " space" &&
295 git add " space" &&
296 git commit -m "Add a file with a leading space" &&
297 id=$(git rev-parse HEAD) &&
298 git cvsexportcommit -w "$CVSWORK" -c $id &&
299 check_entries "$CVSWORK" " space/1.1/|DS/1.1/|release-notes/1.2/" &&
300 test_cmp "$CVSWORK/ space" " space"
304 test_expect_success 'use the same checkout for Git and CVS' '
306 (mkdir shared &&
307 cd shared &&
308 unset GIT_DIR &&
309 cvs co . &&
310 git init &&
311 git add " space" &&
312 git commit -m "fake initial commit" &&
313 echo Hello >> " space" &&
314 git commit -m "Another change" " space" &&
315 git cvsexportcommit -W -p -u -c HEAD &&
316 grep Hello " space" &&
317 git diff-files)
321 test_done