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