]>
Commit | Line | Data |
---|---|---|
8a06a632 MO |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2008 Matthew Ogilvie | |
4 | # Parts adapted from other tests. | |
5 | # | |
6 | ||
7 | test_description='git-cvsserver -kb modes | |
8 | ||
9 | tests -kb mode for binary files when accessing a git | |
10 | repository using cvs CLI client via git-cvsserver server' | |
11 | ||
a881baa2 | 12 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
334afbc7 JS |
13 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
14 | ||
8a06a632 MO |
15 | . ./test-lib.sh |
16 | ||
8a06a632 MO |
17 | marked_as () { |
18 | foundEntry="$(grep "^/$2/" "$1/CVS/Entries")" | |
19 | if [ x"$foundEntry" = x"" ] ; then | |
20 | echo "NOT FOUND: $1 $2 1 $3" >> "${WORKDIR}/marked.log" | |
21 | return 1 | |
22 | fi | |
23 | test x"$(grep "^/$2/" "$1/CVS/Entries" | cut -d/ -f5)" = x"$3" | |
24 | stat=$? | |
25 | echo "$1 $2 $stat '$3'" >> "${WORKDIR}/marked.log" | |
26 | return $stat | |
27 | } | |
28 | ||
29 | not_present() { | |
30 | foundEntry="$(grep "^/$2/" "$1/CVS/Entries")" | |
31 | if [ -r "$1/$2" ] ; then | |
32 | echo "Error: File still exists: $1 $2" >> "${WORKDIR}/marked.log" | |
33 | return 1; | |
34 | fi | |
35 | if [ x"$foundEntry" != x"" ] ; then | |
36 | echo "Error: should not have found: $1 $2" >> "${WORKDIR}/marked.log" | |
37 | return 1; | |
38 | else | |
39 | echo "Correctly not found: $1 $2" >> "${WORKDIR}/marked.log" | |
40 | return 0; | |
41 | fi | |
42 | } | |
43 | ||
abd66f22 MO |
44 | check_status_options() { |
45 | (cd "$1" && | |
46 | GIT_CONFIG="$git_config" cvs -Q status "$2" > "${WORKDIR}/status.out" 2>&1 | |
47 | ) | |
48 | if [ x"$?" != x"0" ] ; then | |
49 | echo "Error from cvs status: $1 $2" >> "${WORKDIR}/marked.log" | |
50 | return 1; | |
51 | fi | |
db7fde9c | 52 | got="$(sed -n -e 's/^[ ]*Sticky Options:[ ]*//p' "${WORKDIR}/status.out")" |
abd66f22 MO |
53 | expect="$3" |
54 | if [ x"$expect" = x"" ] ; then | |
55 | expect="(none)" | |
56 | fi | |
57 | test x"$got" = x"$expect" | |
58 | stat=$? | |
59 | echo "cvs status: $1 $2 $stat '$3' '$got'" >> "${WORKDIR}/marked.log" | |
60 | return $stat | |
61 | } | |
62 | ||
8a06a632 MO |
63 | cvs >/dev/null 2>&1 |
64 | if test $? -ne 1 | |
65 | then | |
fadb5156 | 66 | skip_all='skipping git-cvsserver tests, cvs not found' |
8a06a632 | 67 | test_done |
8a06a632 | 68 | fi |
1b19ccd2 JK |
69 | if ! test_have_prereq PERL |
70 | then | |
fadb5156 | 71 | skip_all='skipping git-cvsserver tests, perl not available' |
1b19ccd2 JK |
72 | test_done |
73 | fi | |
94221d22 | 74 | perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || { |
fadb5156 | 75 | skip_all='skipping git-cvsserver tests, Perl SQLite interface unavailable' |
8a06a632 | 76 | test_done |
8a06a632 MO |
77 | } |
78 | ||
79 | unset GIT_DIR GIT_CONFIG | |
fd318a94 JS |
80 | WORKDIR=$PWD |
81 | SERVERDIR=$PWD/gitcvs.git | |
8a06a632 MO |
82 | git_config="$SERVERDIR/config" |
83 | CVSROOT=":fork:$SERVERDIR" | |
fd318a94 | 84 | CVSWORK="$PWD/cvswork" |
8a06a632 MO |
85 | CVS_SERVER=git-cvsserver |
86 | export CVSROOT CVS_SERVER | |
87 | ||
88 | rm -rf "$CVSWORK" "$SERVERDIR" | |
89 | test_expect_success 'setup' ' | |
e2a83b21 | 90 | git config push.default matching && |
8a06a632 MO |
91 | echo "Simple text file" >textfile.c && |
92 | echo "File with embedded NUL: Q <- there" | q_to_nul > binfile.bin && | |
93 | mkdir subdir && | |
94 | echo "Another text file" > subdir/file.h && | |
95 | echo "Another binary: Q (this time CR)" | q_to_cr > subdir/withCr.bin && | |
a48fcd83 | 96 | echo "Mixed up NUL, but marked text: Q <- there" | q_to_nul > mixedUp.c && |
8a06a632 MO |
97 | echo "Unspecified" > subdir/unspecified.other && |
98 | echo "/*.bin -crlf" > .gitattributes && | |
99 | echo "/*.c crlf" >> .gitattributes && | |
100 | echo "subdir/*.bin -crlf" >> .gitattributes && | |
101 | echo "subdir/*.c crlf" >> .gitattributes && | |
102 | echo "subdir/file.h crlf" >> .gitattributes && | |
103 | git add .gitattributes textfile.c binfile.bin mixedUp.c subdir/* && | |
104 | git commit -q -m "First Commit" && | |
7fd3ef1f | 105 | git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 && |
8a06a632 MO |
106 | GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true && |
107 | GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" | |
108 | ' | |
109 | ||
110 | test_expect_success 'cvs co (default crlf)' ' | |
a881baa2 | 111 | GIT_CONFIG="$git_config" cvs -Q co -d cvswork main >cvs.log 2>&1 && |
8a06a632 MO |
112 | test x"$(grep '/-k' cvswork/CVS/Entries cvswork/subdir/CVS/Entries)" = x"" |
113 | ' | |
114 | ||
115 | rm -rf cvswork | |
116 | test_expect_success 'cvs co (allbinary)' ' | |
117 | GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary true && | |
a881baa2 | 118 | GIT_CONFIG="$git_config" cvs -Q co -d cvswork main >cvs.log 2>&1 && |
8a06a632 MO |
119 | marked_as cvswork textfile.c -kb && |
120 | marked_as cvswork binfile.bin -kb && | |
121 | marked_as cvswork .gitattributes -kb && | |
122 | marked_as cvswork mixedUp.c -kb && | |
123 | marked_as cvswork/subdir withCr.bin -kb && | |
124 | marked_as cvswork/subdir file.h -kb && | |
125 | marked_as cvswork/subdir unspecified.other -kb | |
126 | ' | |
127 | ||
128 | rm -rf cvswork cvs.log | |
129 | test_expect_success 'cvs co (use attributes/allbinary)' ' | |
130 | GIT_DIR="$SERVERDIR" git config --bool gitcvs.usecrlfattr true && | |
a881baa2 | 131 | GIT_CONFIG="$git_config" cvs -Q co -d cvswork main >cvs.log 2>&1 && |
8a06a632 MO |
132 | marked_as cvswork textfile.c "" && |
133 | marked_as cvswork binfile.bin -kb && | |
134 | marked_as cvswork .gitattributes -kb && | |
135 | marked_as cvswork mixedUp.c "" && | |
136 | marked_as cvswork/subdir withCr.bin -kb && | |
137 | marked_as cvswork/subdir file.h "" && | |
138 | marked_as cvswork/subdir unspecified.other -kb | |
139 | ' | |
140 | ||
141 | rm -rf cvswork | |
142 | test_expect_success 'cvs co (use attributes)' ' | |
143 | GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary false && | |
a881baa2 | 144 | GIT_CONFIG="$git_config" cvs -Q co -d cvswork main >cvs.log 2>&1 && |
8a06a632 MO |
145 | marked_as cvswork textfile.c "" && |
146 | marked_as cvswork binfile.bin -kb && | |
147 | marked_as cvswork .gitattributes "" && | |
148 | marked_as cvswork mixedUp.c "" && | |
149 | marked_as cvswork/subdir withCr.bin -kb && | |
150 | marked_as cvswork/subdir file.h "" && | |
151 | marked_as cvswork/subdir unspecified.other "" | |
152 | ' | |
153 | ||
154 | test_expect_success 'adding files' ' | |
fd4ec4f2 JL |
155 | (cd cvswork && |
156 | (cd subdir && | |
8a06a632 MO |
157 | echo "more text" > src.c && |
158 | GIT_CONFIG="$git_config" cvs -Q add src.c >cvs.log 2>&1 && | |
159 | marked_as . src.c "" && | |
2e3a16b2 | 160 | echo "pseudo-binary" > temp.bin |
fd4ec4f2 | 161 | ) && |
8a06a632 MO |
162 | GIT_CONFIG="$git_config" cvs -Q add subdir/temp.bin >cvs.log 2>&1 && |
163 | marked_as subdir temp.bin "-kb" && | |
164 | cd subdir && | |
165 | GIT_CONFIG="$git_config" cvs -Q ci -m "adding files" >cvs.log 2>&1 && | |
166 | marked_as . temp.bin "-kb" && | |
167 | marked_as . src.c "" | |
fd4ec4f2 | 168 | ) |
8a06a632 MO |
169 | ' |
170 | ||
8a06a632 MO |
171 | test_expect_success 'updating' ' |
172 | git pull gitcvs.git && | |
c76b84a1 MÅ |
173 | echo "hi" >subdir/newfile.bin && |
174 | echo "junk" >subdir/file.h && | |
175 | echo "hi" >subdir/newfile.c && | |
176 | echo "hello" >>binfile.bin && | |
8a06a632 MO |
177 | git add subdir/newfile.bin subdir/file.h subdir/newfile.c binfile.bin && |
178 | git commit -q -m "Add and change some files" && | |
179 | git push gitcvs.git >/dev/null && | |
fd4ec4f2 JL |
180 | (cd cvswork && |
181 | GIT_CONFIG="$git_config" cvs -Q update | |
182 | ) && | |
8a06a632 MO |
183 | marked_as cvswork textfile.c "" && |
184 | marked_as cvswork binfile.bin -kb && | |
185 | marked_as cvswork .gitattributes "" && | |
186 | marked_as cvswork mixedUp.c "" && | |
187 | marked_as cvswork/subdir withCr.bin -kb && | |
188 | marked_as cvswork/subdir file.h "" && | |
189 | marked_as cvswork/subdir unspecified.other "" && | |
190 | marked_as cvswork/subdir newfile.bin -kb && | |
191 | marked_as cvswork/subdir newfile.c "" && | |
192 | echo "File with embedded NUL: Q <- there" | q_to_nul > tmpExpect1 && | |
193 | echo "hello" >> tmpExpect1 && | |
194 | cmp cvswork/binfile.bin tmpExpect1 | |
195 | ' | |
196 | ||
90948a42 MO |
197 | rm -rf cvswork |
198 | test_expect_success 'cvs co (use attributes/guess)' ' | |
199 | GIT_DIR="$SERVERDIR" git config gitcvs.allbinary guess && | |
a881baa2 | 200 | GIT_CONFIG="$git_config" cvs -Q co -d cvswork main >cvs.log 2>&1 && |
90948a42 MO |
201 | marked_as cvswork textfile.c "" && |
202 | marked_as cvswork binfile.bin -kb && | |
203 | marked_as cvswork .gitattributes "" && | |
204 | marked_as cvswork mixedUp.c "" && | |
205 | marked_as cvswork/subdir withCr.bin -kb && | |
206 | marked_as cvswork/subdir file.h "" && | |
207 | marked_as cvswork/subdir unspecified.other "" && | |
208 | marked_as cvswork/subdir newfile.bin -kb && | |
209 | marked_as cvswork/subdir newfile.c "" | |
210 | ' | |
211 | ||
212 | test_expect_success 'setup multi-line files' ' | |
213 | ( echo "line 1" && | |
214 | echo "line 2" && | |
215 | echo "line 3" && | |
216 | echo "line 4 with NUL: Q <-" ) | q_to_nul > multiline.c && | |
217 | git add multiline.c && | |
218 | ( echo "line 1" && | |
219 | echo "line 2" && | |
220 | echo "line 3" && | |
221 | echo "line 4" ) | q_to_nul > multilineTxt.c && | |
222 | git add multilineTxt.c && | |
223 | git commit -q -m "multiline files" && | |
224 | git push gitcvs.git >/dev/null | |
225 | ' | |
226 | ||
227 | rm -rf cvswork | |
228 | test_expect_success 'cvs co (guess)' ' | |
229 | GIT_DIR="$SERVERDIR" git config --bool gitcvs.usecrlfattr false && | |
a881baa2 | 230 | GIT_CONFIG="$git_config" cvs -Q co -d cvswork main >cvs.log 2>&1 && |
90948a42 MO |
231 | marked_as cvswork textfile.c "" && |
232 | marked_as cvswork binfile.bin -kb && | |
233 | marked_as cvswork .gitattributes "" && | |
234 | marked_as cvswork mixedUp.c -kb && | |
235 | marked_as cvswork multiline.c -kb && | |
236 | marked_as cvswork multilineTxt.c "" && | |
237 | marked_as cvswork/subdir withCr.bin -kb && | |
238 | marked_as cvswork/subdir file.h "" && | |
239 | marked_as cvswork/subdir unspecified.other "" && | |
240 | marked_as cvswork/subdir newfile.bin "" && | |
241 | marked_as cvswork/subdir newfile.c "" | |
242 | ' | |
243 | ||
244 | test_expect_success 'cvs co another copy (guess)' ' | |
a881baa2 | 245 | GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 && |
90948a42 MO |
246 | marked_as cvswork2 textfile.c "" && |
247 | marked_as cvswork2 binfile.bin -kb && | |
248 | marked_as cvswork2 .gitattributes "" && | |
249 | marked_as cvswork2 mixedUp.c -kb && | |
250 | marked_as cvswork2 multiline.c -kb && | |
251 | marked_as cvswork2 multilineTxt.c "" && | |
252 | marked_as cvswork2/subdir withCr.bin -kb && | |
253 | marked_as cvswork2/subdir file.h "" && | |
254 | marked_as cvswork2/subdir unspecified.other "" && | |
255 | marked_as cvswork2/subdir newfile.bin "" && | |
256 | marked_as cvswork2/subdir newfile.c "" | |
257 | ' | |
258 | ||
abd66f22 MO |
259 | test_expect_success 'cvs status - sticky options' ' |
260 | check_status_options cvswork2 textfile.c "" && | |
261 | check_status_options cvswork2 binfile.bin -kb && | |
262 | check_status_options cvswork2 .gitattributes "" && | |
263 | check_status_options cvswork2 mixedUp.c -kb && | |
264 | check_status_options cvswork2 multiline.c -kb && | |
265 | check_status_options cvswork2 multilineTxt.c "" && | |
266 | check_status_options cvswork2/subdir withCr.bin -kb && | |
267 | check_status_options cvswork2 subdir/withCr.bin -kb && | |
268 | check_status_options cvswork2/subdir file.h "" && | |
269 | check_status_options cvswork2 subdir/file.h "" && | |
270 | check_status_options cvswork2/subdir unspecified.other "" && | |
271 | check_status_options cvswork2/subdir newfile.bin "" && | |
272 | check_status_options cvswork2/subdir newfile.c "" | |
273 | ' | |
274 | ||
90948a42 | 275 | test_expect_success 'add text (guess)' ' |
fd4ec4f2 | 276 | (cd cvswork && |
90948a42 | 277 | echo "simpleText" > simpleText.c && |
fd4ec4f2 JL |
278 | GIT_CONFIG="$git_config" cvs -Q add simpleText.c |
279 | ) && | |
90948a42 MO |
280 | marked_as cvswork simpleText.c "" |
281 | ' | |
282 | ||
283 | test_expect_success 'add bin (guess)' ' | |
fd4ec4f2 | 284 | (cd cvswork && |
90948a42 | 285 | echo "simpleBin: NUL: Q <- there" | q_to_nul > simpleBin.bin && |
fd4ec4f2 JL |
286 | GIT_CONFIG="$git_config" cvs -Q add simpleBin.bin |
287 | ) && | |
90948a42 MO |
288 | marked_as cvswork simpleBin.bin -kb |
289 | ' | |
290 | ||
291 | test_expect_success 'remove files (guess)' ' | |
fd4ec4f2 | 292 | (cd cvswork && |
90948a42 | 293 | GIT_CONFIG="$git_config" cvs -Q rm -f subdir/file.h && |
fd4ec4f2 JL |
294 | (cd subdir && |
295 | GIT_CONFIG="$git_config" cvs -Q rm -f withCr.bin | |
296 | )) && | |
90948a42 MO |
297 | marked_as cvswork/subdir withCr.bin -kb && |
298 | marked_as cvswork/subdir file.h "" | |
299 | ' | |
300 | ||
301 | test_expect_success 'cvs ci (guess)' ' | |
fd4ec4f2 JL |
302 | (cd cvswork && |
303 | GIT_CONFIG="$git_config" cvs -Q ci -m "add/rm files" >cvs.log 2>&1 | |
304 | ) && | |
90948a42 MO |
305 | marked_as cvswork textfile.c "" && |
306 | marked_as cvswork binfile.bin -kb && | |
307 | marked_as cvswork .gitattributes "" && | |
308 | marked_as cvswork mixedUp.c -kb && | |
309 | marked_as cvswork multiline.c -kb && | |
310 | marked_as cvswork multilineTxt.c "" && | |
311 | not_present cvswork/subdir withCr.bin && | |
312 | not_present cvswork/subdir file.h && | |
313 | marked_as cvswork/subdir unspecified.other "" && | |
314 | marked_as cvswork/subdir newfile.bin "" && | |
315 | marked_as cvswork/subdir newfile.c "" && | |
316 | marked_as cvswork simpleBin.bin -kb && | |
317 | marked_as cvswork simpleText.c "" | |
318 | ' | |
319 | ||
320 | test_expect_success 'update subdir of other copy (guess)' ' | |
fd4ec4f2 JL |
321 | (cd cvswork2/subdir && |
322 | GIT_CONFIG="$git_config" cvs -Q update | |
323 | ) && | |
90948a42 MO |
324 | marked_as cvswork2 textfile.c "" && |
325 | marked_as cvswork2 binfile.bin -kb && | |
326 | marked_as cvswork2 .gitattributes "" && | |
327 | marked_as cvswork2 mixedUp.c -kb && | |
328 | marked_as cvswork2 multiline.c -kb && | |
329 | marked_as cvswork2 multilineTxt.c "" && | |
330 | not_present cvswork2/subdir withCr.bin && | |
331 | not_present cvswork2/subdir file.h && | |
332 | marked_as cvswork2/subdir unspecified.other "" && | |
333 | marked_as cvswork2/subdir newfile.bin "" && | |
334 | marked_as cvswork2/subdir newfile.c "" && | |
335 | not_present cvswork2 simpleBin.bin && | |
336 | not_present cvswork2 simpleText.c | |
337 | ' | |
338 | ||
339 | echo "starting update/merge" >> "${WORKDIR}/marked.log" | |
340 | test_expect_success 'update/merge full other copy (guess)' ' | |
a881baa2 | 341 | git pull gitcvs.git main && |
90948a42 MO |
342 | sed "s/3/replaced_3/" < multilineTxt.c > ml.temp && |
343 | mv ml.temp multilineTxt.c && | |
344 | git add multilineTxt.c && | |
345 | git commit -q -m "modify multiline file" >> "${WORKDIR}/marked.log" && | |
346 | git push gitcvs.git >/dev/null && | |
fd4ec4f2 | 347 | (cd cvswork2 && |
90948a42 MO |
348 | sed "s/1/replaced_1/" < multilineTxt.c > ml.temp && |
349 | mv ml.temp multilineTxt.c && | |
fd4ec4f2 JL |
350 | GIT_CONFIG="$git_config" cvs update > cvs.log 2>&1 |
351 | ) && | |
90948a42 MO |
352 | marked_as cvswork2 textfile.c "" && |
353 | marked_as cvswork2 binfile.bin -kb && | |
354 | marked_as cvswork2 .gitattributes "" && | |
355 | marked_as cvswork2 mixedUp.c -kb && | |
356 | marked_as cvswork2 multiline.c -kb && | |
357 | marked_as cvswork2 multilineTxt.c "" && | |
358 | not_present cvswork2/subdir withCr.bin && | |
359 | not_present cvswork2/subdir file.h && | |
360 | marked_as cvswork2/subdir unspecified.other "" && | |
361 | marked_as cvswork2/subdir newfile.bin "" && | |
362 | marked_as cvswork2/subdir newfile.c "" && | |
363 | marked_as cvswork2 simpleBin.bin -kb && | |
364 | marked_as cvswork2 simpleText.c "" && | |
365 | echo "line replaced_1" > tmpExpect2 && | |
366 | echo "line 2" >> tmpExpect2 && | |
367 | echo "line replaced_3" >> tmpExpect2 && | |
368 | echo "line 4" | q_to_nul >> tmpExpect2 && | |
369 | cmp cvswork2/multilineTxt.c tmpExpect2 | |
370 | ' | |
371 | ||
8a06a632 | 372 | test_done |