t / t9400-git-cvsserver-server.shon commit git-mergetool/difftool: make (g)vimdiff workable under Windows (bad4273)
   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    say 'skipping git-cvsserver tests, cvs not found'
  17    test_done
  18fi
  19perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || {
  20    say 'skipping git-cvsserver tests, Perl SQLite interface unavailable'
  21    test_done
  22}
  23
  24unset GIT_DIR GIT_CONFIG
  25WORKDIR=$(pwd)
  26SERVERDIR=$(pwd)/gitcvs.git
  27git_config="$SERVERDIR/config"
  28CVSROOT=":fork:$SERVERDIR"
  29CVSWORK="$(pwd)/cvswork"
  30CVS_SERVER=git-cvsserver
  31export CVSROOT CVS_SERVER
  32
  33rm -rf "$CVSWORK" "$SERVERDIR"
  34test_expect_success 'setup' '
  35  echo >empty &&
  36  git add empty &&
  37  git commit -q -m "First Commit" &&
  38  mkdir secondroot &&
  39  ( cd secondroot &&
  40  git init &&
  41  touch secondrootfile &&
  42  git add secondrootfile &&
  43  git commit -m "second root") &&
  44  git pull secondroot master &&
  45  git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
  46  GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
  47  GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log"
  48'
  49
  50# note that cvs doesn't accept absolute pathnames
  51# as argument to co -d
  52test_expect_success 'basic checkout' \
  53  'GIT_CONFIG="$git_config" cvs -Q co -d cvswork master &&
  54   test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | head -n 1))" = "empty/1.1/"
  55   test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | sed -ne \$p))" = "secondrootfile/1.1/"'
  56
  57#------------------------
  58# PSERVER AUTHENTICATION
  59#------------------------
  60
  61cat >request-anonymous  <<EOF
  62BEGIN AUTH REQUEST
  63$SERVERDIR
  64anonymous
  65
  66END AUTH REQUEST
  67EOF
  68
  69cat >request-git  <<EOF
  70BEGIN AUTH REQUEST
  71$SERVERDIR
  72git
  73
  74END AUTH REQUEST
  75EOF
  76
  77cat >login-anonymous <<EOF
  78BEGIN VERIFICATION REQUEST
  79$SERVERDIR
  80anonymous
  81
  82END VERIFICATION REQUEST
  83EOF
  84
  85cat >login-git <<EOF
  86BEGIN VERIFICATION REQUEST
  87$SERVERDIR
  88git
  89
  90END VERIFICATION REQUEST
  91EOF
  92
  93test_expect_success 'pserver authentication' \
  94  'cat request-anonymous | git-cvsserver pserver >log 2>&1 &&
  95   sed -ne \$p log | grep "^I LOVE YOU$"'
  96
  97test_expect_success 'pserver authentication failure (non-anonymous user)' \
  98  'if cat request-git | git-cvsserver pserver >log 2>&1
  99   then
 100       false
 101   else
 102       true
 103   fi &&
 104   sed -ne \$p log | grep "^I HATE YOU$"'
 105
 106test_expect_success 'pserver authentication (login)' \
 107  'cat login-anonymous | git-cvsserver pserver >log 2>&1 &&
 108   sed -ne \$p log | grep "^I LOVE YOU$"'
 109
 110test_expect_success 'pserver authentication failure (login/non-anonymous user)' \
 111  'if cat login-git | git-cvsserver pserver >log 2>&1
 112   then
 113       false
 114   else
 115       true
 116   fi &&
 117   sed -ne \$p log | grep "^I HATE YOU$"'
 118
 119
 120# misuse pserver authentication for testing of req_Root
 121
 122cat >request-relative  <<EOF
 123BEGIN AUTH REQUEST
 124gitcvs.git
 125anonymous
 126
 127END AUTH REQUEST
 128EOF
 129
 130cat >request-conflict  <<EOF
 131BEGIN AUTH REQUEST
 132$SERVERDIR
 133anonymous
 134
 135END AUTH REQUEST
 136Root $WORKDIR
 137EOF
 138
 139test_expect_success 'req_Root failure (relative pathname)' \
 140  'if cat request-relative | git-cvsserver pserver >log 2>&1
 141   then
 142       echo unexpected success
 143       false
 144   else
 145       true
 146   fi &&
 147   tail log | grep "^error 1 Root must be an absolute pathname$"'
 148
 149test_expect_success 'req_Root failure (conflicting roots)' \
 150  'cat request-conflict | git-cvsserver pserver >log 2>&1 &&
 151   tail log | grep "^error 1 Conflicting roots specified$"'
 152
 153test_expect_success 'req_Root (strict paths)' \
 154  'cat request-anonymous | git-cvsserver --strict-paths pserver "$SERVERDIR" >log 2>&1 &&
 155   sed -ne \$p log | grep "^I LOVE YOU$"'
 156
 157test_expect_success 'req_Root failure (strict-paths)' '
 158    ! cat request-anonymous |
 159    git-cvsserver --strict-paths pserver "$WORKDIR" >log 2>&1
 160'
 161
 162test_expect_success 'req_Root (w/o strict-paths)' \
 163  'cat request-anonymous | git-cvsserver pserver "$WORKDIR/" >log 2>&1 &&
 164   sed -ne \$p log | grep "^I LOVE YOU$"'
 165
 166test_expect_success 'req_Root failure (w/o strict-paths)' '
 167    ! cat request-anonymous |
 168    git-cvsserver pserver "$WORKDIR/gitcvs" >log 2>&1
 169'
 170
 171cat >request-base  <<EOF
 172BEGIN AUTH REQUEST
 173/gitcvs.git
 174anonymous
 175
 176END AUTH REQUEST
 177Root /gitcvs.git
 178EOF
 179
 180test_expect_success 'req_Root (base-path)' \
 181  'cat request-base | git-cvsserver --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
 182   sed -ne \$p log | grep "^I LOVE YOU$"'
 183
 184test_expect_success 'req_Root failure (base-path)' '
 185    ! cat request-anonymous |
 186    git-cvsserver --strict-paths --base-path "$WORKDIR" pserver "$SERVERDIR" >log 2>&1
 187'
 188
 189GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false || exit 1
 190
 191test_expect_success 'req_Root (export-all)' \
 192  'cat request-anonymous | git-cvsserver --export-all pserver "$WORKDIR" >log 2>&1 &&
 193   sed -ne \$p log | grep "^I LOVE YOU$"'
 194
 195test_expect_success 'req_Root failure (export-all w/o whitelist)' \
 196  '! (cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 || false)'
 197
 198test_expect_success 'req_Root (everything together)' \
 199  'cat request-base | git-cvsserver --export-all --strict-paths --base-path "$WORKDIR/" pserver "$SERVERDIR" >log 2>&1 &&
 200   sed -ne \$p log | grep "^I LOVE YOU$"'
 201
 202GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true || exit 1
 203
 204#--------------
 205# CONFIG TESTS
 206#--------------
 207
 208test_expect_success 'gitcvs.enabled = false' \
 209  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
 210   if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
 211   then
 212     echo unexpected cvs success
 213     false
 214   else
 215     true
 216   fi &&
 217   grep "GITCVS emulation disabled" cvs.log &&
 218   test ! -d cvswork2'
 219
 220rm -fr cvswork2
 221test_expect_success 'gitcvs.ext.enabled = true' \
 222  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
 223   GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false &&
 224   GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
 225   diff -q cvswork cvswork2'
 226
 227rm -fr cvswork2
 228test_expect_success 'gitcvs.ext.enabled = false' \
 229  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled false &&
 230   GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
 231   if GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1
 232   then
 233     echo unexpected cvs success
 234     false
 235   else
 236     true
 237   fi &&
 238   grep "GITCVS emulation disabled" cvs.log &&
 239   test ! -d cvswork2'
 240
 241rm -fr cvswork2
 242test_expect_success 'gitcvs.dbname' \
 243  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
 244   GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs.%a.%m.sqlite &&
 245   GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
 246   diff -q cvswork cvswork2 &&
 247   test -f "$SERVERDIR/gitcvs.ext.master.sqlite" &&
 248   cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs.ext.master.sqlite"'
 249
 250rm -fr cvswork2
 251test_expect_success 'gitcvs.ext.dbname' \
 252  'GIT_DIR="$SERVERDIR" git config --bool gitcvs.ext.enabled true &&
 253   GIT_DIR="$SERVERDIR" git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite &&
 254   GIT_DIR="$SERVERDIR" git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite &&
 255   GIT_CONFIG="$git_config" cvs -Q co -d cvswork2 master >cvs.log 2>&1 &&
 256   diff -q cvswork cvswork2 &&
 257   test -f "$SERVERDIR/gitcvs1.ext.master.sqlite" &&
 258   test ! -f "$SERVERDIR/gitcvs2.ext.master.sqlite" &&
 259   cmp "$SERVERDIR/gitcvs.master.sqlite" "$SERVERDIR/gitcvs1.ext.master.sqlite"'
 260
 261
 262#------------
 263# CVS UPDATE
 264#------------
 265
 266rm -fr "$SERVERDIR"
 267cd "$WORKDIR" &&
 268git clone -q --bare "$WORKDIR/.git" "$SERVERDIR" >/dev/null 2>&1 &&
 269GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true &&
 270GIT_DIR="$SERVERDIR" git config gitcvs.logfile "$SERVERDIR/gitcvs.log" ||
 271exit 1
 272
 273test_expect_success 'cvs update (create new file)' \
 274  'echo testfile1 >testfile1 &&
 275   git add testfile1 &&
 276   git commit -q -m "Add testfile1" &&
 277   git push gitcvs.git >/dev/null &&
 278   cd cvswork &&
 279   GIT_CONFIG="$git_config" cvs -Q update &&
 280   test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.1/" &&
 281   diff -q testfile1 ../testfile1'
 282
 283cd "$WORKDIR"
 284test_expect_success 'cvs update (update existing file)' \
 285  'echo line 2 >>testfile1 &&
 286   git add testfile1 &&
 287   git commit -q -m "Append to testfile1" &&
 288   git push gitcvs.git >/dev/null &&
 289   cd cvswork &&
 290   GIT_CONFIG="$git_config" cvs -Q update &&
 291   test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.2/" &&
 292   diff -q testfile1 ../testfile1'
 293
 294cd "$WORKDIR"
 295#TODO: cvsserver doesn't support update w/o -d
 296test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" '
 297   mkdir test &&
 298   echo >test/empty &&
 299   git add test &&
 300   git commit -q -m "Single Subdirectory" &&
 301   git push gitcvs.git >/dev/null &&
 302   cd cvswork &&
 303   GIT_CONFIG="$git_config" cvs -Q update &&
 304   test ! -d test
 305'
 306
 307cd "$WORKDIR"
 308test_expect_success 'cvs update (subdirectories)' \
 309  '(for dir in A A/B A/B/C A/D E; do
 310      mkdir $dir &&
 311      echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")"  &&
 312      git add $dir;
 313   done) &&
 314   git commit -q -m "deep sub directory structure" &&
 315   git push gitcvs.git >/dev/null &&
 316   cd cvswork &&
 317   GIT_CONFIG="$git_config" cvs -Q update -d &&
 318   (for dir in A A/B A/B/C A/D E; do
 319      filename="file_in_$(echo $dir|sed -e "s#/# #g")" &&
 320      if test "$(echo $(grep -v ^D $dir/CVS/Entries|cut -d/ -f2,3,5))" = "$filename/1.1/" &&
 321           diff -q "$dir/$filename" "../$dir/$filename"; then
 322        :
 323      else
 324        echo >failure
 325      fi
 326    done) &&
 327   test ! -f failure'
 328
 329cd "$WORKDIR"
 330test_expect_success 'cvs update (delete file)' \
 331  'git rm testfile1 &&
 332   git commit -q -m "Remove testfile1" &&
 333   git push gitcvs.git >/dev/null &&
 334   cd cvswork &&
 335   GIT_CONFIG="$git_config" cvs -Q update &&
 336   test -z "$(grep testfile1 CVS/Entries)" &&
 337   test ! -f testfile1'
 338
 339cd "$WORKDIR"
 340test_expect_success 'cvs update (re-add deleted file)' \
 341  'echo readded testfile >testfile1 &&
 342   git add testfile1 &&
 343   git commit -q -m "Re-Add testfile1" &&
 344   git push gitcvs.git >/dev/null &&
 345   cd cvswork &&
 346   GIT_CONFIG="$git_config" cvs -Q update &&
 347   test "$(echo $(grep testfile1 CVS/Entries|cut -d/ -f2,3,5))" = "testfile1/1.4/" &&
 348   diff -q testfile1 ../testfile1'
 349
 350cd "$WORKDIR"
 351test_expect_success 'cvs update (merge)' \
 352  'echo Line 0 >expected &&
 353   for i in 1 2 3 4 5 6 7
 354   do
 355     echo Line $i >>merge
 356     echo Line $i >>expected
 357   done &&
 358   echo Line 8 >>expected &&
 359   git add merge &&
 360   git commit -q -m "Merge test (pre-merge)" &&
 361   git push gitcvs.git >/dev/null &&
 362   cd cvswork &&
 363   GIT_CONFIG="$git_config" cvs -Q update &&
 364   test "$(echo $(grep merge CVS/Entries|cut -d/ -f2,3,5))" = "merge/1.1/" &&
 365   diff -q merge ../merge &&
 366   ( echo Line 0; cat merge ) >merge.tmp &&
 367   mv merge.tmp merge &&
 368   cd "$WORKDIR" &&
 369   echo Line 8 >>merge &&
 370   git add merge &&
 371   git commit -q -m "Merge test (merge)" &&
 372   git push gitcvs.git >/dev/null &&
 373   cd cvswork &&
 374   sleep 1 && touch merge &&
 375   GIT_CONFIG="$git_config" cvs -Q update &&
 376   diff -q merge ../expected'
 377
 378cd "$WORKDIR"
 379
 380cat >expected.C <<EOF
 381<<<<<<< merge.mine
 382Line 0
 383=======
 384LINE 0
 385>>>>>>> merge.3
 386EOF
 387
 388for i in 1 2 3 4 5 6 7 8
 389do
 390  echo Line $i >>expected.C
 391done
 392
 393test_expect_success 'cvs update (conflict merge)' \
 394  '( echo LINE 0; cat merge ) >merge.tmp &&
 395   mv merge.tmp merge &&
 396   git add merge &&
 397   git commit -q -m "Merge test (conflict)" &&
 398   git push gitcvs.git >/dev/null &&
 399   cd cvswork &&
 400   GIT_CONFIG="$git_config" cvs -Q update &&
 401   diff -q merge ../expected.C'
 402
 403cd "$WORKDIR"
 404test_expect_success 'cvs update (-C)' \
 405  'cd cvswork &&
 406   GIT_CONFIG="$git_config" cvs -Q update -C &&
 407   diff -q merge ../merge'
 408
 409cd "$WORKDIR"
 410test_expect_success 'cvs update (merge no-op)' \
 411   'echo Line 9 >>merge &&
 412    cp merge cvswork/merge &&
 413    git add merge &&
 414    git commit -q -m "Merge test (no-op)" &&
 415    git push gitcvs.git >/dev/null &&
 416    cd cvswork &&
 417    sleep 1 && touch merge &&
 418    GIT_CONFIG="$git_config" cvs -Q update &&
 419    diff -q merge ../merge'
 420
 421cd "$WORKDIR"
 422test_expect_success 'cvs update (-p)' '
 423    touch really-empty &&
 424    echo Line 1 > no-lf &&
 425    printf "Line 2" >> no-lf &&
 426    git add really-empty no-lf &&
 427    git commit -q -m "Update -p test" &&
 428    git push gitcvs.git >/dev/null &&
 429    cd cvswork &&
 430    GIT_CONFIG="$git_config" cvs update &&
 431    rm -f failures &&
 432    for i in merge no-lf empty really-empty; do
 433        GIT_CONFIG="$git_config" cvs update -p "$i" >$i.out
 434        diff $i.out ../$i >>failures 2>&1
 435    done &&
 436    test -z "$(cat failures)"
 437'
 438
 439cd "$WORKDIR"
 440test_expect_success 'cvs update (module list supports packed refs)' '
 441    GIT_DIR="$SERVERDIR" git pack-refs --all &&
 442    GIT_CONFIG="$git_config" cvs -n up -d 2> out &&
 443    grep "cvs update: New directory \`master'\''" < out
 444'
 445
 446#------------
 447# CVS STATUS
 448#------------
 449
 450cd "$WORKDIR"
 451test_expect_success 'cvs status' '
 452    mkdir status.dir &&
 453    echo Line > status.dir/status.file &&
 454    echo Line > status.file &&
 455    git add status.dir status.file &&
 456    git commit -q -m "Status test" &&
 457    git push gitcvs.git >/dev/null &&
 458    cd cvswork &&
 459    GIT_CONFIG="$git_config" cvs update &&
 460    GIT_CONFIG="$git_config" cvs status | grep "^File: status.file" >../out &&
 461    test $(wc -l <../out) = 2
 462'
 463
 464cd "$WORKDIR"
 465test_expect_success 'cvs status (nonrecursive)' '
 466    cd cvswork &&
 467    GIT_CONFIG="$git_config" cvs status -l | grep "^File: status.file" >../out &&
 468    test $(wc -l <../out) = 1
 469'
 470
 471cd "$WORKDIR"
 472test_expect_success 'cvs status (no subdirs in header)' '
 473    cd cvswork &&
 474    GIT_CONFIG="$git_config" cvs status | grep ^File: >../out &&
 475    ! grep / <../out
 476'
 477
 478#------------
 479# CVS CHECKOUT
 480#------------
 481
 482cd "$WORKDIR"
 483test_expect_success 'cvs co -c (shows module database)' '
 484    GIT_CONFIG="$git_config" cvs co -c > out &&
 485    grep "^master[       ]\+master$" < out &&
 486    ! grep -v "^master[  ]\+master$" < out
 487'
 488
 489#------------
 490# CVS ANNOTATE
 491#------------
 492
 493cd "$WORKDIR"
 494test_expect_success 'cvs annotate' '
 495    cd cvswork &&
 496    GIT_CONFIG="$git_config" cvs annotate merge >../out &&
 497    sed -e "s/ .*//" ../out >../actual &&
 498    for i in 3 1 1 1 1 1 1 1 2 4; do echo 1.$i; done >../expect &&
 499    test_cmp ../expect ../actual
 500'
 501
 502test_done