Merge branch 'rs/fix-unlink-unix-socket'
[git/mingw/j6t.git] / t / t9200-git-cvsexportcommit.sh
blob812c9cd462f58f6fd76e3d339e95137aee598801
1 #!/bin/sh
3 # Copyright (c) Robin Rosenberg
5 test_description='Test export of commits to CVS'
7 . ./test-lib.sh
9 if ! test_have_prereq PERL; then
10 skip_all='skipping git cvsexportcommit tests, perl not available'
11 test_done
14 cvs >/dev/null 2>&1
15 if test $? -ne 1
16 then
17 skip_all='skipping git cvsexportcommit tests, cvs not found'
18 test_done
21 CVSROOT=$PWD/tmpcvsroot
22 CVSWORK=$PWD/cvswork
23 GIT_DIR=$PWD/.git
24 export CVSROOT CVSWORK GIT_DIR
26 rm -rf "$CVSROOT" "$CVSWORK"
28 cvs init &&
29 test -d "$CVSROOT" &&
30 cvs -Q co -d "$CVSWORK" . &&
31 echo >empty &&
32 git add empty &&
33 git commit -q -a -m "Initial" 2>/dev/null ||
34 exit 1
36 check_entries () {
37 # $1 == directory, $2 == expected
38 grep '^/' "$1/CVS/Entries" | sort | cut -d/ -f2,3,5 >actual
39 if test -z "$2"
40 then
41 >expected
42 else
43 printf '%s\n' "$2" | tr '|' '\012' >expected
45 test_cmp expected actual
48 test_expect_success \
49 'New file' \
50 'mkdir A B C D E F &&
51 echo hello1 >A/newfile1.txt &&
52 echo hello2 >B/newfile2.txt &&
53 cp "$TEST_DIRECTORY"/test-binary-1.png C/newfile3.png &&
54 cp "$TEST_DIRECTORY"/test-binary-1.png D/newfile4.png &&
55 git add A/newfile1.txt &&
56 git add B/newfile2.txt &&
57 git add C/newfile3.png &&
58 git add D/newfile4.png &&
59 git commit -a -m "Test: New file" &&
60 id=$(git rev-list --max-count=1 HEAD) &&
61 (cd "$CVSWORK" &&
62 git cvsexportcommit -c $id &&
63 check_entries A "newfile1.txt/1.1/" &&
64 check_entries B "newfile2.txt/1.1/" &&
65 check_entries C "newfile3.png/1.1/-kb" &&
66 check_entries D "newfile4.png/1.1/-kb" &&
67 test_cmp A/newfile1.txt ../A/newfile1.txt &&
68 test_cmp B/newfile2.txt ../B/newfile2.txt &&
69 test_cmp C/newfile3.png ../C/newfile3.png &&
70 test_cmp D/newfile4.png ../D/newfile4.png
73 test_expect_success \
74 'Remove two files, add two and update two' \
75 'echo Hello1 >>A/newfile1.txt &&
76 rm -f B/newfile2.txt &&
77 rm -f C/newfile3.png &&
78 echo Hello5 >E/newfile5.txt &&
79 cp "$TEST_DIRECTORY"/test-binary-2.png D/newfile4.png &&
80 cp "$TEST_DIRECTORY"/test-binary-1.png F/newfile6.png &&
81 git add E/newfile5.txt &&
82 git add F/newfile6.png &&
83 git commit -a -m "Test: Remove, add and update" &&
84 id=$(git rev-list --max-count=1 HEAD) &&
85 (cd "$CVSWORK" &&
86 git cvsexportcommit -c $id &&
87 check_entries A "newfile1.txt/1.2/" &&
88 check_entries B "" &&
89 check_entries C "" &&
90 check_entries D "newfile4.png/1.2/-kb" &&
91 check_entries E "newfile5.txt/1.1/" &&
92 check_entries F "newfile6.png/1.1/-kb" &&
93 test_cmp A/newfile1.txt ../A/newfile1.txt &&
94 test_cmp D/newfile4.png ../D/newfile4.png &&
95 test_cmp E/newfile5.txt ../E/newfile5.txt &&
96 test_cmp F/newfile6.png ../F/newfile6.png
99 # Should fail (but only on the git cvsexportcommit stage)
100 test_expect_success \
101 'Fail to change binary more than one generation old' \
102 'cat F/newfile6.png >>D/newfile4.png &&
103 git commit -a -m "generatiion 1" &&
104 cat F/newfile6.png >>D/newfile4.png &&
105 git commit -a -m "generation 2" &&
106 id=$(git rev-list --max-count=1 HEAD) &&
107 (cd "$CVSWORK" &&
108 test_must_fail git cvsexportcommit -c $id
111 #test_expect_success \
112 # 'Fail to remove binary file more than one generation old' \
113 # 'git reset --hard HEAD^ &&
114 # cat F/newfile6.png >>D/newfile4.png &&
115 # git commit -a -m "generation 2 (again)" &&
116 # rm -f D/newfile4.png &&
117 # git commit -a -m "generation 3" &&
118 # id=$(git rev-list --max-count=1 HEAD) &&
119 # (cd "$CVSWORK" &&
120 # test_must_fail git cvsexportcommit -c $id
121 # )'
123 # We reuse the state from two tests back here
125 # This test is here because a patch for only binary files will
126 # fail with gnu patch, so cvsexportcommit must handle that.
127 test_expect_success \
128 'Remove only binary files' \
129 'git reset --hard HEAD^^ &&
130 rm -f D/newfile4.png &&
131 git commit -a -m "test: remove only a binary file" &&
132 id=$(git rev-list --max-count=1 HEAD) &&
133 (cd "$CVSWORK" &&
134 git cvsexportcommit -c $id &&
135 check_entries A "newfile1.txt/1.2/" &&
136 check_entries B "" &&
137 check_entries C "" &&
138 check_entries D "" &&
139 check_entries E "newfile5.txt/1.1/" &&
140 check_entries F "newfile6.png/1.1/-kb" &&
141 test_cmp A/newfile1.txt ../A/newfile1.txt &&
142 test_cmp E/newfile5.txt ../E/newfile5.txt &&
143 test_cmp F/newfile6.png ../F/newfile6.png
146 test_expect_success \
147 'Remove only a text file' \
148 'rm -f A/newfile1.txt &&
149 git commit -a -m "test: remove only a binary file" &&
150 id=$(git rev-list --max-count=1 HEAD) &&
151 (cd "$CVSWORK" &&
152 git cvsexportcommit -c $id &&
153 check_entries A "" &&
154 check_entries B "" &&
155 check_entries C "" &&
156 check_entries D "" &&
157 check_entries E "newfile5.txt/1.1/" &&
158 check_entries F "newfile6.png/1.1/-kb" &&
159 test_cmp E/newfile5.txt ../E/newfile5.txt &&
160 test_cmp F/newfile6.png ../F/newfile6.png
163 test_expect_success \
164 'New file with spaces in file name' \
165 'mkdir "G g" &&
166 echo ok then >"G g/with spaces.txt" &&
167 git add "G g/with spaces.txt" && \
168 cp "$TEST_DIRECTORY"/test-binary-1.png "G g/with spaces.png" && \
169 git add "G g/with spaces.png" &&
170 git commit -a -m "With spaces" &&
171 id=$(git rev-list --max-count=1 HEAD) &&
172 (cd "$CVSWORK" &&
173 git cvsexportcommit -c $id &&
174 check_entries "G g" "with spaces.png/1.1/-kb|with spaces.txt/1.1/"
177 test_expect_success \
178 'Update file with spaces in file name' \
179 'echo Ok then >>"G g/with spaces.txt" &&
180 cat "$TEST_DIRECTORY"/test-binary-1.png >>"G g/with spaces.png" && \
181 git add "G g/with spaces.png" &&
182 git commit -a -m "Update with spaces" &&
183 id=$(git rev-list --max-count=1 HEAD) &&
184 (cd "$CVSWORK" &&
185 git cvsexportcommit -c $id
186 check_entries "G g" "with spaces.png/1.2/-kb|with spaces.txt/1.2/"
189 # Some filesystems mangle pathnames with UTF-8 characters --
190 # check and skip
191 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/å/ä/ö" &&
192 mkdir -p "tst/$p" &&
193 date >"tst/$p/day" &&
194 found=$(find tst -type f -print) &&
195 test "z$found" = "ztst/$p/day" &&
196 rm -fr tst
197 then
199 # This test contains UTF-8 characters
200 test_expect_success \
201 'File with non-ascii file name' \
202 '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/å/ä/ö &&
203 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 &&
204 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 &&
205 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 &&
206 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 &&
207 git commit -a -m "Går det så går det" && \
208 id=$(git rev-list --max-count=1 HEAD) &&
209 (cd "$CVSWORK" &&
210 git cvsexportcommit -v -c $id &&
211 check_entries \
212 "Å/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/å/ä/ö" \
213 "gårdetsågårdet.png/1.1/-kb|gårdetsågårdet.txt/1.1/"
218 rm -fr tst
220 test_expect_success \
221 'Mismatching patch should fail' \
222 'date >>"E/newfile5.txt" &&
223 git add "E/newfile5.txt" &&
224 git commit -a -m "Update one" &&
225 date >>"E/newfile5.txt" &&
226 git add "E/newfile5.txt" &&
227 git commit -a -m "Update two" &&
228 id=$(git rev-list --max-count=1 HEAD) &&
229 (cd "$CVSWORK" &&
230 test_must_fail git cvsexportcommit -c $id
233 test_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
248 test_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
264 test_expect_success 'check files before directories' '
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 &&
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
287 test_expect_success 're-commit a removed filename which remains in CVS attic' '
289 (cd "$CVSWORK" &&
290 echo >attic_gremlin &&
291 cvs -Q add attic_gremlin &&
292 cvs -Q ci -m "added attic_gremlin" &&
293 rm attic_gremlin &&
294 cvs -Q rm attic_gremlin &&
295 cvs -Q ci -m "removed attic_gremlin") &&
297 echo > attic_gremlin &&
298 git add attic_gremlin &&
299 git commit -m "Added attic_gremlin" &&
300 git cvsexportcommit -w "$CVSWORK" -c HEAD &&
301 (cd "$CVSWORK"; cvs -Q update -d) &&
302 test -f "$CVSWORK/attic_gremlin"
305 # the state of the CVS sandbox may be indeterminate for ' space'
306 # after this test on some platforms / with some versions of CVS
307 # consider adding new tests above this point
308 test_expect_success 'commit a file with leading spaces in the name' '
310 echo space > " space" &&
311 git add " space" &&
312 git commit -m "Add a file with a leading space" &&
313 id=$(git rev-parse HEAD) &&
314 git cvsexportcommit -w "$CVSWORK" -c $id &&
315 check_entries "$CVSWORK" " space/1.1/|DS/1.1/|attic_gremlin/1.3/|release-notes/1.2/" &&
316 test_cmp "$CVSWORK/ space" " space"
320 test_expect_success 'use the same checkout for Git and CVS' '
322 (mkdir shared &&
323 cd shared &&
324 sane_unset GIT_DIR &&
325 cvs co . &&
326 git init &&
327 git add " space" &&
328 git commit -m "fake initial commit" &&
329 echo Hello >> " space" &&
330 git commit -m "Another change" " space" &&
331 git cvsexportcommit -W -p -u -c HEAD &&
332 grep Hello " space" &&
333 git diff-files)
337 test_done