t / t9401-git-cvsserver-crlf.shon commit Merge branch 'jk/ident-ai-canonname-could-be-null' into maint (11738dd)
   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
  71perl -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    git config push.default matching &&
  88    echo "Simple text file" >textfile.c &&
  89    echo "File with embedded NUL: Q <- there" | q_to_nul > binfile.bin &&
  90    mkdir subdir &&
  91    echo "Another text file" > subdir/file.h &&
  92    echo "Another binary: Q (this time CR)" | q_to_cr > subdir/withCr.bin &&
  93    echo "Mixed up NUL, but marked text: Q <- there" | q_to_nul > mixedUp.c &&
  94    echo "Unspecified" > subdir/unspecified.other &&
  95    echo "/*.bin -crlf" > .gitattributes &&
  96    echo "/*.c crlf" >> .gitattributes &&
  97    echo "subdir/*.bin -crlf" >> .gitattributes &&
  98    echo "subdir/*.c crlf" >> .gitattributes &&
  99    echo "subdir/file.h crlf" >> .gitattributes &&
 100    git add .gitattributes textfile.c binfile.bin mixedUp.c subdir/* &&
 101    git commit -q -m "First Commit" &&
 102    git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
 103    GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
 104    GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
 105'
 106
 107test_expect_success 'cvs co (default crlf)' '
 108    GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
 109    test x"$(grep '/-k' cvswork/CVS/Entries cvswork/subdir/CVS/Entries)" = x""
 110'
 111
 112rm -rf cvswork
 113test_expect_success 'cvs co (allbinary)' '
 114    GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary true &&
 115    GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
 116    marked_as cvswork textfile.c -kb &&
 117    marked_as cvswork binfile.bin -kb &&
 118    marked_as cvswork .gitattributes -kb &&
 119    marked_as cvswork mixedUp.c -kb &&
 120    marked_as cvswork/subdir withCr.bin -kb &&
 121    marked_as cvswork/subdir file.h -kb &&
 122    marked_as cvswork/subdir unspecified.other -kb
 123'
 124
 125rm -rf cvswork cvs.log
 126test_expect_success 'cvs co (use attributes/allbinary)' '
 127    GIT_DIR="$SERVERDIR" git config --bool gitcvs.usecrlfattr true &&
 128    GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
 129    marked_as cvswork textfile.c "" &&
 130    marked_as cvswork binfile.bin -kb &&
 131    marked_as cvswork .gitattributes -kb &&
 132    marked_as cvswork mixedUp.c "" &&
 133    marked_as cvswork/subdir withCr.bin -kb &&
 134    marked_as cvswork/subdir file.h "" &&
 135    marked_as cvswork/subdir unspecified.other -kb
 136'
 137
 138rm -rf cvswork
 139test_expect_success 'cvs co (use attributes)' '
 140    GIT_DIR="$SERVERDIR" git config --bool gitcvs.allbinary false &&
 141    GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
 142    marked_as cvswork textfile.c "" &&
 143    marked_as cvswork binfile.bin -kb &&
 144    marked_as cvswork .gitattributes "" &&
 145    marked_as cvswork mixedUp.c "" &&
 146    marked_as cvswork/subdir withCr.bin -kb &&
 147    marked_as cvswork/subdir file.h "" &&
 148    marked_as cvswork/subdir unspecified.other ""
 149'
 150
 151test_expect_success 'adding files' '
 152    (cd cvswork &&
 153    (cd subdir &&
 154    echo "more text" > src.c &&
 155    GIT_CONFIG="$git_config" cvs -Q add src.c >cvs.log 2>&1 &&
 156    marked_as . src.c "" &&
 157    echo "pseudo-binary" > temp.bin
 158    ) &&
 159    GIT_CONFIG="$git_config" cvs -Q add subdir/temp.bin >cvs.log 2>&1 &&
 160    marked_as subdir temp.bin "-kb" &&
 161    cd subdir &&
 162    GIT_CONFIG="$git_config" cvs -Q ci -m "adding files" >cvs.log 2>&1 &&
 163    marked_as . temp.bin "-kb" &&
 164    marked_as . src.c ""
 165    )
 166'
 167
 168test_expect_success 'updating' '
 169    git pull gitcvs.git &&
 170    echo 'hi' > subdir/newfile.bin &&
 171    echo 'junk' > subdir/file.h &&
 172    echo 'hi' > subdir/newfile.c &&
 173    echo 'hello' >> binfile.bin &&
 174    git add subdir/newfile.bin subdir/file.h subdir/newfile.c binfile.bin &&
 175    git commit -q -m "Add and change some files" &&
 176    git push gitcvs.git >/dev/null &&
 177    (cd cvswork &&
 178    GIT_CONFIG="$git_config" cvs -Q update
 179    ) &&
 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 "" &&
 189    echo "File with embedded NUL: Q <- there" | q_to_nul > tmpExpect1 &&
 190    echo "hello" >> tmpExpect1 &&
 191    cmp cvswork/binfile.bin tmpExpect1
 192'
 193
 194rm -rf cvswork
 195test_expect_success 'cvs co (use attributes/guess)' '
 196    GIT_DIR="$SERVERDIR" git config gitcvs.allbinary guess &&
 197    GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
 198    marked_as cvswork textfile.c "" &&
 199    marked_as cvswork binfile.bin -kb &&
 200    marked_as cvswork .gitattributes "" &&
 201    marked_as cvswork mixedUp.c "" &&
 202    marked_as cvswork/subdir withCr.bin -kb &&
 203    marked_as cvswork/subdir file.h "" &&
 204    marked_as cvswork/subdir unspecified.other "" &&
 205    marked_as cvswork/subdir newfile.bin -kb &&
 206    marked_as cvswork/subdir newfile.c ""
 207'
 208
 209test_expect_success 'setup multi-line files' '
 210    ( echo "line 1" &&
 211      echo "line 2" &&
 212      echo "line 3" &&
 213      echo "line 4 with NUL: Q <-" ) | q_to_nul > multiline.c &&
 214    git add multiline.c &&
 215    ( echo "line 1" &&
 216      echo "line 2" &&
 217      echo "line 3" &&
 218      echo "line 4" ) | q_to_nul > multilineTxt.c &&
 219    git add multilineTxt.c &&
 220    git commit -q -m "multiline files" &&
 221    git push gitcvs.git >/dev/null
 222'
 223
 224rm -rf cvswork
 225test_expect_success 'cvs co (guess)' '
 226    GIT_DIR="$SERVERDIR" git config --bool gitcvs.usecrlfattr false &&
 227    GIT_CONFIG="$git_config" cvs -Q co -d cvswork master >cvs.log 2>&1 &&
 228    marked_as cvswork textfile.c "" &&
 229    marked_as cvswork binfile.bin -kb &&
 230    marked_as cvswork .gitattributes "" &&
 231    marked_as cvswork mixedUp.c -kb &&
 232    marked_as cvswork multiline.c -kb &&
 233    marked_as cvswork multilineTxt.c "" &&
 234    marked_as cvswork/subdir withCr.bin -kb &&
 235    marked_as cvswork/subdir file.h "" &&
 236    marked_as cvswork/subdir unspecified.other "" &&
 237    marked_as cvswork/subdir newfile.bin "" &&
 238    marked_as cvswork/subdir newfile.c ""
 239'
 240
 241test_expect_success 'cvs co another copy (guess)' '
 242    GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
 243    marked_as cvswork2 textfile.c "" &&
 244    marked_as cvswork2 binfile.bin -kb &&
 245    marked_as cvswork2 .gitattributes "" &&
 246    marked_as cvswork2 mixedUp.c -kb &&
 247    marked_as cvswork2 multiline.c -kb &&
 248    marked_as cvswork2 multilineTxt.c "" &&
 249    marked_as cvswork2/subdir withCr.bin -kb &&
 250    marked_as cvswork2/subdir file.h "" &&
 251    marked_as cvswork2/subdir unspecified.other "" &&
 252    marked_as cvswork2/subdir newfile.bin "" &&
 253    marked_as cvswork2/subdir newfile.c ""
 254'
 255
 256test_expect_success 'cvs status - sticky options' '
 257    check_status_options cvswork2 textfile.c "" &&
 258    check_status_options cvswork2 binfile.bin -kb &&
 259    check_status_options cvswork2 .gitattributes "" &&
 260    check_status_options cvswork2 mixedUp.c -kb &&
 261    check_status_options cvswork2 multiline.c -kb &&
 262    check_status_options cvswork2 multilineTxt.c "" &&
 263    check_status_options cvswork2/subdir withCr.bin -kb &&
 264    check_status_options cvswork2 subdir/withCr.bin -kb &&
 265    check_status_options cvswork2/subdir file.h "" &&
 266    check_status_options cvswork2 subdir/file.h "" &&
 267    check_status_options cvswork2/subdir unspecified.other "" &&
 268    check_status_options cvswork2/subdir newfile.bin "" &&
 269    check_status_options cvswork2/subdir newfile.c ""
 270'
 271
 272test_expect_success 'add text (guess)' '
 273    (cd cvswork &&
 274    echo "simpleText" > simpleText.c &&
 275    GIT_CONFIG="$git_config" cvs -Q add simpleText.c
 276    ) &&
 277    marked_as cvswork simpleText.c ""
 278'
 279
 280test_expect_success 'add bin (guess)' '
 281    (cd cvswork &&
 282    echo "simpleBin: NUL: Q <- there" | q_to_nul > simpleBin.bin &&
 283    GIT_CONFIG="$git_config" cvs -Q add simpleBin.bin
 284    ) &&
 285    marked_as cvswork simpleBin.bin -kb
 286'
 287
 288test_expect_success 'remove files (guess)' '
 289    (cd cvswork &&
 290    GIT_CONFIG="$git_config" cvs -Q rm -f subdir/file.h &&
 291    (cd subdir &&
 292    GIT_CONFIG="$git_config" cvs -Q rm -f withCr.bin
 293    )) &&
 294    marked_as cvswork/subdir withCr.bin -kb &&
 295    marked_as cvswork/subdir file.h ""
 296'
 297
 298test_expect_success 'cvs ci (guess)' '
 299    (cd cvswork &&
 300    GIT_CONFIG="$git_config" cvs -Q ci -m "add/rm files" >cvs.log 2>&1
 301    ) &&
 302    marked_as cvswork textfile.c "" &&
 303    marked_as cvswork binfile.bin -kb &&
 304    marked_as cvswork .gitattributes "" &&
 305    marked_as cvswork mixedUp.c -kb &&
 306    marked_as cvswork multiline.c -kb &&
 307    marked_as cvswork multilineTxt.c "" &&
 308    not_present cvswork/subdir withCr.bin &&
 309    not_present cvswork/subdir file.h &&
 310    marked_as cvswork/subdir unspecified.other "" &&
 311    marked_as cvswork/subdir newfile.bin "" &&
 312    marked_as cvswork/subdir newfile.c "" &&
 313    marked_as cvswork simpleBin.bin -kb &&
 314    marked_as cvswork simpleText.c ""
 315'
 316
 317test_expect_success 'update subdir of other copy (guess)' '
 318    (cd cvswork2/subdir &&
 319    GIT_CONFIG="$git_config" cvs -Q update
 320    ) &&
 321    marked_as cvswork2 textfile.c "" &&
 322    marked_as cvswork2 binfile.bin -kb &&
 323    marked_as cvswork2 .gitattributes "" &&
 324    marked_as cvswork2 mixedUp.c -kb &&
 325    marked_as cvswork2 multiline.c -kb &&
 326    marked_as cvswork2 multilineTxt.c "" &&
 327    not_present cvswork2/subdir withCr.bin &&
 328    not_present cvswork2/subdir file.h &&
 329    marked_as cvswork2/subdir unspecified.other "" &&
 330    marked_as cvswork2/subdir newfile.bin "" &&
 331    marked_as cvswork2/subdir newfile.c "" &&
 332    not_present cvswork2 simpleBin.bin &&
 333    not_present cvswork2 simpleText.c
 334'
 335
 336echo "starting update/merge" >> "${WORKDIR}/marked.log"
 337test_expect_success 'update/merge full other copy (guess)' '
 338    git pull gitcvs.git master &&
 339    sed "s/3/replaced_3/" < multilineTxt.c > ml.temp &&
 340    mv ml.temp multilineTxt.c &&
 341    git add multilineTxt.c &&
 342    git commit -q -m "modify multiline file" >> "${WORKDIR}/marked.log" &&
 343    git push gitcvs.git >/dev/null &&
 344    (cd cvswork2 &&
 345    sed "s/1/replaced_1/" < multilineTxt.c > ml.temp &&
 346    mv ml.temp multilineTxt.c &&
 347    GIT_CONFIG="$git_config" cvs update > cvs.log 2>&1
 348    ) &&
 349    marked_as cvswork2 textfile.c "" &&
 350    marked_as cvswork2 binfile.bin -kb &&
 351    marked_as cvswork2 .gitattributes "" &&
 352    marked_as cvswork2 mixedUp.c -kb &&
 353    marked_as cvswork2 multiline.c -kb &&
 354    marked_as cvswork2 multilineTxt.c "" &&
 355    not_present cvswork2/subdir withCr.bin &&
 356    not_present cvswork2/subdir file.h &&
 357    marked_as cvswork2/subdir unspecified.other "" &&
 358    marked_as cvswork2/subdir newfile.bin "" &&
 359    marked_as cvswork2/subdir newfile.c "" &&
 360    marked_as cvswork2 simpleBin.bin -kb &&
 361    marked_as cvswork2 simpleText.c "" &&
 362    echo "line replaced_1" > tmpExpect2 &&
 363    echo "line 2" >> tmpExpect2 &&
 364    echo "line replaced_3" >> tmpExpect2 &&
 365    echo "line 4" | q_to_nul >> tmpExpect2 &&
 366    cmp cvswork2/multilineTxt.c tmpExpect2
 367'
 368
 369test_done