#! /bin/sh

# This should be executed in a clean working copy of the test repo.

set -e
set -x

BASE="$(dirname "$(cd $(dirname "$0") && pwd)")"
TMP="$BASE/t/tmp"
GIT_IMERGE="$BASE/git-imerge"

cd "$TMP"

# Clean up detritus from possible previous runs of this test:
git checkout master
"$GIT_IMERGE" remove --name=c-d || true
for b in c-d-merge c-d-rebase c-d-rebase-with-history c-d-full
do
    git branch -D $b || true
done

git checkout c
"$GIT_IMERGE" init --first-parent --name=c-d d
"$GIT_IMERGE" list
"$GIT_IMERGE" diagram --commits --frontier --html=imerge0.html
"$GIT_IMERGE" autofill || true
"$GIT_IMERGE" diagram --commits --frontier --html=imerge1.html
"$GIT_IMERGE" continue
echo 'cd version' >conflict.txt
git add conflict.txt
"$GIT_IMERGE" continue --no-edit
"$GIT_IMERGE" diagram --commits --frontier --html=imerge2.html
GIT_EDITOR=cat "$GIT_IMERGE" simplify --goal=merge --branch=c-d-merge
"$GIT_IMERGE" simplify --goal=rebase --branch=c-d-rebase
"$GIT_IMERGE" simplify --goal=rebase-with-history --branch=c-d-rebase-with-history
"$GIT_IMERGE" remove

git checkout c
"$GIT_IMERGE" start --goal=full --first-parent --name=c-d d || true
"$GIT_IMERGE" diagram --commits --frontier --html=imerge3.html
echo 'cd version' >conflict.txt
git add conflict.txt
GIT_EDITOR=cat git commit
"$GIT_IMERGE" continue
"$GIT_IMERGE" diagram --commits --frontier --html=imerge4.html
"$GIT_IMERGE" finish --branch=c-d-full

