doc: add verb in front of command to run
[git/git-svn.git] / t / lib-git-svn.sh
blobfb8823224e9ed2452c32e847bf53dbc4da116f1b
1 . ./test-lib.sh
3 if test -n "$NO_SVN_TESTS"
4 then
5 skip_all='skipping git svn tests, NO_SVN_TESTS defined'
6 test_done
7 fi
8 if ! test_have_prereq PERL; then
9 skip_all='skipping git svn tests, perl not available'
10 test_done
13 GIT_DIR=$PWD/.git
14 GIT_SVN_DIR=$GIT_DIR/svn/refs/remotes/git-svn
15 SVN_TREE=$GIT_SVN_DIR/svn-tree
17 svn >/dev/null 2>&1
18 if test $? -ne 1
19 then
20 skip_all='skipping git svn tests, svn not found'
21 test_done
24 svnrepo=$PWD/svnrepo
25 export svnrepo
26 svnconf=$PWD/svnconf
27 export svnconf
29 perl -w -e "
30 use SVN::Core;
31 use SVN::Repos;
32 \$SVN::Core::VERSION gt '1.1.0' or exit(42);
33 system(qw/svnadmin create --fs-type fsfs/, \$ENV{svnrepo}) == 0 or exit(41);
34 " >&3 2>&4
35 x=$?
36 if test $x -ne 0
37 then
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'
45 test_done
48 rawsvnrepo="$svnrepo"
49 svnrepo="file://$svnrepo"
51 poke() {
52 test-chmtime +1 "$1"
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.
58 svn_cmd () {
59 [ -d "$svnconf" ] || mkdir "$svnconf"
60 orig_svncmd="$1"; shift
61 if [ -z "$orig_svncmd" ]; then
62 svn
63 return
65 svn "$orig_svncmd" --config-dir "$svnconf" "$@"
68 prepare_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
79 done
80 if test -z "$SVN_HTTPD_PATH"
81 then
82 echo >&2 '*** error: Apache not found'
83 return 1
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
95 done
96 if test -z "$SVN_HTTPD_MODULE_PATH"
97 then
98 echo >&2 '*** error: Apache module dir not found'
99 return 1
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
107 repo_base_path="${1-svn}"
108 mkdir "$GIT_DIR"/logs
110 cat > "$GIT_DIR/httpd.conf" <<EOF
111 ServerName "git svn test"
112 ServerRoot "$GIT_DIR"
113 DocumentRoot "$GIT_DIR"
114 PidFile "$GIT_DIR/httpd.pid"
115 LockFile logs/accept.lock
116 Listen 127.0.0.1:$SVN_HTTPD_PORT
117 LoadModule dav_module $SVN_HTTPD_MODULE_PATH/mod_dav.so
118 LoadModule dav_svn_module $SVN_HTTPD_MODULE_PATH/mod_dav_svn.so
119 <Location /$repo_base_path>
120 DAV svn
121 SVNPath "$rawsvnrepo"
122 </Location>
126 start_httpd () {
127 if test -z "$SVN_HTTPD_PORT"
128 then
129 echo >&2 'SVN_HTTPD_PORT is not defined!'
130 return
133 prepare_httpd "$1" || return 1
135 "$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k start
136 svnrepo="http://127.0.0.1:$SVN_HTTPD_PORT/$repo_base_path"
139 stop_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
145 convert_to_rev_db () {
146 perl -w -- - "$@" <<\EOF
147 use strict;
148 @ARGV == 2 or die "usage: convert_to_rev_db <input> <output>";
149 open my $wr, '+>', $ARGV[1] or die "$!: couldn't open: $ARGV[1]";
150 open my $rd, '<', $ARGV[0] or die "$!: couldn't open: $ARGV[0]";
151 my $size = (stat($rd))[7];
152 ($size % 24) == 0 or die "Inconsistent size: $size";
153 while (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 $!;
163 seek $wr, $offset, 0 or die $!;
164 print $wr $c,"\n" or die $!;
166 close $wr or die $!;
167 close $rd or die $!;
171 require_svnserve () {
172 if test -z "$SVNSERVE_PORT"
173 then
174 skip_all='skipping svnserve test. (set $SVNSERVE_PORT to enable)'
175 test_done
179 start_svnserve () {
180 svnserve --listen-port $SVNSERVE_PORT \
181 --root "$rawsvnrepo" \
182 --listen-once \
183 --listen-host 127.0.0.1 &
186 prepare_a_utf8_locale () {
187 a_utf8_locale=$(locale -a | sed -n '/\.[uU][tT][fF]-*8$/{
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"