3 # Copyright (c) Robin Rosenberg
5 test_description
='Test export of commits to CVS'
9 say
"CVS does not work on MinGW, skipping tests."
16 test_expect_success
'skipping git-cvsexportcommit tests, cvs not found' :
21 CVSROOT
=$
(pwd)/cvsroot
22 CVSWORK
=$
(pwd)/cvswork
24 export CVSROOT CVSWORK GIT_DIR
26 rm -rf "$CVSROOT" "$CVSWORK"
29 cvs
-Q co
-d "$CVSWORK" .
&&
32 git commit
-q -a -m "Initial" 2>/dev
/null ||
36 # $1 == directory, $2 == expected
37 grep '^/' "$1/CVS/Entries" |
sort | cut
-d/ -f2,3,5 >actual
42 printf '%s\n' "$2" |
tr '|' '\012' >expected
44 test_cmp expected actual
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) &&
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
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) &&
85 git cvsexportcommit -c $id &&
86 check_entries A "newfile1.txt/1.2/" &&
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)
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) &&
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) &&
119 # ! git cvsexportcommit -c $id
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) &&
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) &&
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' \
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) &&
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) &&
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 --
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/å/ä/ö" &&
192 date >"tst/$p/day" &&
193 found
=$
(find tst
-type f
-print) &&
194 test "z$found" = "ztst/$p/day" &&
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) &&
209 git-cvsexportcommit -v -c $id &&
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/"
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) &&
229 ! git-cvsexportcommit -c $id
232 case "$(git config --bool core.filemode)" in
236 test_expect_success \
237 'Retain execute bit' \
239 echo executeon >G/on &&
241 echo executeoff >G/off &&
244 git commit -a -m "Execute test" &&
246 git-cvsexportcommit -c HEAD
253 test_expect_success
'-w option should work with relative GIT_DIR' '
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) &&
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 &&
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" &&
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' '
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" &&