#!/bin/bash
# ------------------------------------------------------------------------------
# Copyright (C) 2006-2021 British Crown (Met Office) & Contributors.
#
# This file is part of FCM, tools for managing and building source code.
#
# FCM is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FCM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with FCM. If not, see <http://www.gnu.org/licenses/>.
# ------------------------------------------------------------------------------
# Optional enviroment variables:
#   TEST_REMOTE_HOST (tests using svn+ssh repositories located on given host)
# ------------------------------------------------------------------------------

. $(dirname $0)/../lib/bash/svn_test_header

function init_repos_layout_roses() {
    if [[ -n ${TEST_REMOTE_HOST:-} ]]; then
        TEST_REMOTE_DIR=$(ssh $TEST_REMOTE_HOST "mktemp -d")
        ssh $TEST_REMOTE_HOST "svnadmin create --fs-type fsfs $TEST_REMOTE_DIR"
        REPOS_URL="svn+ssh://${TEST_REMOTE_HOST}$TEST_REMOTE_DIR"
    else
        svnadmin create --fs-type fsfs $TEST_DIR/test_repos
        REPOS_URL="file://$TEST_DIR/test_repos"
    fi
    svn mkdir -q -m " " --parents $REPOS_URL/a/a/0/0/0/trunk
    svn import -q $TEST_SOURCE_DIR/../etc/repo_files \
        $REPOS_URL/a/a/0/0/0/trunk -m "initial trunk import"
    TMPFILE=$(mktemp)
    cat >$TMPFILE <<__LAYOUT__
depth-project = 5
depth-branch = 1
depth-tag = 1
dir-trunk = trunk
dir-branch =
dir-tag =
level-owner-branch =
level-owner-tag =
template-branch =
template-tag =
__LAYOUT__
    TMPDIR=$(mktemp -d)
    svn checkout -q $REPOS_URL $TMPDIR
    svn propset -q --file=$TMPFILE fcm:layout $TMPDIR
    svn commit -q -m " " $TMPDIR
    rm -f $TMPFILE
    rm -rf $TMPDIR
    ROOT_URL=$REPOS_URL
}
