t / t9400-git-cvsserver-server.shon commit t9400: Add some basic pserver tests (240ba7f)
   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"
  36echo >empty &&
  37  git add empty &&
  38  git commit -q -m "First Commit" &&
  39  git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
  40  GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
  41  GIT_DIR="$SERVERDIR" git config --bool gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
  42  exit 1
  43
  44# note that cvs doesn't accept absolute pathnames
  45# as argument to co -d
  46test_expect_success 'basic checkout' \
  47  'GIT_CONFIG="$git_config" cvs -Q co -d cvswork master &&
  48   test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5))" = "empty/1.1/"'
  49
  50#------------------------
  51# PSERVER AUTHENTICATION
  52#------------------------
  53
  54cat >request-anonymous  <<EOF
  55BEGIN AUTH REQUEST
  56$SERVERDIR
  57anonymous
  58
  59END AUTH REQUEST
  60EOF
  61
  62cat >request-git  <<EOF
  63BEGIN AUTH REQUEST
  64$SERVERDIR
  65git
  66
  67END AUTH REQUEST
  68EOF
  69
  70test_expect_success 'pserver authentication' \
  71  'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
  72   tail -n1 log | grep -q "^I LOVE YOU$"'
  73
  74test_expect_success 'pserver authentication failure (non-anonymous user)' \
  75  'if cat request-git | git-cvsserver pserver >log 2>&1
  76   then
  77       false
  78   else
  79       true
  80   fi &&
  81   tail -n1 log | grep -q "^I HATE YOU$"'
  82
  83
  84#--------------
  85# CONFIG TESTS
  86#--------------
  87
  88test_expect_success 'gitcvs.enabled = false' \
  89  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
  90   if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
  91   then
  92     echo unexpected cvs success
  93     false
  94   else
  95     true
  96   fi &&
  97   cat cvs.log | grep -q "GITCVS emulation disabled" &&
  98   test ! -d cvswork2'
  99
 100rm -fr cvswork2
 101test_expect_success 'gitcvs.ext.enabled = true' \
 102  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
 103   GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
 104   GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
 105   diff -q cvswork cvswork2'
 106
 107rm -fr cvswork2
 108test_expect_success 'gitcvs.ext.enabled = false' \
 109  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
 110   GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
 111   if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
 112   then
 113     echo unexpected cvs success
 114     false
 115   else
 116     true
 117   fi &&
 118   cat cvs.log | grep -q "GITCVS emulation disabled" &&
 119   test ! -d cvswork2'
 120
 121rm -fr cvswork2
 122test_expect_success 'gitcvs.dbname' \
 123  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
 124   GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
 125   GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
 126   diff -q cvswork cvswork2 &&
 127   test -f "$SERVERDIR/gitcvs.ext.master.sqlite" &&
 128   cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs.ext.master.sqlite"'
 129
 130rm -fr cvswork2
 131test_expect_success 'gitcvs.ext.dbname' \
 132  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
 133   GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
 134   GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
 135   GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
 136   diff -q cvswork cvswork2 &&
 137   test -f "$SERVERDIR/gitcvs1.ext.master.sqlite" &&
 138   test ! -f "$SERVERDIR/gitcvs2.ext.master.sqlite" &&
 139   cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs1.ext.master.sqlite"'
 140
 141
 142#------------
 143# CVS UPDATE
 144#------------
 145
 146rm -fr "$SERVERDIR"
 147cd "$WORKDIR" &&
 148git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
 149GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
 150GIT_DIR="$SERVERDIR" git config --bool gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
 151exit 1
 152
 153test_expect_success 'cvs update (create new file)' \
 154  'echo testfile1 >testfile1 &&
 155   git add testfile1 &&
 156   git commit -q -m "Add testfile1" &&
 157   git push gitcvs.git >/dev/null &&
 158   cd cvswork &&
 159   GIT_CONFIG="$git_config" cvs -Q update &&
 160   test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
 161   diff -q testfile1 ../testfile1'
 162
 163cd "$WORKDIR"
 164test_expect_success 'cvs update (update existing file)' \
 165  'echo line 2 >>testfile1 &&
 166   git add testfile1 &&
 167   git commit -q -m "Append to testfile1" &&
 168   git push gitcvs.git >/dev/null &&
 169   cd cvswork &&
 170   GIT_CONFIG="$git_config" cvs -Q update &&
 171   test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
 172   diff -q testfile1 ../testfile1'
 173
 174cd "$WORKDIR"
 175#TODO: cvsserver doesn't support update w/o -d
 176test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" \
 177  'mkdir test &&
 178   echo >test/empty &&
 179   git add test &&
 180   git commit -q -m "Single Subdirectory" &&
 181   git push gitcvs.git >/dev/null &&
 182   cd cvswork &&
 183   GIT_CONFIG="$git_config" cvs -Q update &&
 184   test ! -d test'
 185
 186cd "$WORKDIR"
 187test_expect_success 'cvs update (subdirectories)' \
 188  '(for dir in A A/B A/B/C A/D E; do
 189      mkdir $dir &&
 190      echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")"  &&
 191      git add $dir;
 192   done) &&
 193   git commit -q -m "deep sub directory structure" &&
 194   git push gitcvs.git >/dev/null &&
 195   cd cvswork &&
 196   GIT_CONFIG="$git_config" cvs -Q update -d &&
 197   (for dir in A A/B A/B/C A/D E; do
 198      filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
 199      if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
 200           diff -q "$dir/$filename" "../$dir/$filename"; then
 201        :
 202      else
 203        echo >failure
 204      fi
 205    done) &&
 206   test ! -f failure'
 207
 208cd "$WORKDIR"
 209test_expect_success 'cvs update (delete file)' \
 210  'git rm testfile1 &&
 211   git commit -q -m "Remove testfile1" &&
 212   git push gitcvs.git >/dev/null &&
 213   cd cvswork &&
 214   GIT_CONFIG="$git_config" cvs -Q update &&
 215   test -z "$(grep testfile1 CVS/Entries)" &&
 216   test ! -f testfile1'
 217
 218cd "$WORKDIR"
 219test_expect_success 'cvs update (re-add deleted file)' \
 220  'echo readded testfile >testfile1 &&
 221   git add testfile1 &&
 222   git commit -q -m "Re-Add testfile1" &&
 223   git push gitcvs.git >/dev/null &&
 224   cd cvswork &&
 225   GIT_CONFIG="$git_config" cvs -Q update &&
 226   test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
 227   diff -q testfile1 ../testfile1'
 228
 229cd "$WORKDIR"
 230test_expect_success 'cvs update (merge)' \
 231  'echo Line 0 >expected &&
 232   for i in 1 2 3 4 5 6 7
 233   do
 234     echo Line $i >>merge
 235     echo Line $i >>expected
 236   done &&
 237   echo Line 8 >>expected &&
 238   git add merge &&
 239   git commit -q -m "Merge test (pre-merge)" &&
 240   git push gitcvs.git >/dev/null &&
 241   cd cvswork &&
 242   GIT_CONFIG="$git_config" cvs -Q update &&
 243   test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
 244   diff -q merge ../merge &&
 245   ( echo Line 0; cat merge ) >merge.tmp &&
 246   mv merge.tmp merge &&
 247   cd "$WORKDIR" &&
 248   echo Line 8 >>merge &&
 249   git add merge &&
 250   git commit -q -m "Merge test (merge)" &&
 251   git push gitcvs.git >/dev/null &&
 252   cd cvswork &&
 253   GIT_CONFIG="$git_config" cvs -Q update &&
 254   diff -q merge ../expected'
 255
 256cd "$WORKDIR"
 257
 258cat >expected.C <<EOF
 259<<<<<<< merge.mine
 260Line 0
 261=======
 262LINE 0
 263>>>>>>> merge.3
 264EOF
 265
 266for i in 1 2 3 4 5 6 7 8
 267do
 268  echo Line $i >>expected.C
 269done
 270
 271test_expect_success 'cvs update (conflict merge)' \
 272  '( echo LINE 0; cat merge ) >merge.tmp &&
 273   mv merge.tmp merge &&
 274   git add merge &&
 275   git commit -q -m "Merge test (conflict)" &&
 276   git push gitcvs.git >/dev/null &&
 277   cd cvswork &&
 278   GIT_CONFIG="$git_config" cvs -Q update &&
 279   diff -q merge ../expected.C'
 280
 281cd "$WORKDIR"
 282test_expect_success 'cvs update (-C)' \
 283  'cd cvswork &&
 284   GIT_CONFIG="$git_config" cvs -Q update -C &&
 285   diff -q merge ../merge'
 286
 287cd "$WORKDIR"
 288test_expect_success 'cvs update (merge no-op)' \
 289   'echo Line 9 >>merge &&
 290    cp merge cvswork/merge &&
 291    git add merge &&
 292    git commit -q -m "Merge test (no-op)" &&
 293    git push gitcvs.git >/dev/null &&
 294    cd cvswork &&
 295    GIT_CONFIG="$git_config" cvs -Q update &&
 296    diff -q merge ../merge'
 297
 298test_done