t / t9400-git-cvsserver-server.shon commit t/t3800-mktag.sh: use test_must_fail rather than '!' (525d461)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Frank Lichtenheld
   4#
   5
   6test_description='git-cvsserver access
   7
   8tests read access to a git repository with the
   9cvs CLI client via git-cvsserver server'
  10
  11. ./test-lib.sh
  12
  13cvs >/dev/null 2>&1
  14if test $? -ne 1
  15then
  16    test_expect_success 'skipping git-cvsserver tests, cvs not found' :
  17    test_done
  18    exit
  19fi
  20perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
  21    test_expect_success 'skipping git-cvsserver tests, Perl SQLite interface unavailable' :
  22    test_done
  23    exit
  24}
  25
  26unset GIT_DIR GIT_CONFIG
  27WORKDIR=$(pwd)
  28SERVERDIR=$(pwd)/gitcvs.git
  29git_config="$SERVERDIR/config"
  30CVSROOT=":fork:$SERVERDIR"
  31CVSWORK="$(pwd)/cvswork"
  32CVS_SERVER=git-cvsserver
  33export CVSROOT CVS_SERVER
  34
  35rm -rf "$CVSWORK" "$SERVERDIR"
  36test_expect_success 'setup' '
  37  echo >empty &&
  38  git add empty &&
  39  git commit -q -m "First Commit" &&
  40  mkdir secondroot &&
  41  ( cd secondroot &&
  42  git init &&
  43  touch secondrootfile &&
  44  git add secondrootfile &&
  45  git commit -m "second root") &&
  46  git pull secondroot master &&
  47  git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
  48  GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
  49  GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
  50'
  51
  52# note that cvs doesn't accept absolute pathnames
  53# as argument to co -d
  54test_expect_success 'basic checkout' \
  55  'GIT_CONFIG="$git_config" cvs -Q co -d cvswork master &&
  56   test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | head -n 1))" = "empty/1.1/"
  57   test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | tail -n 1))" = "secondrootfile/1.1/"'
  58
  59#------------------------
  60# PSERVER AUTHENTICATION
  61#------------------------
  62
  63cat >request-anonymous  <<EOF
  64BEGIN AUTH REQUEST
  65$SERVERDIR
  66anonymous
  67
  68END AUTH REQUEST
  69EOF
  70
  71cat >request-git  <<EOF
  72BEGIN AUTH REQUEST
  73$SERVERDIR
  74git
  75
  76END AUTH REQUEST
  77EOF
  78
  79cat >login-anonymous <<EOF
  80BEGIN VERIFICATION REQUEST
  81$SERVERDIR
  82anonymous
  83
  84END VERIFICATION REQUEST
  85EOF
  86
  87cat >login-git <<EOF
  88BEGIN VERIFICATION REQUEST
  89$SERVERDIR
  90git
  91
  92END VERIFICATION REQUEST
  93EOF
  94
  95test_expect_success 'pserver authentication' \
  96  'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
  97   tail -n1 log | grep -q "^I LOVE YOU$"'
  98
  99test_expect_success 'pserver authentication failure (non-anonymous user)' \
 100  'if cat request-git | git-cvsserver pserver >log 2>&1
 101   then
 102       false
 103   else
 104       true
 105   fi &&
 106   tail -n1 log | grep -q "^I HATE YOU$"'
 107
 108test_expect_success 'pserver authentication (login)' \
 109  'cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
 110   tail -n1 log | grep -q "^I LOVE YOU$"'
 111
 112test_expect_success 'pserver authentication failure (login/non-anonymous user)' \
 113  'if cat login-git | git-cvsserver pserver >log 2>&1
 114   then
 115       false
 116   else
 117       true
 118   fi &&
 119   tail -n1 log | grep -q "^I HATE YOU$"'
 120
 121
 122# misuse pserver authentication for testing of req_Root
 123
 124cat >request-relative  <<EOF
 125BEGIN AUTH REQUEST
 126gitcvs.git
 127anonymous
 128
 129END AUTH REQUEST
 130EOF
 131
 132cat >request-conflict  <<EOF
 133BEGIN AUTH REQUEST
 134$SERVERDIR
 135anonymous
 136
 137END AUTH REQUEST
 138Root $WORKDIR
 139EOF
 140
 141test_expect_success 'req_Root failure (relative pathname)' \
 142  'if cat request-relative | git-cvsserver pserver >log 2>&1
 143   then
 144       echo unexpected success
 145       false
 146   else
 147       true
 148   fi &&
 149   tail log | grep -q "^error 1 Root must be an absolute pathname$"'
 150
 151test_expect_success 'req_Root failure (conflicting roots)' \
 152  'cat request-conflict | git-cvsserver pserver >log 2>&1 &&
 153   tail log | grep -q "^error 1 Conflicting roots specified$"'
 154
 155test_expect_success 'req_Root (strict paths)' \
 156  'cat request-anonymous | git-cvsserver --strict-paths pserver $SERVERDIR >log 2>&1 &&
 157   tail -n1 log | grep -q "^I LOVE YOU$"'
 158
 159test_expect_failure 'req_Root failure (strict-paths)' \
 160  'cat request-anonymous | git-cvsserver --strict-paths pserver $WORKDIR >log 2>&1'
 161
 162test_expect_success 'req_Root (w/o strict-paths)' \
 163  'cat request-anonymous | git-cvsserver pserver $WORKDIR/ >log 2>&1 &&
 164   tail -n1 log | grep -q "^I LOVE YOU$"'
 165
 166test_expect_failure 'req_Root failure (w/o strict-paths)' \
 167  'cat request-anonymous | git-cvsserver pserver $WORKDIR/gitcvs >log 2>&1'
 168
 169cat >request-base  <<EOF
 170BEGIN AUTH REQUEST
 171/gitcvs.git
 172anonymous
 173
 174END AUTH REQUEST
 175Root /gitcvs.git
 176EOF
 177
 178test_expect_success 'req_Root (base-path)' \
 179  'cat request-base | git-cvsserver --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 &&
 180   tail -n1 log | grep -q "^I LOVE YOU$"'
 181
 182test_expect_failure 'req_Root failure (base-path)' \
 183  'cat request-anonymous | git-cvsserver --strict-paths --base-path $WORKDIR pserver $SERVERDIR >log 2>&1'
 184
 185GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false || exit 1
 186
 187test_expect_success 'req_Root (export-all)' \
 188  'cat request-anonymous | git-cvsserver --export-all pserver $WORKDIR >log 2>&1 &&
 189   tail -n1 log | grep -q "^I LOVE YOU$"'
 190
 191test_expect_failure 'req_Root failure (export-all w/o whitelist)' \
 192  'cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 ||
 193   false'
 194
 195test_expect_success 'req_Root (everything together)' \
 196  'cat request-base | git-cvsserver --export-all --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 &&
 197   tail -n1 log | grep -q "^I LOVE YOU$"'
 198
 199GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true || exit 1
 200
 201#--------------
 202# CONFIG TESTS
 203#--------------
 204
 205test_expect_success 'gitcvs.enabled = false' \
 206  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
 207   if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
 208   then
 209     echo unexpected cvs success
 210     false
 211   else
 212     true
 213   fi &&
 214   cat cvs.log | grep -q "GITCVS emulation disabled" &&
 215   test ! -d cvswork2'
 216
 217rm -fr cvswork2
 218test_expect_success 'gitcvs.ext.enabled = true' \
 219  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
 220   GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
 221   GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
 222   diff -q cvswork cvswork2'
 223
 224rm -fr cvswork2
 225test_expect_success 'gitcvs.ext.enabled = false' \
 226  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
 227   GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
 228   if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
 229   then
 230     echo unexpected cvs success
 231     false
 232   else
 233     true
 234   fi &&
 235   cat cvs.log | grep -q "GITCVS emulation disabled" &&
 236   test ! -d cvswork2'
 237
 238rm -fr cvswork2
 239test_expect_success 'gitcvs.dbname' \
 240  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
 241   GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
 242   GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
 243   diff -q cvswork cvswork2 &&
 244   test -f "$SERVERDIR/gitcvs.ext.master.sqlite" &&
 245   cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs.ext.master.sqlite"'
 246
 247rm -fr cvswork2
 248test_expect_success 'gitcvs.ext.dbname' \
 249  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
 250   GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
 251   GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
 252   GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
 253   diff -q cvswork cvswork2 &&
 254   test -f "$SERVERDIR/gitcvs1.ext.master.sqlite" &&
 255   test ! -f "$SERVERDIR/gitcvs2.ext.master.sqlite" &&
 256   cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs1.ext.master.sqlite"'
 257
 258
 259#------------
 260# CVS UPDATE
 261#------------
 262
 263rm -fr "$SERVERDIR"
 264cd "$WORKDIR" &&
 265git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
 266GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
 267GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
 268exit 1
 269
 270test_expect_success 'cvs update (create new file)' \
 271  'echo testfile1 >testfile1 &&
 272   git add testfile1 &&
 273   git commit -q -m "Add testfile1" &&
 274   git push gitcvs.git >/dev/null &&
 275   cd cvswork &&
 276   GIT_CONFIG="$git_config" cvs -Q update &&
 277   test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
 278   diff -q testfile1 ../testfile1'
 279
 280cd "$WORKDIR"
 281test_expect_success 'cvs update (update existing file)' \
 282  'echo line 2 >>testfile1 &&
 283   git add testfile1 &&
 284   git commit -q -m "Append to testfile1" &&
 285   git push gitcvs.git >/dev/null &&
 286   cd cvswork &&
 287   GIT_CONFIG="$git_config" cvs -Q update &&
 288   test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
 289   diff -q testfile1 ../testfile1'
 290
 291cd "$WORKDIR"
 292#TODO: cvsserver doesn't support update w/o -d
 293test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" \
 294  'mkdir test &&
 295   echo >test/empty &&
 296   git add test &&
 297   git commit -q -m "Single Subdirectory" &&
 298   git push gitcvs.git >/dev/null &&
 299   cd cvswork &&
 300   GIT_CONFIG="$git_config" cvs -Q update &&
 301   test ! -d test'
 302
 303cd "$WORKDIR"
 304test_expect_success 'cvs update (subdirectories)' \
 305  '(for dir in A A/B A/B/C A/D E; do
 306      mkdir $dir &&
 307      echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")"  &&
 308      git add $dir;
 309   done) &&
 310   git commit -q -m "deep sub directory structure" &&
 311   git push gitcvs.git >/dev/null &&
 312   cd cvswork &&
 313   GIT_CONFIG="$git_config" cvs -Q update -d &&
 314   (for dir in A A/B A/B/C A/D E; do
 315      filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
 316      if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
 317           diff -q "$dir/$filename" "../$dir/$filename"; then
 318        :
 319      else
 320        echo >failure
 321      fi
 322    done) &&
 323   test ! -f failure'
 324
 325cd "$WORKDIR"
 326test_expect_success 'cvs update (delete file)' \
 327  'git rm testfile1 &&
 328   git commit -q -m "Remove testfile1" &&
 329   git push gitcvs.git >/dev/null &&
 330   cd cvswork &&
 331   GIT_CONFIG="$git_config" cvs -Q update &&
 332   test -z "$(grep testfile1 CVS/Entries)" &&
 333   test ! -f testfile1'
 334
 335cd "$WORKDIR"
 336test_expect_success 'cvs update (re-add deleted file)' \
 337  'echo readded testfile >testfile1 &&
 338   git add testfile1 &&
 339   git commit -q -m "Re-Add testfile1" &&
 340   git push gitcvs.git >/dev/null &&
 341   cd cvswork &&
 342   GIT_CONFIG="$git_config" cvs -Q update &&
 343   test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
 344   diff -q testfile1 ../testfile1'
 345
 346cd "$WORKDIR"
 347test_expect_success 'cvs update (merge)' \
 348  'echo Line 0 >expected &&
 349   for i in 1 2 3 4 5 6 7
 350   do
 351     echo Line $i >>merge
 352     echo Line $i >>expected
 353   done &&
 354   echo Line 8 >>expected &&
 355   git add merge &&
 356   git commit -q -m "Merge test (pre-merge)" &&
 357   git push gitcvs.git >/dev/null &&
 358   cd cvswork &&
 359   GIT_CONFIG="$git_config" cvs -Q update &&
 360   test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
 361   diff -q merge ../merge &&
 362   ( echo Line 0; cat merge ) >merge.tmp &&
 363   mv merge.tmp merge &&
 364   cd "$WORKDIR" &&
 365   echo Line 8 >>merge &&
 366   git add merge &&
 367   git commit -q -m "Merge test (merge)" &&
 368   git push gitcvs.git >/dev/null &&
 369   cd cvswork &&
 370   sleep 1 && touch merge &&
 371   GIT_CONFIG="$git_config" cvs -Q update &&
 372   diff -q merge ../expected'
 373
 374cd "$WORKDIR"
 375
 376cat >expected.C <<EOF
 377<<<<<<< merge.mine
 378Line 0
 379=======
 380LINE 0
 381>>>>>>> merge.3
 382EOF
 383
 384for i in 1 2 3 4 5 6 7 8
 385do
 386  echo Line $i >>expected.C
 387done
 388
 389test_expect_success 'cvs update (conflict merge)' \
 390  '( echo LINE 0; cat merge ) >merge.tmp &&
 391   mv merge.tmp merge &&
 392   git add merge &&
 393   git commit -q -m "Merge test (conflict)" &&
 394   git push gitcvs.git >/dev/null &&
 395   cd cvswork &&
 396   GIT_CONFIG="$git_config" cvs -Q update &&
 397   diff -q merge ../expected.C'
 398
 399cd "$WORKDIR"
 400test_expect_success 'cvs update (-C)' \
 401  'cd cvswork &&
 402   GIT_CONFIG="$git_config" cvs -Q update -C &&
 403   diff -q merge ../merge'
 404
 405cd "$WORKDIR"
 406test_expect_success 'cvs update (merge no-op)' \
 407   'echo Line 9 >>merge &&
 408    cp merge cvswork/merge &&
 409    git add merge &&
 410    git commit -q -m "Merge test (no-op)" &&
 411    git push gitcvs.git >/dev/null &&
 412    cd cvswork &&
 413    sleep 1 && touch merge &&
 414    GIT_CONFIG="$git_config" cvs -Q update &&
 415    diff -q merge ../merge'
 416
 417test_done