t / lib-git-svn.shon commit t0027: do not use an empty string as a pathspec element (229a95a)
   1. ./test-lib.sh
   2
   3if test -n "$NO_SVN_TESTS"
   4then
   5        skip_all='skipping git svn tests, NO_SVN_TESTS defined'
   6        test_done
   7fi
   8if ! test_have_prereq PERL; then
   9        skip_all='skipping git svn tests, perl not available'
  10        test_done
  11fi
  12
  13GIT_DIR=$PWD/.git
  14GIT_SVN_DIR=$GIT_DIR/svn/refs/remotes/git-svn
  15SVN_TREE=$GIT_SVN_DIR/svn-tree
  16
  17svn >/dev/null 2>&1
  18if test $? -ne 1
  19then
  20    skip_all='skipping git svn tests, svn not found'
  21    test_done
  22fi
  23
  24svnrepo=$PWD/svnrepo
  25export svnrepo
  26svnconf=$PWD/svnconf
  27export svnconf
  28
  29perl -w -e "
  30use SVN::Core;
  31use SVN::Repos;
  32\$SVN::Core::VERSION gt '1.1.0' or exit(42);
  33system(qw/svnadmin create --fs-type fsfs/, \$ENV{svnrepo}) == 0 or exit(41);
  34" >&3 2>&4
  35x=$?
  36if test $x -ne 0
  37then
  38        if test $x -eq 42; then
  39                skip_all='Perl SVN libraries must be >= 1.1.0'
  40        elif test $x -eq 41; then
  41                skip_all='svnadmin failed to create fsfs repository'
  42        else
  43                skip_all='Perl SVN libraries not found or unusable'
  44        fi
  45        test_done
  46fi
  47
  48rawsvnrepo="$svnrepo"
  49svnrepo="file://$svnrepo"
  50
  51poke() {
  52        test-chmtime +1 "$1"
  53}
  54
  55# We need this, because we should pass empty configuration directory to
  56# the 'svn commit' to avoid automated property changes and other stuff
  57# that could be set from user's configuration files in ~/.subversion.
  58svn_cmd () {
  59        [ -d "$svnconf" ] || mkdir "$svnconf"
  60        orig_svncmd="$1"; shift
  61        if [ -z "$orig_svncmd" ]; then
  62                svn
  63                return
  64        fi
  65        svn "$orig_svncmd" --config-dir "$svnconf" "$@"
  66}
  67
  68prepare_httpd () {
  69        for d in \
  70                "$SVN_HTTPD_PATH" \
  71                /usr/sbin/apache2 \
  72                /usr/sbin/httpd \
  73        ; do
  74                if test -f "$d"
  75                then
  76                        SVN_HTTPD_PATH="$d"
  77                        break
  78                fi
  79        done
  80        if test -z "$SVN_HTTPD_PATH"
  81        then
  82                echo >&2 '*** error: Apache not found'
  83                return 1
  84        fi
  85        for d in \
  86                "$SVN_HTTPD_MODULE_PATH" \
  87                /usr/lib/apache2/modules \
  88                /usr/libexec/apache2 \
  89        ; do
  90                if test -d "$d"
  91                then
  92                        SVN_HTTPD_MODULE_PATH="$d"
  93                        break
  94                fi
  95        done
  96        if test -z "$SVN_HTTPD_MODULE_PATH"
  97        then
  98                echo >&2 '*** error: Apache module dir not found'
  99                return 1
 100        fi
 101        if test ! -f "$SVN_HTTPD_MODULE_PATH/mod_dav_svn.so"
 102        then
 103                echo >&2 '*** error: Apache module "mod_dav_svn" not found'
 104                return 1
 105        fi
 106
 107        repo_base_path="${1-svn}"
 108        mkdir "$GIT_DIR"/logs
 109
 110        cat > "$GIT_DIR/httpd.conf" <<EOF
 111ServerName "git svn test"
 112ServerRoot "$GIT_DIR"
 113DocumentRoot "$GIT_DIR"
 114PidFile "$GIT_DIR/httpd.pid"
 115LockFile logs/accept.lock
 116Listen 127.0.0.1:$SVN_HTTPD_PORT
 117LoadModule dav_module $SVN_HTTPD_MODULE_PATH/mod_dav.so
 118LoadModule dav_svn_module $SVN_HTTPD_MODULE_PATH/mod_dav_svn.so
 119<Location /$repo_base_path>
 120        DAV svn
 121        SVNPath "$rawsvnrepo"
 122</Location>
 123EOF
 124}
 125
 126start_httpd () {
 127        if test -z "$SVN_HTTPD_PORT"
 128        then
 129                echo >&2 'SVN_HTTPD_PORT is not defined!'
 130                return
 131        fi
 132
 133        prepare_httpd "$1" || return 1
 134
 135        "$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k start
 136        svnrepo="http://127.0.0.1:$SVN_HTTPD_PORT/$repo_base_path"
 137}
 138
 139stop_httpd () {
 140        test -z "$SVN_HTTPD_PORT" && return
 141        test ! -f "$GIT_DIR/httpd.conf" && return
 142        "$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k stop
 143}
 144
 145convert_to_rev_db () {
 146        perl -w -- - "$@" <<\EOF
 147use strict;
 148@ARGV == 2 or die "usage: convert_to_rev_db <input> <output>";
 149open my $wr, '+>', $ARGV[1] or die "$!: couldn't open: $ARGV[1]";
 150open my $rd, '<', $ARGV[0] or die "$!: couldn't open: $ARGV[0]";
 151my $size = (stat($rd))[7];
 152($size % 24) == 0 or die "Inconsistent size: $size";
 153while (sysread($rd, my $buf, 24) == 24) {
 154        my ($r, $c) = unpack('NH40', $buf);
 155        my $offset = $r * 41;
 156        seek $wr, 0, 2 or die $!;
 157        my $pos = tell $wr;
 158        if ($pos < $offset) {
 159                for (1 .. (($offset - $pos) / 41)) {
 160                        print $wr (('0' x 40),"\n") or die $!;
 161                }
 162        }
 163        seek $wr, $offset, 0 or die $!;
 164        print $wr $c,"\n" or die $!;
 165}
 166close $wr or die $!;
 167close $rd or die $!;
 168EOF
 169}
 170
 171require_svnserve () {
 172    if test -z "$SVNSERVE_PORT"
 173    then
 174        skip_all='skipping svnserve test. (set $SVNSERVE_PORT to enable)'
 175        test_done
 176    fi
 177}
 178
 179start_svnserve () {
 180    svnserve --listen-port $SVNSERVE_PORT \
 181             --root "$rawsvnrepo" \
 182             --listen-once \
 183             --listen-host 127.0.0.1 &
 184}
 185
 186prepare_a_utf8_locale () {
 187        a_utf8_locale=$(locale -a | sed -n '/\.[uU][tT][fF]-*8$/{
 188        p
 189        q
 190}')
 191        if test -n "$a_utf8_locale"
 192        then
 193                test_set_prereq UTF8
 194        else
 195                say "# UTF-8 locale not available, some tests are skipped"
 196        fi
 197}