#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail


TESTDIR=/tmp/svntest
SVNREPODIR=$TESTDIR/svn
SVN_URI=file://$SVNREPODIR/test

cd $TESTDIR

rm -rf $SVNREPODIR test

svnadmin create $SVNREPODIR
svn mkdir --parents $SVN_URI/trunk $SVN_URI/branches $SVN_URI/tags -m 'Create branches.'

git svn clone -s $SVN_URI
cd test

# create and checkout a new branch v1.2
svn copy $SVN_URI/trunk $SVN_URI/branches/v1.2 -m 'Create branch v1.2.'
git svn fetch --all
git checkout origin/v1.2 -b v1.2

# add a new file to branch v1.2
echo -e 1\\n2\\n3 > test.txt
git add test.txt
git commit test.txt -m 'Add test.txt'
git svn dcommit --merge

# create and checkout a new branch v1.2_issue-1
svn copy $SVN_URI/branches/v1.2 $SVN_URI/branches/v1.2_issue-1 -m 'Create branch v1.2_issue-1'
git svn fetch --all
git checkout origin/v1.2_issue-1 -b v1.2_issue-1

# do work in branch v1.2_issue-1
echo -e 4\\n5 >> test.txt
git commit test.txt -m 'Extend test.txt'
git svn dcommit

# merge branch v1.2_issue-1 into v1.2
git checkout v1.2
git merge v1.2_issue-1

# error! the change is pushed to v1.2_issue-1 instead of v1.2
git svn dcommit
svn log $SVN_URI
