1#!/bin/sh 2# 3# Copyright (c) 2008 Matthew Ogilvie 4# Parts adapted from other tests. 5# 6 7test_description='git-cvsserver -kb modes 8 9tests -kb mode for binary files when accessing a git 10repository using cvs CLI client via git-cvsserver server' 11 12GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 13export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 14 15. ./test-lib.sh 16 17marked_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 29not_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 44check_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 52 got="$(sed -n -e 's/^[ ]*Sticky Options:[ ]*//p' "${WORKDIR}/status.out")" 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 63cvs >/dev/null 2>&1 64if test $? -ne 1 65then 66 skip_all='skipping git-cvsserver tests, cvs not found' 67 test_done 68fi 69if ! test_have_prereq PERL 70then 71 skip_all='skipping git-cvsserver tests, perl not available' 72 test_done 73fi 74perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || { 75 skip_all='skipping git-cvsserver tests, Perl SQLite interface unavailable' 76 test_done 77} 78 79unset GIT_DIR GIT_CONFIG 80WORKDIR=$PWD 81SERVERDIR=$PWD/gitcvs.git 82git_config="$SERVERDIR/config" 83CVSROOT=":fork:$SERVERDIR" 84CVSWORK="$PWD/cvswork" 85CVS_SERVER=git-cvsserver 86export CVSROOT CVS_SERVER 87 88rm -rf "$CVSWORK" "$SERVERDIR" 89test_expect_success 'setup' ' 90 git config push.default matching && 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 && 96 echo "Mixed up NUL, but marked text: Q <- there" | q_to_nul > mixedUp.c && 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" && 105 git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 && 106 GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true && 107 GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" 108' 109 110test_expect_success 'cvs co (default crlf)' ' 111 GIT_CONFIG="$git_config" cvs -Q co -d cvswork main >cvs.log 2>&1 && 112 test x"$(grep '/-k' cvswork/CVS/Entries cvswork/subdir/CVS/Entries)" = x"" 113' 114 115rm -rf cvswork 116test_expect_success 'cvs co (allbinary)' ' 117 GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary true && 118 GIT_CONFIG="$git_config" cvs -Q co -d cvswork main >cvs.log 2>&1 && 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 128rm -rf cvswork cvs.log 129test_expect_success 'cvs co (use attributes/allbinary)' ' 130 GIT_DIR="$SERVERDIR" git config --bool gitcvs.usecrlfattr true && 131 GIT_CONFIG="$git_config" cvs -Q co -d cvswork main >cvs.log 2>&1 && 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 141rm -rf cvswork 142test_expect_success 'cvs co (use attributes)' ' 143 GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary false && 144 GIT_CONFIG="$git_config" cvs -Q co -d cvswork main >cvs.log 2>&1 && 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 154test_expect_success 'adding files' ' 155 (cd cvswork && 156 (cd subdir && 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 "" && 160 echo "pseudo-binary" > temp.bin 161 ) && 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 "" 168 ) 169' 170 171test_expect_success 'updating' ' 172 git pull gitcvs.git && 173 echo "hi" >subdir/newfile.bin && 174 echo "junk" >subdir/file.h && 175 echo "hi" >subdir/newfile.c && 176 echo "hello" >>binfile.bin && 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 && 180 (cd cvswork && 181 GIT_CONFIG="$git_config" cvs -Q update 182 ) && 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 197rm -rf cvswork 198test_expect_success 'cvs co (use attributes/guess)' ' 199 GIT_DIR="$SERVERDIR" git config gitcvs.allbinary guess && 200 GIT_CONFIG="$git_config" cvs -Q co -d cvswork main >cvs.log 2>&1 && 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 212test_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 227rm -rf cvswork 228test_expect_success 'cvs co (guess)' ' 229 GIT_DIR="$SERVERDIR" git config --bool gitcvs.usecrlfattr false && 230 GIT_CONFIG="$git_config" cvs -Q co -d cvswork main >cvs.log 2>&1 && 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 244test_expect_success 'cvs co another copy (guess)' ' 245 GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 main >cvs.log 2>&1 && 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 259test_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 275test_expect_success 'add text (guess)' ' 276 (cd cvswork && 277 echo "simpleText" > simpleText.c && 278 GIT_CONFIG="$git_config" cvs -Q add simpleText.c 279 ) && 280 marked_as cvswork simpleText.c "" 281' 282 283test_expect_success 'add bin (guess)' ' 284 (cd cvswork && 285 echo "simpleBin: NUL: Q <- there" | q_to_nul > simpleBin.bin && 286 GIT_CONFIG="$git_config" cvs -Q add simpleBin.bin 287 ) && 288 marked_as cvswork simpleBin.bin -kb 289' 290 291test_expect_success 'remove files (guess)' ' 292 (cd cvswork && 293 GIT_CONFIG="$git_config" cvs -Q rm -f subdir/file.h && 294 (cd subdir && 295 GIT_CONFIG="$git_config" cvs -Q rm -f withCr.bin 296 )) && 297 marked_as cvswork/subdir withCr.bin -kb && 298 marked_as cvswork/subdir file.h "" 299' 300 301test_expect_success 'cvs ci (guess)' ' 302 (cd cvswork && 303 GIT_CONFIG="$git_config" cvs -Q ci -m "add/rm files" >cvs.log 2>&1 304 ) && 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 320test_expect_success 'update subdir of other copy (guess)' ' 321 (cd cvswork2/subdir && 322 GIT_CONFIG="$git_config" cvs -Q update 323 ) && 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 339echo "starting update/merge" >> "${WORKDIR}/marked.log" 340test_expect_success 'update/merge full other copy (guess)' ' 341 git pull gitcvs.git main && 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 && 347 (cd cvswork2 && 348 sed "s/1/replaced_1/" < multilineTxt.c > ml.temp && 349 mv ml.temp multilineTxt.c && 350 GIT_CONFIG="$git_config" cvs update > cvs.log 2>&1 351 ) && 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 372test_done 373