Merge branch 'nd/index-pack-l10n-buf-overflow' into maint-1.8.1
[git/jnareb-git.git] / t / t9200-git-cvsexportcommit.sh
blob3fb3368903686c8588c51e881beaee1f29808575
1 #!/bin/sh
3 # Copyright (c) Robin Rosenberg
5 test_description='Test export of commits to CVS'
7 . ./test-lib.sh
8 . "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh
10 if ! test_have_prereq PERL; then
11 skip_all='skipping git cvsexportcommit tests, perl not available'
12 test_done
15 cvs >/dev/null 2>&1
16 if test $? -ne 1
17 then
18 skip_all='skipping git cvsexportcommit tests, cvs not found'
19 test_done
22 CVSROOT=$PWD/tmpcvsroot
23 CVSWORK=$PWD/cvswork
24 GIT_DIR=$PWD/.git
25 export CVSROOT CVSWORK GIT_DIR
27 rm -rf "$CVSROOT" "$CVSWORK"
29 cvs init &&
30 test -d "$CVSROOT" &&
31 cvs -Q co -d "$CVSWORK" . &&
32 echo >empty &&
33 git add empty &&
34 git commit -q -a -m "Initial" 2>/dev/null ||
35 exit 1
37 check_entries () {
38 # $1 == directory, $2 == expected
39 grep '^/' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
40 if test -z "$2"
41 then
42 >expected
43 else
44 printf '%s\n' "$2" | tr '|' '\012' >expected
46 test_cmp expected actual
49 test_expect_success \
50 'New file' \
51 'mkdir A B C D E F &&
52 echo hello1 >A/newfile1.txt &&
53 echo hello2 >B/newfile2.txt &&
54 cp "$TEST_DIRECTORY"/test-binary-1.png C/newfile3.png &&
55 cp "$TEST_DIRECTORY"/test-binary-1.png D/newfile4.png &&
56 git add A/newfile1.txt &&
57 git add B/newfile2.txt &&
58 git add C/newfile3.png &&
59 git add D/newfile4.png &&
60 git commit -a -m "Test: New file" &&
61 id=$(git rev-list --max-count=1 HEAD) &&
62 (cd "$CVSWORK" &&
63 git cvsexportcommit -c $id &&
64 check_entries A "newfile1.txt/1.1/" &&
65 check_entries B "newfile2.txt/1.1/" &&
66 check_entries C "newfile3.png/1.1/-kb" &&
67 check_entries D "newfile4.png/1.1/-kb" &&
68 test_cmp A/newfile1.txt ../A/newfile1.txt &&
69 test_cmp B/newfile2.txt ../B/newfile2.txt &&
70 test_cmp C/newfile3.png ../C/newfile3.png &&
71 test_cmp D/newfile4.png ../D/newfile4.png
74 test_expect_success \
75 'Remove two files, add two and update two' \
76 'echo Hello1 >>A/newfile1.txt &&
77 rm -f B/newfile2.txt &&
78 rm -f C/newfile3.png &&
79 echo Hello5 >E/newfile5.txt &&
80 cp "$TEST_DIRECTORY"/test-binary-2.png D/newfile4.png &&
81 cp "$TEST_DIRECTORY"/test-binary-1.png F/newfile6.png &&
82 git add E/newfile5.txt &&
83 git add F/newfile6.png &&
84 git commit -a -m "Test: Remove, add and update" &&
85 id=$(git rev-list --max-count=1 HEAD) &&
86 (cd "$CVSWORK" &&
87 git cvsexportcommit -c $id &&
88 check_entries A "newfile1.txt/1.2/" &&
89 check_entries B "" &&
90 check_entries C "" &&
91 check_entries D "newfile4.png/1.2/-kb" &&
92 check_entries E "newfile5.txt/1.1/" &&
93 check_entries F "newfile6.png/1.1/-kb" &&
94 test_cmp A/newfile1.txt ../A/newfile1.txt &&
95 test_cmp D/newfile4.png ../D/newfile4.png &&
96 test_cmp E/newfile5.txt ../E/newfile5.txt &&
97 test_cmp F/newfile6.png ../F/newfile6.png
100 # Should fail (but only on the git cvsexportcommit stage)
101 test_expect_success \
102 'Fail to change binary more than one generation old' \
103 'cat F/newfile6.png >>D/newfile4.png &&
104 git commit -a -m "generatiion 1" &&
105 cat F/newfile6.png >>D/newfile4.png &&
106 git commit -a -m "generation 2" &&
107 id=$(git rev-list --max-count=1 HEAD) &&
108 (cd "$CVSWORK" &&
109 test_must_fail git cvsexportcommit -c $id
112 #test_expect_success \
113 # 'Fail to remove binary file more than one generation old' \
114 # 'git reset --hard HEAD^ &&
115 # cat F/newfile6.png >>D/newfile4.png &&
116 # git commit -a -m "generation 2 (again)" &&
117 # rm -f D/newfile4.png &&
118 # git commit -a -m "generation 3" &&
119 # id=$(git rev-list --max-count=1 HEAD) &&
120 # (cd "$CVSWORK" &&
121 # test_must_fail git cvsexportcommit -c $id
122 # )'
124 # We reuse the state from two tests back here
126 # This test is here because a patch for only binary files will
127 # fail with gnu patch, so cvsexportcommit must handle that.
128 test_expect_success \
129 'Remove only binary files' \
130 'git reset --hard HEAD^^ &&
131 rm -f D/newfile4.png &&
132 git commit -a -m "test: remove only a binary file" &&
133 id=$(git rev-list --max-count=1 HEAD) &&
134 (cd "$CVSWORK" &&
135 git cvsexportcommit -c $id &&
136 check_entries A "newfile1.txt/1.2/" &&
137 check_entries B "" &&
138 check_entries C "" &&
139 check_entries D "" &&
140 check_entries E "newfile5.txt/1.1/" &&
141 check_entries F "newfile6.png/1.1/-kb" &&
142 test_cmp A/newfile1.txt ../A/newfile1.txt &&
143 test_cmp E/newfile5.txt ../E/newfile5.txt &&
144 test_cmp F/newfile6.png ../F/newfile6.png
147 test_expect_success \
148 'Remove only a text file' \
149 'rm -f A/newfile1.txt &&
150 git commit -a -m "test: remove only a binary file" &&
151 id=$(git rev-list --max-count=1 HEAD) &&
152 (cd "$CVSWORK" &&
153 git cvsexportcommit -c $id &&
154 check_entries A "" &&
155 check_entries B "" &&
156 check_entries C "" &&
157 check_entries D "" &&
158 check_entries E "newfile5.txt/1.1/" &&
159 check_entries F "newfile6.png/1.1/-kb" &&
160 test_cmp E/newfile5.txt ../E/newfile5.txt &&
161 test_cmp F/newfile6.png ../F/newfile6.png
164 test_expect_success \
165 'New file with spaces in file name' \
166 'mkdir "G g" &&
167 echo ok then >"G g/with spaces.txt" &&
168 git add "G g/with spaces.txt" && \
169 cp "$TEST_DIRECTORY"/test-binary-1.png "G g/with spaces.png" && \
170 git add "G g/with spaces.png" &&
171 git commit -a -m "With spaces" &&
172 id=$(git rev-list --max-count=1 HEAD) &&
173 (cd "$CVSWORK" &&
174 git cvsexportcommit -c $id &&
175 check_entries "G g" "with spaces.png/1.1/-kb|with spaces.txt/1.1/"
178 test_expect_success \
179 'Update file with spaces in file name' \
180 'echo Ok then >>"G g/with spaces.txt" &&
181 cat "$TEST_DIRECTORY"/test-binary-1.png >>"G g/with spaces.png" && \
182 git add "G g/with spaces.png" &&
183 git commit -a -m "Update with spaces" &&
184 id=$(git rev-list --max-count=1 HEAD) &&
185 (cd "$CVSWORK" &&
186 git cvsexportcommit -c $id
187 check_entries "G g" "with spaces.png/1.2/-kb|with spaces.txt/1.2/"
190 # Some filesystems mangle pathnames with UTF-8 characters --
191 # check and skip
192 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/å/ä/ö" &&
193 mkdir -p "tst/$p" &&
194 date >"tst/$p/day" &&
195 found=$(find tst -type f -print) &&
196 test "z$found" = "ztst/$p/day" &&
197 rm -fr tst
198 then
200 # This test contains UTF-8 characters
201 test_expect_success \
202 'File with non-ascii file name' \
203 '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/å/ä/ö &&
204 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 &&
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.txt &&
206 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 &&
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.png &&
208 git commit -a -m "Går det så går det" && \
209 id=$(git rev-list --max-count=1 HEAD) &&
210 (cd "$CVSWORK" &&
211 git cvsexportcommit -v -c $id &&
212 check_entries \
213 "Å/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/å/ä/ö" \
214 "gårdetsågårdet.png/1.1/-kb|gårdetsågårdet.txt/1.1/"
219 rm -fr tst
221 test_expect_success \
222 'Mismatching patch should fail' \
223 'date >>"E/newfile5.txt" &&
224 git add "E/newfile5.txt" &&
225 git commit -a -m "Update one" &&
226 date >>"E/newfile5.txt" &&
227 git add "E/newfile5.txt" &&
228 git commit -a -m "Update two" &&
229 id=$(git rev-list --max-count=1 HEAD) &&
230 (cd "$CVSWORK" &&
231 test_must_fail git cvsexportcommit -c $id
234 test_expect_success FILEMODE \
235 'Retain execute bit' \
236 'mkdir G &&
237 echo executeon >G/on &&
238 chmod +x G/on &&
239 echo executeoff >G/off &&
240 git add G/on &&
241 git add G/off &&
242 git commit -a -m "Execute test" &&
243 (cd "$CVSWORK" &&
244 git cvsexportcommit -c HEAD
245 test -x G/on &&
246 ! test -x G/off
249 test_expect_success '-w option should work with relative GIT_DIR' '
250 mkdir W &&
251 echo foobar >W/file1.txt &&
252 echo bazzle >W/file2.txt &&
253 git add W/file1.txt &&
254 git add W/file2.txt &&
255 git commit -m "More updates" &&
256 id=$(git rev-list --max-count=1 HEAD) &&
257 (cd "$GIT_DIR" &&
258 GIT_DIR=. git cvsexportcommit -w "$CVSWORK" -c $id &&
259 check_entries "$CVSWORK/W" "file1.txt/1.1/|file2.txt/1.1/" &&
260 test_cmp "$CVSWORK/W/file1.txt" ../W/file1.txt &&
261 test_cmp "$CVSWORK/W/file2.txt" ../W/file2.txt
265 test_expect_success 'check files before directories' '
267 echo Notes > release-notes &&
268 git add release-notes &&
269 git commit -m "Add release notes" release-notes &&
270 id=$(git rev-parse HEAD) &&
271 git cvsexportcommit -w "$CVSWORK" -c $id &&
273 echo new > DS &&
274 echo new > E/DS &&
275 echo modified > release-notes &&
276 git add DS E/DS release-notes &&
277 git commit -m "Add two files with the same basename" &&
278 id=$(git rev-parse HEAD) &&
279 git cvsexportcommit -w "$CVSWORK" -c $id &&
280 check_entries "$CVSWORK/E" "DS/1.1/|newfile5.txt/1.1/" &&
281 check_entries "$CVSWORK" "DS/1.1/|release-notes/1.2/" &&
282 test_cmp "$CVSWORK/DS" DS &&
283 test_cmp "$CVSWORK/E/DS" E/DS &&
284 test_cmp "$CVSWORK/release-notes" release-notes
288 test_expect_success 're-commit a removed filename which remains in CVS attic' '
290 (cd "$CVSWORK" &&
291 echo >attic_gremlin &&
292 cvs -Q add attic_gremlin &&
293 cvs -Q ci -m "added attic_gremlin" &&
294 rm attic_gremlin &&
295 cvs -Q rm attic_gremlin &&
296 cvs -Q ci -m "removed attic_gremlin") &&
298 echo > attic_gremlin &&
299 git add attic_gremlin &&
300 git commit -m "Added attic_gremlin" &&
301 git cvsexportcommit -w "$CVSWORK" -c HEAD &&
302 (cd "$CVSWORK"; cvs -Q update -d) &&
303 test -f "$CVSWORK/attic_gremlin"
306 # the state of the CVS sandbox may be indeterminate for ' space'
307 # after this test on some platforms / with some versions of CVS
308 # consider adding new tests above this point
309 test_expect_success 'commit a file with leading spaces in the name' '
311 echo space > " space" &&
312 git add " space" &&
313 git commit -m "Add a file with a leading space" &&
314 id=$(git rev-parse HEAD) &&
315 git cvsexportcommit -w "$CVSWORK" -c $id &&
316 check_entries "$CVSWORK" " space/1.1/|DS/1.1/|attic_gremlin/1.3/|release-notes/1.2/" &&
317 test_cmp "$CVSWORK/ space" " space"
321 test_expect_success 'use the same checkout for Git and CVS' '
323 (mkdir shared &&
324 cd shared &&
325 sane_unset GIT_DIR &&
326 cvs co . &&
327 git init &&
328 git add " space" &&
329 git commit -m "fake initial commit" &&
330 echo Hello >> " space" &&
331 git commit -m "Another change" " space" &&
332 git cvsexportcommit -W -p -u -c HEAD &&
333 grep Hello " space" &&
334 git diff-files)
338 test_done