user-manual: the name of the hash function is SHA-1, not sha1
[git/mingw.git] / t / t9401-git-cvsserver-crlf.sh
blob12e0e508226cb9197ad3f419387dfcfb3ab9e0d9
1 #!/bin/sh
3 # Copyright (c) 2008 Matthew Ogilvie
4 # Parts adapted from other tests.
7 test_description='git-cvsserver -kb modes
9 tests -kb mode for binary files when accessing a git
10 repository using cvs CLI client via git-cvsserver server'
12 . ./test-lib.sh
14 q_to_nul () {
15 perl -pe 'y/Q/\000/'
18 q_to_cr () {
19 tr Q '\015'
22 marked_as () {
23 foundEntry="$(grep "^/$2/" "$1/CVS/Entries")"
24 if [ x"$foundEntry" = x"" ] ; then
25 echo "NOT FOUND: $1 $2 1 $3" >> "${WORKDIR}/marked.log"
26 return 1
28 test x"$(grep "^/$2/" "$1/CVS/Entries" | cut -d/ -f5)" = x"$3"
29 stat=$?
30 echo "$1 $2 $stat '$3'" >> "${WORKDIR}/marked.log"
31 return $stat
34 not_present() {
35 foundEntry="$(grep "^/$2/" "$1/CVS/Entries")"
36 if [ -r "$1/$2" ] ; then
37 echo "Error: File still exists: $1 $2" >> "${WORKDIR}/marked.log"
38 return 1;
40 if [ x"$foundEntry" != x"" ] ; then
41 echo "Error: should not have found: $1 $2" >> "${WORKDIR}/marked.log"
42 return 1;
43 else
44 echo "Correctly not found: $1 $2" >> "${WORKDIR}/marked.log"
45 return 0;
49 cvs >/dev/null 2>&1
50 if test $? -ne 1
51 then
52 say 'skipping git-cvsserver tests, cvs not found'
53 test_done
55 perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
56 say 'skipping git-cvsserver tests, Perl SQLite interface unavailable'
57 test_done
60 unset GIT_DIR GIT_CONFIG
61 WORKDIR=$(pwd)
62 SERVERDIR=$(pwd)/gitcvs.git
63 git_config="$SERVERDIR/config"
64 CVSROOT=":fork:$SERVERDIR"
65 CVSWORK="$(pwd)/cvswork"
66 CVS_SERVER=git-cvsserver
67 export CVSROOT CVS_SERVER
69 rm -rf "$CVSWORK" "$SERVERDIR"
70 test_expect_success 'setup' '
71 echo "Simple text file" >textfile.c &&
72 echo "File with embedded NUL: Q <- there" | q_to_nul > binfile.bin &&
73 mkdir subdir &&
74 echo "Another text file" > subdir/file.h &&
75 echo "Another binary: Q (this time CR)" | q_to_cr > subdir/withCr.bin &&
76 echo "Mixed up NUL, but marked text: Q <- there" | q_to_nul > mixedUp.c
77 echo "Unspecified" > subdir/unspecified.other &&
78 echo "/*.bin -crlf" > .gitattributes &&
79 echo "/*.c crlf" >> .gitattributes &&
80 echo "subdir/*.bin -crlf" >> .gitattributes &&
81 echo "subdir/*.c crlf" >> .gitattributes &&
82 echo "subdir/file.h crlf" >> .gitattributes &&
83 git add .gitattributes textfile.c binfile.bin mixedUp.c subdir/* &&
84 git commit -q -m "First Commit" &&
85 git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
86 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
87 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
90 test_expect_success 'cvs co (default crlf)' '
91 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
92 test x"$(grep '/-k' cvswork/CVS/Entries cvswork/subdir/CVS/Entries)" = x""
95 rm -rf cvswork
96 test_expect_success 'cvs co (allbinary)' '
97 GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary true &&
98 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
99 marked_as cvswork textfile.c -kb &&
100 marked_as cvswork binfile.bin -kb &&
101 marked_as cvswork .gitattributes -kb &&
102 marked_as cvswork mixedUp.c -kb &&
103 marked_as cvswork/subdir withCr.bin -kb &&
104 marked_as cvswork/subdir file.h -kb &&
105 marked_as cvswork/subdir unspecified.other -kb
108 rm -rf cvswork cvs.log
109 test_expect_success 'cvs co (use attributes/allbinary)' '
110 GIT_DIR="$SERVERDIR" git config --bool gitcvs.usecrlfattr true &&
111 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
112 marked_as cvswork textfile.c "" &&
113 marked_as cvswork binfile.bin -kb &&
114 marked_as cvswork .gitattributes -kb &&
115 marked_as cvswork mixedUp.c "" &&
116 marked_as cvswork/subdir withCr.bin -kb &&
117 marked_as cvswork/subdir file.h "" &&
118 marked_as cvswork/subdir unspecified.other -kb
121 rm -rf cvswork
122 test_expect_success 'cvs co (use attributes)' '
123 GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary false &&
124 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
125 marked_as cvswork textfile.c "" &&
126 marked_as cvswork binfile.bin -kb &&
127 marked_as cvswork .gitattributes "" &&
128 marked_as cvswork mixedUp.c "" &&
129 marked_as cvswork/subdir withCr.bin -kb &&
130 marked_as cvswork/subdir file.h "" &&
131 marked_as cvswork/subdir unspecified.other ""
134 test_expect_success 'adding files' '
135 cd cvswork/subdir &&
136 echo "more text" > src.c &&
137 GIT_CONFIG="$git_config" cvs -Q add src.c >cvs.log 2>&1 &&
138 marked_as . src.c "" &&
139 echo "psuedo-binary" > temp.bin &&
140 cd .. &&
141 GIT_CONFIG="$git_config" cvs -Q add subdir/temp.bin >cvs.log 2>&1 &&
142 marked_as subdir temp.bin "-kb" &&
143 cd subdir &&
144 GIT_CONFIG="$git_config" cvs -Q ci -m "adding files" >cvs.log 2>&1 &&
145 marked_as . temp.bin "-kb" &&
146 marked_as . src.c ""
149 cd "$WORKDIR"
150 test_expect_success 'updating' '
151 git pull gitcvs.git &&
152 echo 'hi' > subdir/newfile.bin &&
153 echo 'junk' > subdir/file.h &&
154 echo 'hi' > subdir/newfile.c &&
155 echo 'hello' >> binfile.bin &&
156 git add subdir/newfile.bin subdir/file.h subdir/newfile.c binfile.bin &&
157 git commit -q -m "Add and change some files" &&
158 git push gitcvs.git >/dev/null &&
159 cd cvswork &&
160 GIT_CONFIG="$git_config" cvs -Q update &&
161 cd .. &&
162 marked_as cvswork textfile.c "" &&
163 marked_as cvswork binfile.bin -kb &&
164 marked_as cvswork .gitattributes "" &&
165 marked_as cvswork mixedUp.c "" &&
166 marked_as cvswork/subdir withCr.bin -kb &&
167 marked_as cvswork/subdir file.h "" &&
168 marked_as cvswork/subdir unspecified.other "" &&
169 marked_as cvswork/subdir newfile.bin -kb &&
170 marked_as cvswork/subdir newfile.c "" &&
171 echo "File with embedded NUL: Q <- there" | q_to_nul > tmpExpect1 &&
172 echo "hello" >> tmpExpect1 &&
173 cmp cvswork/binfile.bin tmpExpect1
176 rm -rf cvswork
177 test_expect_success 'cvs co (use attributes/guess)' '
178 GIT_DIR="$SERVERDIR" git config gitcvs.allbinary guess &&
179 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
180 marked_as cvswork textfile.c "" &&
181 marked_as cvswork binfile.bin -kb &&
182 marked_as cvswork .gitattributes "" &&
183 marked_as cvswork mixedUp.c "" &&
184 marked_as cvswork/subdir withCr.bin -kb &&
185 marked_as cvswork/subdir file.h "" &&
186 marked_as cvswork/subdir unspecified.other "" &&
187 marked_as cvswork/subdir newfile.bin -kb &&
188 marked_as cvswork/subdir newfile.c ""
191 test_expect_success 'setup multi-line files' '
192 ( echo "line 1" &&
193 echo "line 2" &&
194 echo "line 3" &&
195 echo "line 4 with NUL: Q <-" ) | q_to_nul > multiline.c &&
196 git add multiline.c &&
197 ( echo "line 1" &&
198 echo "line 2" &&
199 echo "line 3" &&
200 echo "line 4" ) | q_to_nul > multilineTxt.c &&
201 git add multilineTxt.c &&
202 git commit -q -m "multiline files" &&
203 git push gitcvs.git >/dev/null
206 rm -rf cvswork
207 test_expect_success 'cvs co (guess)' '
208 GIT_DIR="$SERVERDIR" git config --bool gitcvs.usecrlfattr false &&
209 GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
210 marked_as cvswork textfile.c "" &&
211 marked_as cvswork binfile.bin -kb &&
212 marked_as cvswork .gitattributes "" &&
213 marked_as cvswork mixedUp.c -kb &&
214 marked_as cvswork multiline.c -kb &&
215 marked_as cvswork multilineTxt.c "" &&
216 marked_as cvswork/subdir withCr.bin -kb &&
217 marked_as cvswork/subdir file.h "" &&
218 marked_as cvswork/subdir unspecified.other "" &&
219 marked_as cvswork/subdir newfile.bin "" &&
220 marked_as cvswork/subdir newfile.c ""
223 test_expect_success 'cvs co another copy (guess)' '
224 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
225 marked_as cvswork2 textfile.c "" &&
226 marked_as cvswork2 binfile.bin -kb &&
227 marked_as cvswork2 .gitattributes "" &&
228 marked_as cvswork2 mixedUp.c -kb &&
229 marked_as cvswork2 multiline.c -kb &&
230 marked_as cvswork2 multilineTxt.c "" &&
231 marked_as cvswork2/subdir withCr.bin -kb &&
232 marked_as cvswork2/subdir file.h "" &&
233 marked_as cvswork2/subdir unspecified.other "" &&
234 marked_as cvswork2/subdir newfile.bin "" &&
235 marked_as cvswork2/subdir newfile.c ""
238 test_expect_success 'add text (guess)' '
239 cd cvswork &&
240 echo "simpleText" > simpleText.c &&
241 GIT_CONFIG="$git_config" cvs -Q add simpleText.c &&
242 cd .. &&
243 marked_as cvswork simpleText.c ""
246 test_expect_success 'add bin (guess)' '
247 cd cvswork &&
248 echo "simpleBin: NUL: Q <- there" | q_to_nul > simpleBin.bin &&
249 GIT_CONFIG="$git_config" cvs -Q add simpleBin.bin &&
250 cd .. &&
251 marked_as cvswork simpleBin.bin -kb
254 test_expect_success 'remove files (guess)' '
255 cd cvswork &&
256 GIT_CONFIG="$git_config" cvs -Q rm -f subdir/file.h &&
257 cd subdir &&
258 GIT_CONFIG="$git_config" cvs -Q rm -f withCr.bin &&
259 cd ../.. &&
260 marked_as cvswork/subdir withCr.bin -kb &&
261 marked_as cvswork/subdir file.h ""
264 test_expect_success 'cvs ci (guess)' '
265 cd cvswork &&
266 GIT_CONFIG="$git_config" cvs -Q ci -m "add/rm files" >cvs.log 2>&1 &&
267 cd .. &&
268 marked_as cvswork textfile.c "" &&
269 marked_as cvswork binfile.bin -kb &&
270 marked_as cvswork .gitattributes "" &&
271 marked_as cvswork mixedUp.c -kb &&
272 marked_as cvswork multiline.c -kb &&
273 marked_as cvswork multilineTxt.c "" &&
274 not_present cvswork/subdir withCr.bin &&
275 not_present cvswork/subdir file.h &&
276 marked_as cvswork/subdir unspecified.other "" &&
277 marked_as cvswork/subdir newfile.bin "" &&
278 marked_as cvswork/subdir newfile.c "" &&
279 marked_as cvswork simpleBin.bin -kb &&
280 marked_as cvswork simpleText.c ""
283 test_expect_success 'update subdir of other copy (guess)' '
284 cd cvswork2/subdir &&
285 GIT_CONFIG="$git_config" cvs -Q update &&
286 cd ../.. &&
287 marked_as cvswork2 textfile.c "" &&
288 marked_as cvswork2 binfile.bin -kb &&
289 marked_as cvswork2 .gitattributes "" &&
290 marked_as cvswork2 mixedUp.c -kb &&
291 marked_as cvswork2 multiline.c -kb &&
292 marked_as cvswork2 multilineTxt.c "" &&
293 not_present cvswork2/subdir withCr.bin &&
294 not_present cvswork2/subdir file.h &&
295 marked_as cvswork2/subdir unspecified.other "" &&
296 marked_as cvswork2/subdir newfile.bin "" &&
297 marked_as cvswork2/subdir newfile.c "" &&
298 not_present cvswork2 simpleBin.bin &&
299 not_present cvswork2 simpleText.c
302 echo "starting update/merge" >> "${WORKDIR}/marked.log"
303 test_expect_success 'update/merge full other copy (guess)' '
304 git pull gitcvs.git master &&
305 sed "s/3/replaced_3/" < multilineTxt.c > ml.temp &&
306 mv ml.temp multilineTxt.c &&
307 git add multilineTxt.c &&
308 git commit -q -m "modify multiline file" >> "${WORKDIR}/marked.log" &&
309 git push gitcvs.git >/dev/null &&
310 cd cvswork2 &&
311 sed "s/1/replaced_1/" < multilineTxt.c > ml.temp &&
312 mv ml.temp multilineTxt.c &&
313 GIT_CONFIG="$git_config" cvs update > cvs.log 2>&1 &&
314 cd .. &&
315 marked_as cvswork2 textfile.c "" &&
316 marked_as cvswork2 binfile.bin -kb &&
317 marked_as cvswork2 .gitattributes "" &&
318 marked_as cvswork2 mixedUp.c -kb &&
319 marked_as cvswork2 multiline.c -kb &&
320 marked_as cvswork2 multilineTxt.c "" &&
321 not_present cvswork2/subdir withCr.bin &&
322 not_present cvswork2/subdir file.h &&
323 marked_as cvswork2/subdir unspecified.other "" &&
324 marked_as cvswork2/subdir newfile.bin "" &&
325 marked_as cvswork2/subdir newfile.c "" &&
326 marked_as cvswork2 simpleBin.bin -kb &&
327 marked_as cvswork2 simpleText.c "" &&
328 echo "line replaced_1" > tmpExpect2 &&
329 echo "line 2" >> tmpExpect2 &&
330 echo "line replaced_3" >> tmpExpect2 &&
331 echo "line 4" | q_to_nul >> tmpExpect2 &&
332 cmp cvswork2/multilineTxt.c tmpExpect2
335 test_done