t / t9400-git-cvsserver-server.shon commit t9400: Add test cases for config file handling (1d431b2)
   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# CONFIG TESTS
  52#--------------
  53
  54test_expect_success 'gitcvs.enabled = false' \
  55  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
  56   if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
  57   then
  58     echo unexpected cvs success
  59     false
  60   else
  61     true
  62   fi &&
  63   cat cvs.log | grep -q "GITCVS emulation disabled" &&
  64   test ! -d cvswork2'
  65
  66rm -fr cvswork2
  67test_expect_success 'gitcvs.ext.enabled = true' \
  68  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
  69   GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
  70   GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
  71   diff -q cvswork cvswork2'
  72
  73rm -fr cvswork2
  74test_expect_success 'gitcvs.ext.enabled = false' \
  75  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
  76   GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
  77   if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
  78   then
  79     echo unexpected cvs success
  80     false
  81   else
  82     true
  83   fi &&
  84   cat cvs.log | grep -q "GITCVS emulation disabled" &&
  85   test ! -d cvswork2'
  86
  87rm -fr cvswork2
  88test_expect_success 'gitcvs.dbname' \
  89  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
  90   GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
  91   GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
  92   diff -q cvswork cvswork2 &&
  93   test -f "$SERVERDIR/gitcvs.ext.master.sqlite" &&
  94   cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs.ext.master.sqlite"'
  95
  96rm -fr cvswork2
  97test_expect_success 'gitcvs.ext.dbname' \
  98  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
  99   GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
 100   GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
 101   GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
 102   diff -q cvswork cvswork2 &&
 103   test -f "$SERVERDIR/gitcvs1.ext.master.sqlite" &&
 104   test ! -f "$SERVERDIR/gitcvs2.ext.master.sqlite" &&
 105   cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs1.ext.master.sqlite"'
 106
 107
 108#------------
 109# CVS UPDATE
 110#------------
 111
 112rm -fr "$SERVERDIR"
 113cd "$WORKDIR" &&
 114git clone -q --local --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
 115GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
 116GIT_DIR="$SERVERDIR" git config --bool gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
 117exit 1
 118
 119test_expect_success 'cvs update (create new file)' \
 120  'echo testfile1 >testfile1 &&
 121   git add testfile1 &&
 122   git commit -q -m "Add testfile1" &&
 123   git push gitcvs.git >/dev/null &&
 124   cd cvswork &&
 125   GIT_CONFIG="$git_config" cvs -Q update &&
 126   test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
 127   diff -q testfile1 ../testfile1'
 128
 129cd "$WORKDIR"
 130test_expect_success 'cvs update (update existing file)' \
 131  'echo line 2 >>testfile1 &&
 132   git add testfile1 &&
 133   git commit -q -m "Append to testfile1" &&
 134   git push gitcvs.git >/dev/null &&
 135   cd cvswork &&
 136   GIT_CONFIG="$git_config" cvs -Q update &&
 137   test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
 138   diff -q testfile1 ../testfile1'
 139
 140cd "$WORKDIR"
 141#TODO: cvsserver doesn't support update w/o -d
 142test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" \
 143  'mkdir test &&
 144   echo >test/empty &&
 145   git add test &&
 146   git commit -q -m "Single Subdirectory" &&
 147   git push gitcvs.git >/dev/null &&
 148   cd cvswork &&
 149   GIT_CONFIG="$git_config" cvs -Q update &&
 150   test ! -d test'
 151
 152cd "$WORKDIR"
 153test_expect_success 'cvs update (subdirectories)' \
 154  '(for dir in A A/B A/B/C A/D E; do
 155      mkdir $dir &&
 156      echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")"  &&
 157      git add $dir;
 158   done) &&
 159   git commit -q -m "deep sub directory structure" &&
 160   git push gitcvs.git >/dev/null &&
 161   cd cvswork &&
 162   GIT_CONFIG="$git_config" cvs -Q update -d &&
 163   (for dir in A A/B A/B/C A/D E; do
 164      filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
 165      if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
 166           diff -q "$dir/$filename" "../$dir/$filename"; then
 167        :
 168      else
 169        echo >failure
 170      fi
 171    done) &&
 172   test ! -f failure'
 173
 174cd "$WORKDIR"
 175test_expect_success 'cvs update (delete file)' \
 176  'git rm testfile1 &&
 177   git commit -q -m "Remove testfile1" &&
 178   git push gitcvs.git >/dev/null &&
 179   cd cvswork &&
 180   GIT_CONFIG="$git_config" cvs -Q update &&
 181   test -z "$(grep testfile1 CVS/Entries)" &&
 182   test ! -f testfile1'
 183
 184cd "$WORKDIR"
 185test_expect_success 'cvs update (re-add deleted file)' \
 186  'echo readded testfile >testfile1 &&
 187   git add testfile1 &&
 188   git commit -q -m "Re-Add testfile1" &&
 189   git push gitcvs.git >/dev/null &&
 190   cd cvswork &&
 191   GIT_CONFIG="$git_config" cvs -Q update &&
 192   test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
 193   diff -q testfile1 ../testfile1'
 194
 195test_done