#!/bin/bash

#  Copyright © 2011-2013  B. Clausius <barcc@gmx.de>
#
#  This program 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.
#
#  This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.

set -ex
function err() { echo; echo "Fehler"; }
trap err ERR

function rmmkcd() {
    [ -d "$1" ] && rm -r "$1"
    mkdir -p "$1"
    cd "$1"
}
function mkfile() {
    test ! -e "$1"
    echo "$1" >"$1"
}

[ "$(dirname "$(readlink -e "$0")")" = "$PWD" ] || { echo 'wrong directory'; exit 1; }
rmmkcd data
bzr init-repo .

# create branch with one commit to test filelist view
(
    rmmkcd filelist_repo/test_branch

    bzr init
    bzr reconfigure --standalone

    mkfile file_unversioned
    mkfile file_removed
    mkfile file_orig
    mkfile file_kind_changed
    mkdir dir_kind_changed
    mkfile file_modified
    mkfile file_unchanged
    mkfile file_ignored
    bzr ignore file_ignored
    mkfile file_ignored.pyc
    bzr add
    bzr commit -m 'test_branch revision 1'

    mkfile file_added
    bzr add file_added
    bzr rm --keep file_unversioned
    bzr rm file_removed
    bzr mv file_orig file_renamed
    rm file_kind_changed
    mkdir file_kind_changed
    rmdir dir_kind_changed
    mkfile dir_kind_changed
    echo 'line added' >>file_modified
    mkfile file_unknown
)

# create repository and files in a directory to test init branch
(
    rmmkcd new_repo
    #bzr init-repo .
    rmmkcd new_branch
    mkfile file_one
    mkfile file_two
    mkfile file_three
)

# create branches to test pending merge
(
    rmmkcd pending_repo/merge_target
    bzr init
    for n in eins zwei drei vier fünf; do
        mkfile $n
        bzr add
        bzr commit -m $n
    done
    cd ..
    bzr branch merge_target merge_source
    cd merge_source
    for n in sechs sieben acht neun zehn; do
        mkfile $n
        bzr add
        bzr commit -m $n
    done
    cd ../merge_target
    bzr merge ../merge_source
)

