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