t / lib-git-svn.shon commit Merge branch 'js/clean-report-too-long-a-path' into maint (17952bd)
   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
  16test_set_port SVNSERVE_PORT
  17
  18svn >/dev/null 2>&1
  19if test $? -ne 1
  20then
  21        skip_all='skipping git svn tests, svn not found'
  22        test_done
  23fi
  24
  25svnrepo=$PWD/svnrepo
  26export svnrepo
  27svnconf=$PWD/svnconf
  28export svnconf
  29
  30perl -w -e "
  31use SVN::Core;
  32use SVN::Repos;
  33\$SVN::Core::VERSION gt '1.1.0' or exit(42);
  34system(qw/svnadmin create --fs-type fsfs/, \$ENV{svnrepo}) == 0 or exit(41);
  35" >&3 2>&4
  36x=$?
  37if test $x -ne 0
  38then
  39        if test $x -eq 42; then
  40                skip_all='Perl SVN libraries must be >= 1.1.0'
  41        elif test $x -eq 41; then
  42                skip_all='svnadmin failed to create fsfs repository'
  43        else
  44                skip_all='Perl SVN libraries not found or unusable'
  45        fi
  46        test_done
  47fi
  48
  49rawsvnrepo="$svnrepo"
  50svnrepo="file://$svnrepo"
  51
  52poke() {
  53        test-tool chmtime +1 "$1"
  54}
  55
  56# We need this, because we should pass empty configuration directory to
  57# the 'svn commit' to avoid automated property changes and other stuff
  58# that could be set from user's configuration files in ~/.subversion.
  59svn_cmd () {
  60        [ -d "$svnconf" ] || mkdir "$svnconf"
  61        orig_svncmd="$1"; shift
  62        if [ -z "$orig_svncmd" ]; then
  63                svn
  64                return
  65        fi
  66        svn "$orig_svncmd" --config-dir "$svnconf" "$@"
  67}
  68
  69maybe_start_httpd () {
  70        loc=${1-svn}
  71
  72        test_tristate GIT_SVN_TEST_HTTPD
  73        case $GIT_SVN_TEST_HTTPD in
  74        true)
  75                . "$TEST_DIRECTORY"/lib-httpd.sh
  76                LIB_HTTPD_SVN="$loc"
  77                start_httpd
  78                ;;
  79        esac
  80}
  81
  82convert_to_rev_db () {
  83        perl -w -- - "$@" <<\EOF
  84use strict;
  85@ARGV == 2 or die "usage: convert_to_rev_db <input> <output>";
  86open my $wr, '+>', $ARGV[1] or die "$!: couldn't open: $ARGV[1]";
  87open my $rd, '<', $ARGV[0] or die "$!: couldn't open: $ARGV[0]";
  88my $size = (stat($rd))[7];
  89($size % 24) == 0 or die "Inconsistent size: $size";
  90while (sysread($rd, my $buf, 24) == 24) {
  91        my ($r, $c) = unpack('NH40', $buf);
  92        my $offset = $r * 41;
  93        seek $wr, 0, 2 or die $!;
  94        my $pos = tell $wr;
  95        if ($pos < $offset) {
  96                for (1 .. (($offset - $pos) / 41)) {
  97                        print $wr (('0' x 40),"\n") or die $!;
  98                }
  99        }
 100        seek $wr, $offset, 0 or die $!;
 101        print $wr $c,"\n" or die $!;
 102}
 103close $wr or die $!;
 104close $rd or die $!;
 105EOF
 106}
 107
 108require_svnserve () {
 109        test_tristate GIT_TEST_SVNSERVE
 110        if ! test "$GIT_TEST_SVNSERVE" = true
 111        then
 112                skip_all='skipping svnserve test. (set $GIT_TEST_SVNSERVE to enable)'
 113                test_done
 114        fi
 115}
 116
 117start_svnserve () {
 118        svnserve --listen-port $SVNSERVE_PORT \
 119                 --root "$rawsvnrepo" \
 120                 --listen-once \
 121                 --listen-host 127.0.0.1 &
 122}
 123
 124prepare_a_utf8_locale () {
 125        a_utf8_locale=$(locale -a | sed -n '/\.[uU][tT][fF]-*8$/{
 126        p
 127        q
 128}')
 129        if test -n "$a_utf8_locale"
 130        then
 131                test_set_prereq UTF8
 132        else
 133                say "# UTF-8 locale not available, some tests are skipped"
 134        fi
 135}