t / t9401-git-cvsserver-crlf.shon commit Merge git://git.kernel.org/pub/scm/gitk/gitk (847d10f)
   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
  12. ./test-lib.sh
  13
  14q_to_nul () {
  15    perl -pe 'y/Q/\000/'
  16}
  17
  18q_to_cr () {
  19    tr Q '\015'
  20}
  21
  22marked_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
  27    fi
  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
  32}
  33
  34not_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;
  39    fi
  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;
  46    fi
  47}
  48
  49cvs >/dev/null 2>&1
  50if test $? -ne 1
  51then
  52    test_expect_success 'skipping git-cvsserver tests, cvs not found' :
  53    test_done
  54    exit
  55fi
  56perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
  57    test_expect_success 'skipping git-cvsserver tests, Perl SQLite interface unavailable' :
  58    test_done
  59    exit
  60}
  61
  62unset GIT_DIR GIT_CONFIG
  63WORKDIR=$(pwd)
  64SERVERDIR=$(pwd)/gitcvs.git
  65git_config="$SERVERDIR/config"
  66CVSROOT=":fork:$SERVERDIR"
  67CVSWORK="$(pwd)/cvswork"
  68CVS_SERVER=git-cvsserver
  69export CVSROOT CVS_SERVER
  70
  71rm -rf "$CVSWORK" "$SERVERDIR"
  72test_expect_success 'setup' '
  73    echo "Simple text file" >textfile.c &&
  74    echo "File with embedded NUL: Q <- there" | q_to_nul > binfile.bin &&
  75    mkdir subdir &&
  76    echo "Another text file" > subdir/file.h &&
  77    echo "Another binary: Q (this time CR)" | q_to_cr > subdir/withCr.bin &&
  78    echo "Mixed up NUL, but marked text: Q <- there" | q_to_nul > mixedUp.c
  79    echo "Unspecified" > subdir/unspecified.other &&
  80    echo "/*.bin -crlf" > .gitattributes &&
  81    echo "/*.c crlf" >> .gitattributes &&
  82    echo "subdir/*.bin -crlf" >> .gitattributes &&
  83    echo "subdir/*.c crlf" >> .gitattributes &&
  84    echo "subdir/file.h crlf" >> .gitattributes &&
  85    git add .gitattributes textfile.c binfile.bin mixedUp.c subdir/* &&
  86    git commit -q -m "First Commit" &&
  87    git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
  88    GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
  89    GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
  90'
  91
  92test_expect_success 'cvs co (default crlf)' '
  93    GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
  94    test x"$(grep '/-k' cvswork/CVS/Entries cvswork/subdir/CVS/Entries)" = x""
  95'
  96
  97rm -rf cvswork
  98test_expect_success 'cvs co (allbinary)' '
  99    GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary true &&
 100    GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
 101    marked_as cvswork textfile.c -kb &&
 102    marked_as cvswork binfile.bin -kb &&
 103    marked_as cvswork .gitattributes -kb &&
 104    marked_as cvswork mixedUp.c -kb &&
 105    marked_as cvswork/subdir withCr.bin -kb &&
 106    marked_as cvswork/subdir file.h -kb &&
 107    marked_as cvswork/subdir unspecified.other -kb
 108'
 109
 110rm -rf cvswork cvs.log
 111test_expect_success 'cvs co (use attributes/allbinary)' '
 112    GIT_DIR="$SERVERDIR" git config --bool gitcvs.usecrlfattr true &&
 113    GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
 114    marked_as cvswork textfile.c "" &&
 115    marked_as cvswork binfile.bin -kb &&
 116    marked_as cvswork .gitattributes -kb &&
 117    marked_as cvswork mixedUp.c "" &&
 118    marked_as cvswork/subdir withCr.bin -kb &&
 119    marked_as cvswork/subdir file.h "" &&
 120    marked_as cvswork/subdir unspecified.other -kb
 121'
 122
 123rm -rf cvswork
 124test_expect_success 'cvs co (use attributes)' '
 125    GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary false &&
 126    GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
 127    marked_as cvswork textfile.c "" &&
 128    marked_as cvswork binfile.bin -kb &&
 129    marked_as cvswork .gitattributes "" &&
 130    marked_as cvswork mixedUp.c "" &&
 131    marked_as cvswork/subdir withCr.bin -kb &&
 132    marked_as cvswork/subdir file.h "" &&
 133    marked_as cvswork/subdir unspecified.other ""
 134'
 135
 136test_expect_success 'adding files' '
 137    cd cvswork/subdir &&
 138    echo "more text" > src.c &&
 139    GIT_CONFIG="$git_config" cvs -Q add src.c >cvs.log 2>&1 &&
 140    marked_as . src.c "" &&
 141    echo "psuedo-binary" > temp.bin &&
 142    cd .. &&
 143    GIT_CONFIG="$git_config" cvs -Q add subdir/temp.bin >cvs.log 2>&1 &&
 144    marked_as subdir temp.bin "-kb" &&
 145    cd subdir &&
 146    GIT_CONFIG="$git_config" cvs -Q ci -m "adding files" >cvs.log 2>&1 &&
 147    marked_as . temp.bin "-kb" &&
 148    marked_as . src.c ""
 149'
 150
 151cd "$WORKDIR"
 152test_expect_success 'updating' '
 153    git pull gitcvs.git &&
 154    echo 'hi' > subdir/newfile.bin &&
 155    echo 'junk' > subdir/file.h &&
 156    echo 'hi' > subdir/newfile.c &&
 157    echo 'hello' >> binfile.bin &&
 158    git add subdir/newfile.bin subdir/file.h subdir/newfile.c binfile.bin &&
 159    git commit -q -m "Add and change some files" &&
 160    git push gitcvs.git >/dev/null &&
 161    cd cvswork &&
 162    GIT_CONFIG="$git_config" cvs -Q update &&
 163    cd .. &&
 164    marked_as cvswork textfile.c "" &&
 165    marked_as cvswork binfile.bin -kb &&
 166    marked_as cvswork .gitattributes "" &&
 167    marked_as cvswork mixedUp.c "" &&
 168    marked_as cvswork/subdir withCr.bin -kb &&
 169    marked_as cvswork/subdir file.h "" &&
 170    marked_as cvswork/subdir unspecified.other "" &&
 171    marked_as cvswork/subdir newfile.bin -kb &&
 172    marked_as cvswork/subdir newfile.c "" &&
 173    echo "File with embedded NUL: Q <- there" | q_to_nul > tmpExpect1 &&
 174    echo "hello" >> tmpExpect1 &&
 175    cmp cvswork/binfile.bin tmpExpect1
 176'
 177
 178rm -rf cvswork
 179test_expect_success 'cvs co (use attributes/guess)' '
 180    GIT_DIR="$SERVERDIR" git config gitcvs.allbinary guess &&
 181    GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
 182    marked_as cvswork textfile.c "" &&
 183    marked_as cvswork binfile.bin -kb &&
 184    marked_as cvswork .gitattributes "" &&
 185    marked_as cvswork mixedUp.c "" &&
 186    marked_as cvswork/subdir withCr.bin -kb &&
 187    marked_as cvswork/subdir file.h "" &&
 188    marked_as cvswork/subdir unspecified.other "" &&
 189    marked_as cvswork/subdir newfile.bin -kb &&
 190    marked_as cvswork/subdir newfile.c ""
 191'
 192
 193test_expect_success 'setup multi-line files' '
 194    ( echo "line 1" &&
 195      echo "line 2" &&
 196      echo "line 3" &&
 197      echo "line 4 with NUL: Q <-" ) | q_to_nul > multiline.c &&
 198    git add multiline.c &&
 199    ( echo "line 1" &&
 200      echo "line 2" &&
 201      echo "line 3" &&
 202      echo "line 4" ) | q_to_nul > multilineTxt.c &&
 203    git add multilineTxt.c &&
 204    git commit -q -m "multiline files" &&
 205    git push gitcvs.git >/dev/null
 206'
 207
 208rm -rf cvswork
 209test_expect_success 'cvs co (guess)' '
 210    GIT_DIR="$SERVERDIR" git config --bool gitcvs.usecrlfattr false &&
 211    GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
 212    marked_as cvswork textfile.c "" &&
 213    marked_as cvswork binfile.bin -kb &&
 214    marked_as cvswork .gitattributes "" &&
 215    marked_as cvswork mixedUp.c -kb &&
 216    marked_as cvswork multiline.c -kb &&
 217    marked_as cvswork multilineTxt.c "" &&
 218    marked_as cvswork/subdir withCr.bin -kb &&
 219    marked_as cvswork/subdir file.h "" &&
 220    marked_as cvswork/subdir unspecified.other "" &&
 221    marked_as cvswork/subdir newfile.bin "" &&
 222    marked_as cvswork/subdir newfile.c ""
 223'
 224
 225test_expect_success 'cvs co another copy (guess)' '
 226    GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
 227    marked_as cvswork2 textfile.c "" &&
 228    marked_as cvswork2 binfile.bin -kb &&
 229    marked_as cvswork2 .gitattributes "" &&
 230    marked_as cvswork2 mixedUp.c -kb &&
 231    marked_as cvswork2 multiline.c -kb &&
 232    marked_as cvswork2 multilineTxt.c "" &&
 233    marked_as cvswork2/subdir withCr.bin -kb &&
 234    marked_as cvswork2/subdir file.h "" &&
 235    marked_as cvswork2/subdir unspecified.other "" &&
 236    marked_as cvswork2/subdir newfile.bin "" &&
 237    marked_as cvswork2/subdir newfile.c ""
 238'
 239
 240test_expect_success 'add text (guess)' '
 241    cd cvswork &&
 242    echo "simpleText" > simpleText.c &&
 243    GIT_CONFIG="$git_config" cvs -Q add simpleText.c &&
 244    cd .. &&
 245    marked_as cvswork simpleText.c ""
 246'
 247
 248test_expect_success 'add bin (guess)' '
 249    cd cvswork &&
 250    echo "simpleBin: NUL: Q <- there" | q_to_nul > simpleBin.bin &&
 251    GIT_CONFIG="$git_config" cvs -Q add simpleBin.bin &&
 252    cd .. &&
 253    marked_as cvswork simpleBin.bin -kb
 254'
 255
 256test_expect_success 'remove files (guess)' '
 257    cd cvswork &&
 258    GIT_CONFIG="$git_config" cvs -Q rm -f subdir/file.h &&
 259    cd subdir &&
 260    GIT_CONFIG="$git_config" cvs -Q rm -f withCr.bin &&
 261    cd ../.. &&
 262    marked_as cvswork/subdir withCr.bin -kb &&
 263    marked_as cvswork/subdir file.h ""
 264'
 265
 266test_expect_success 'cvs ci (guess)' '
 267    cd cvswork &&
 268    GIT_CONFIG="$git_config" cvs -Q ci -m "add/rm files" >cvs.log 2>&1 &&
 269    cd .. &&
 270    marked_as cvswork textfile.c "" &&
 271    marked_as cvswork binfile.bin -kb &&
 272    marked_as cvswork .gitattributes "" &&
 273    marked_as cvswork mixedUp.c -kb &&
 274    marked_as cvswork multiline.c -kb &&
 275    marked_as cvswork multilineTxt.c "" &&
 276    not_present cvswork/subdir withCr.bin &&
 277    not_present cvswork/subdir file.h &&
 278    marked_as cvswork/subdir unspecified.other "" &&
 279    marked_as cvswork/subdir newfile.bin "" &&
 280    marked_as cvswork/subdir newfile.c "" &&
 281    marked_as cvswork simpleBin.bin -kb &&
 282    marked_as cvswork simpleText.c ""
 283'
 284
 285test_expect_success 'update subdir of other copy (guess)' '
 286    cd cvswork2/subdir &&
 287    GIT_CONFIG="$git_config" cvs -Q update &&
 288    cd ../.. &&
 289    marked_as cvswork2 textfile.c "" &&
 290    marked_as cvswork2 binfile.bin -kb &&
 291    marked_as cvswork2 .gitattributes "" &&
 292    marked_as cvswork2 mixedUp.c -kb &&
 293    marked_as cvswork2 multiline.c -kb &&
 294    marked_as cvswork2 multilineTxt.c "" &&
 295    not_present cvswork2/subdir withCr.bin &&
 296    not_present cvswork2/subdir file.h &&
 297    marked_as cvswork2/subdir unspecified.other "" &&
 298    marked_as cvswork2/subdir newfile.bin "" &&
 299    marked_as cvswork2/subdir newfile.c "" &&
 300    not_present cvswork2 simpleBin.bin &&
 301    not_present cvswork2 simpleText.c
 302'
 303
 304echo "starting update/merge" >> "${WORKDIR}/marked.log"
 305test_expect_success 'update/merge full other copy (guess)' '
 306    git pull gitcvs.git master &&
 307    sed "s/3/replaced_3/" < multilineTxt.c > ml.temp &&
 308    mv ml.temp multilineTxt.c &&
 309    git add multilineTxt.c &&
 310    git commit -q -m "modify multiline file" >> "${WORKDIR}/marked.log" &&
 311    git push gitcvs.git >/dev/null &&
 312    cd cvswork2 &&
 313    sed "s/1/replaced_1/" < multilineTxt.c > ml.temp &&
 314    mv ml.temp multilineTxt.c &&
 315    GIT_CONFIG="$git_config" cvs update > cvs.log 2>&1 &&
 316    cd .. &&
 317    marked_as cvswork2 textfile.c "" &&
 318    marked_as cvswork2 binfile.bin -kb &&
 319    marked_as cvswork2 .gitattributes "" &&
 320    marked_as cvswork2 mixedUp.c -kb &&
 321    marked_as cvswork2 multiline.c -kb &&
 322    marked_as cvswork2 multilineTxt.c "" &&
 323    not_present cvswork2/subdir withCr.bin &&
 324    not_present cvswork2/subdir file.h &&
 325    marked_as cvswork2/subdir unspecified.other "" &&
 326    marked_as cvswork2/subdir newfile.bin "" &&
 327    marked_as cvswork2/subdir newfile.c "" &&
 328    marked_as cvswork2 simpleBin.bin -kb &&
 329    marked_as cvswork2 simpleText.c "" &&
 330    echo "line replaced_1" > tmpExpect2 &&
 331    echo "line 2" >> tmpExpect2 &&
 332    echo "line replaced_3" >> tmpExpect2 &&
 333    echo "line 4" | q_to_nul >> tmpExpect2 &&
 334    cmp cvswork2/multilineTxt.c tmpExpect2
 335'
 336
 337test_done