blob: b0ec12ff6cbcdd7352b764db32bc34340b37fc8a [file] [log] [blame]
Eric Wong36f5b1f2006-05-23 19:23:41 -07001. ./test-lib.sh
2
Nanako Shiraishi16805d32008-09-08 19:02:05 +09003remotes_git_svn=remotes/git""-svn
4git_svn_id=git""-svn-id
5
Eric Wong60d02cc2006-07-06 00:14:16 -07006if test -n "$NO_SVN_TESTS"
7then
Ævar Arnfjörð Bjarmasonfadb5152010-06-24 17:44:48 +00008 skip_all='skipping git svn tests, NO_SVN_TESTS defined'
Eric Wong60d02cc2006-07-06 00:14:16 -07009 test_done
Eric Wong60d02cc2006-07-06 00:14:16 -070010fi
Jeff King1b19ccd2009-04-03 15:33:59 -040011if ! test_have_prereq PERL; then
Ævar Arnfjörð Bjarmasonfadb5152010-06-24 17:44:48 +000012 skip_all='skipping git svn tests, perl not available'
Jeff King1b19ccd2009-04-03 15:33:59 -040013 test_done
14fi
Eric Wong60d02cc2006-07-06 00:14:16 -070015
Eric Wong36f5b1f2006-05-23 19:23:41 -070016GIT_DIR=$PWD/.git
Adam Brewster6f5748e2009-08-11 23:14:27 -040017GIT_SVN_DIR=$GIT_DIR/svn/refs/remotes/git-svn
Eric Wonga5e0ced2006-06-12 15:23:48 -070018SVN_TREE=$GIT_SVN_DIR/svn-tree
Eric Wong36f5b1f2006-05-23 19:23:41 -070019
Eric Wong36f5b1f2006-05-23 19:23:41 -070020svn >/dev/null 2>&1
Junio C Hamano4b832e82006-07-07 03:17:16 -070021if test $? -ne 1
Eric Wong36f5b1f2006-05-23 19:23:41 -070022then
Ævar Arnfjörð Bjarmasone8344e82010-07-08 01:16:06 +000023 skip_all='skipping git svn tests, svn not found'
Eric Wong36f5b1f2006-05-23 19:23:41 -070024 test_done
Eric Wong36f5b1f2006-05-23 19:23:41 -070025fi
26
27svnrepo=$PWD/svnrepo
Bryan Donlancdf3ec02008-05-04 01:37:57 -040028export svnrepo
Eygene Ryabinkinda083d62009-05-08 12:06:16 +040029svnconf=$PWD/svnconf
30export svnconf
Eric Wong36f5b1f2006-05-23 19:23:41 -070031
Jeff King94221d22013-10-28 21:23:03 -040032perl -w -e "
Eric Wongc6d499a2006-12-31 21:49:45 -080033use SVN::Core;
34use SVN::Repos;
35\$SVN::Core::VERSION gt '1.1.0' or exit(42);
Bryan Donlancdf3ec02008-05-04 01:37:57 -040036system(qw/svnadmin create --fs-type fsfs/, \$ENV{svnrepo}) == 0 or exit(41);
Shawn O. Pearce38434f22007-01-14 03:22:47 -050037" >&3 2>&4
Eric Wongc6d499a2006-12-31 21:49:45 -080038x=$?
39if test $x -ne 0
Eric Wongdc62e252006-06-28 03:07:14 -070040then
Eric Wongc6d499a2006-12-31 21:49:45 -080041 if test $x -eq 42; then
Ævar Arnfjörð Bjarmasone8344e82010-07-08 01:16:06 +000042 skip_all='Perl SVN libraries must be >= 1.1.0'
Eric Wonge66191f2007-01-13 02:47:53 -080043 elif test $x -eq 41; then
Ævar Arnfjörð Bjarmasone8344e82010-07-08 01:16:06 +000044 skip_all='svnadmin failed to create fsfs repository'
Eric Wongc6d499a2006-12-31 21:49:45 -080045 else
Ævar Arnfjörð Bjarmasone8344e82010-07-08 01:16:06 +000046 skip_all='Perl SVN libraries not found or unusable'
Eric Wongc6d499a2006-12-31 21:49:45 -080047 fi
Eric Wongc6d499a2006-12-31 21:49:45 -080048 test_done
Eric Wongdc62e252006-06-28 03:07:14 -070049fi
50
sam@vilain.net2edb9c52006-12-05 16:17:38 +110051rawsvnrepo="$svnrepo"
Eric Wonge1516112006-11-27 21:46:50 -080052svnrepo="file://$svnrepo"
Eric Wong36f5b1f2006-05-23 19:23:41 -070053
Michael Spang7b3fab82007-02-12 19:33:37 -050054poke() {
Eric Wong56cf9802007-02-24 16:59:52 -080055 test-chmtime +1 "$1"
Michael Spang7b3fab82007-02-12 19:33:37 -050056}
Eric Wong29633bb2007-07-15 21:53:50 -070057
Eygene Ryabinkinda083d62009-05-08 12:06:16 +040058# We need this, because we should pass empty configuration directory to
59# the 'svn commit' to avoid automated property changes and other stuff
60# that could be set from user's configuration files in ~/.subversion.
61svn_cmd () {
62 [ -d "$svnconf" ] || mkdir "$svnconf"
63 orig_svncmd="$1"; shift
64 if [ -z "$orig_svncmd" ]; then
65 svn
66 return
67 fi
68 svn "$orig_svncmd" --config-dir "$svnconf" "$@"
69}
70
Ramsay Jones3aa30472010-12-30 19:44:48 +000071prepare_httpd () {
Ramsay Jonesb6fe9742010-12-14 18:22:29 +000072 for d in \
73 "$SVN_HTTPD_PATH" \
74 /usr/sbin/apache2 \
75 /usr/sbin/httpd \
76 ; do
77 if test -f "$d"
78 then
79 SVN_HTTPD_PATH="$d"
80 break
81 fi
82 done
Ramsay Jonescff484a2010-12-14 18:25:11 +000083 if test -z "$SVN_HTTPD_PATH"
84 then
Ramsay Jones3aa30472010-12-30 19:44:48 +000085 echo >&2 '*** error: Apache not found'
86 return 1
Ramsay Jonescff484a2010-12-14 18:25:11 +000087 fi
Ramsay Jonesb6fe9742010-12-14 18:22:29 +000088 for d in \
89 "$SVN_HTTPD_MODULE_PATH" \
90 /usr/lib/apache2/modules \
91 /usr/libexec/apache2 \
92 ; do
93 if test -d "$d"
94 then
95 SVN_HTTPD_MODULE_PATH="$d"
96 break
97 fi
98 done
Ramsay Jonescff484a2010-12-14 18:25:11 +000099 if test -z "$SVN_HTTPD_MODULE_PATH"
100 then
Ramsay Jones3aa30472010-12-30 19:44:48 +0000101 echo >&2 '*** error: Apache module dir not found'
102 return 1
Ramsay Jonescff484a2010-12-14 18:25:11 +0000103 fi
Ramsay Jones3aa30472010-12-30 19:44:48 +0000104 if test ! -f "$SVN_HTTPD_MODULE_PATH/mod_dav_svn.so"
Eric Wong29633bb2007-07-15 21:53:50 -0700105 then
Ramsay Jones3aa30472010-12-30 19:44:48 +0000106 echo >&2 '*** error: Apache module "mod_dav_svn" not found'
107 return 1
Eric Wongd1a8d0e2008-05-10 17:14:49 -0700108 fi
Eric Wong29633bb2007-07-15 21:53:50 -0700109
Ramsay Jones3aa30472010-12-30 19:44:48 +0000110 repo_base_path="${1-svn}"
Eric Wong29633bb2007-07-15 21:53:50 -0700111 mkdir "$GIT_DIR"/logs
112
113 cat > "$GIT_DIR/httpd.conf" <<EOF
Nanako Shiraishi1364ff22008-09-08 19:02:08 +0900114ServerName "git svn test"
Eric Wong29633bb2007-07-15 21:53:50 -0700115ServerRoot "$GIT_DIR"
116DocumentRoot "$GIT_DIR"
117PidFile "$GIT_DIR/httpd.pid"
Kevin Ballard3644da72008-03-21 03:27:35 -0400118LockFile logs/accept.lock
Eric Wong29633bb2007-07-15 21:53:50 -0700119Listen 127.0.0.1:$SVN_HTTPD_PORT
120LoadModule dav_module $SVN_HTTPD_MODULE_PATH/mod_dav.so
121LoadModule dav_svn_module $SVN_HTTPD_MODULE_PATH/mod_dav_svn.so
Eric Wongd1a8d0e2008-05-10 17:14:49 -0700122<Location /$repo_base_path>
Eric Wong29633bb2007-07-15 21:53:50 -0700123 DAV svn
Eric Wong3901a8c2008-07-14 02:13:56 -0700124 SVNPath "$rawsvnrepo"
Eric Wong29633bb2007-07-15 21:53:50 -0700125</Location>
126EOF
Ramsay Jones3aa30472010-12-30 19:44:48 +0000127}
128
129start_httpd () {
130 if test -z "$SVN_HTTPD_PORT"
131 then
132 echo >&2 'SVN_HTTPD_PORT is not defined!'
133 return
134 fi
135
136 prepare_httpd "$1" || return 1
137
Eric Wong29633bb2007-07-15 21:53:50 -0700138 "$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k start
Eric Wongd1a8d0e2008-05-10 17:14:49 -0700139 svnrepo="http://127.0.0.1:$SVN_HTTPD_PORT/$repo_base_path"
Eric Wong29633bb2007-07-15 21:53:50 -0700140}
141
142stop_httpd () {
143 test -z "$SVN_HTTPD_PORT" && return
Ramsay Jones3aa30472010-12-30 19:44:48 +0000144 test ! -f "$GIT_DIR/httpd.conf" && return
Eric Wong29633bb2007-07-15 21:53:50 -0700145 "$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k stop
146}
Eric Wong060610c2007-12-08 23:27:41 -0800147
148convert_to_rev_db () {
Jeff King94221d22013-10-28 21:23:03 -0400149 perl -w -- - "$@" <<\EOF
Eric Wong060610c2007-12-08 23:27:41 -0800150use strict;
David Aguilarb9784032013-02-24 14:48:39 -0800151@ARGV == 2 or die "usage: convert_to_rev_db <input> <output>";
Eric Wong060610c2007-12-08 23:27:41 -0800152open my $wr, '+>', $ARGV[1] or die "$!: couldn't open: $ARGV[1]";
153open my $rd, '<', $ARGV[0] or die "$!: couldn't open: $ARGV[0]";
154my $size = (stat($rd))[7];
155($size % 24) == 0 or die "Inconsistent size: $size";
156while (sysread($rd, my $buf, 24) == 24) {
157 my ($r, $c) = unpack('NH40', $buf);
158 my $offset = $r * 41;
159 seek $wr, 0, 2 or die $!;
160 my $pos = tell $wr;
161 if ($pos < $offset) {
162 for (1 .. (($offset - $pos) / 41)) {
163 print $wr (('0' x 40),"\n") or die $!;
164 }
165 }
166 seek $wr, $offset, 0 or die $!;
167 print $wr $c,"\n" or die $!;
168}
169close $wr or die $!;
170close $rd or die $!;
171EOF
172}
Alec Berrymandd9da512008-09-14 17:14:15 -0400173
174require_svnserve () {
175 if test -z "$SVNSERVE_PORT"
176 then
Ævar Arnfjörð Bjarmasone8344e82010-07-08 01:16:06 +0000177 skip_all='skipping svnserve test. (set $SVNSERVE_PORT to enable)'
Alec Berrymandd9da512008-09-14 17:14:15 -0400178 test_done
Alec Berrymandd9da512008-09-14 17:14:15 -0400179 fi
180}
181
182start_svnserve () {
183 svnserve --listen-port $SVNSERVE_PORT \
184 --root "$rawsvnrepo" \
185 --listen-once \
186 --listen-host 127.0.0.1 &
187}
188