1#!/bin/sh 2 3# File: test-mtn2svn.include 4# 5# This is an include for all other tests. 6# Tested with monotone 0.35, Subversion Version 1.3.0 (r17949) 7# 8# Can enable shared base dir by setting "SHAREDDIR=yes" before start 9# scripts "test-mtn2svn-*.sh". Default is off. 10 11STARTDIR=$PWD 12 13# Fast exit, if no backend installed 14which mtn >/dev/null 2>&1 || exit 201 15which svn >/dev/null 2>&1 || exit 201 16 17# Exit immediately if a command exits with a non-zero 18set -e 19 20# Remove monotone keypair, because Tailor is bootstrapping it again (see patch) 21rm -f $HOME/.monotone/keys/key-dummy 22 23# Create a new empty tempdirectory and work there. 24rm -rf testdir 25mkdir testdir 26cd testdir 27 28# Runs with Shared basedir? 29if [ -n "$SHAREDDIR" ] 30then 31 SOURCEDIR="shared-dir" 32 TARGETDIR="shared-dir" 33else 34 SOURCEDIR="source-side" 35 TARGETDIR="target-side" 36fi 37 38# execute monotone with more params 39mtn_exec() 40{ 41 mtn --norc --keydir=$KEYDIR --rcfile=$LUA "$@" 42} 43 44monotone_setup() 45{ 46 # Don't use global users keys here 47 KEYDIR=$PWD/test-monotone_keys 48 LUA=$PWD/test-monotone.lua 49 50 # Create keypair for testing 51 cat <<EOF >$LUA 52function get_passphrase(keypair_id) 53 if (keypair_id == "key-dummy") then return "secret" end 54end 55EOF 56 57 echo "secret" | mtn --norc --keydir=$KEYDIR genkey "key-dummy" 58 59 # Create a new data base with a branch 60 mtn_exec --db=test1.mtn db init 61 mtn_exec --db=test1.mtn --key="key-dummy" --branch=A setup monotone-work 62 63 cd monotone-work 64} 65 66tailor_mtn2svn() 67{ 68 69 # create first config for tailor 70 cat <<EOF >test-mtn-svn-forward.conf 71[DEFAULT] 72patch-name-format = "" 73use-propset = True 74#verbose = True 75#Debug = True 76 77[project] 78root-directory = $PWD/rootdir 79source = monotone:source 80target = svn:target 81 82[monotone:source] 83repository = $PWD/test1.mtn 84module = A 85subdir = $SOURCEDIR 86 87[svn:target] 88repository = file://$PWD/svnrepository 89module = A 90subdir = $TARGETDIR 91#tags-path = my-taged-vers 92#commit-all-files = False 93EOF 94 95 # Convert from Monotone to Subversion 96 tailor -c test-mtn-svn-forward.conf 97} 98 99 100tailor_svn2mtn() 101{ 102 103 # create a second config for tailor 104 cat <<EOF >test-mtn-svn-backward.conf 105[DEFAULT] 106patch-name-format = "" 107use-propset = True 108#verbose = True 109#Debug = True 110 111[project] 112root-directory = $PWD/rootdir-back 113target = monotone:target 114source = svn:source 115 116[monotone:target] 117repository = $PWD/test2.mtn 118module = A 119subdir = $SOURCEDIR 120keygenid = key-dummy 121passphrase = secret 122 123[svn:source] 124repository = file://$PWD/svnrepository 125module = A 126subdir = $TARGETDIR 127EOF 128 129 # Convert back from Subversion to Monotone 130 tailor -c test-mtn-svn-backward.conf 131} 132 133cat <<EOF >diffexclude 134.mt* 135_MTN 136.svn 137EOF 138 139target_diff1() 140{ 141 if diff -Naur -X diffexclude monotone-work rootdir/$TARGETDIR >test0a.log 142 then 143 echo "WD-diff: PASS" 144 else 145 echo "WD-diff: Diffs in Working Dir! (step mtn-->svn, see test0a.log)" >&2 146 exit 101 147 fi 148} 149 150target_diff2() 151{ 152 if diff -Naur -X diffexclude monotone-work rootdir-back/$TARGETDIR >test0b.log 153 then 154 echo "WD-diff: PASS" 155 else 156 echo "WD-diff: Diffs in Working Dir! (step svn-->mtn, see test0b.log)" >&2 157 exit 102 158 fi 159} 160 161monotone_logs() 162{ 163 # Create a log to see into: 164 LANG=C mtn --db=test1.mtn log --from `mtn --db=test1.mtn automate heads A` --no-graph > test1.log 165 LANG=C mtn --db=test2.mtn log --from `mtn --db=test2.mtn automate heads A` --no-graph > test2.log 166 167 # Bug from Monotone: Starts with "Added directories:", but no dirs listend. 168 # Replace or remove stubs. 169 170 sed -r -e 's/^((Revision|Ancestor): )([0-9a-f]{40})?$/\1STUB-NUMBER/' < test1.log \ 171 | sed -r -e \ '/^Added directories:$/,+1s/^.+$/REMOVE-STUBS/' \ 172 | grep -v -E "REMOVE-STUBS" \ 173 > test1-v.log 174 sed -r -e 's/^((Revision|Ancestor): )([0-9a-f]{40})?$/\1STUB-NUMBER/' < test2.log \ 175 | sed -r -e \ '/^Added directories:$/,+1s/^.+$/REMOVE-STUBS/' \ 176 | grep -v -E "REMOVE-STUBS" \ 177 | head -n -11 \ 178 > test2-v.log 179 180 # Compair logs 181 if diff -B test1-v.log test2-v.log >/dev/null 182 then 183 echo "Log-diff: PASS" 184 else 185 echo "Log-diff: Logs are different!" >&2 186 exit 200 187 fi 188} 189 190testing_runs() 191{ 192 cd .. 193 tailor_mtn2svn 194 target_diff1 195 tailor_svn2mtn 196 target_diff2 197 monotone_logs 198 cd $STARTDIR 199} 200