#! /bin/sh

set -ex

BASE="$(dirname "$(cd $(dirname "$0") && pwd)")"
. "$BASE/t/test-lib.sh"

GIT_IMERGE="git-imerge"
TMP="$BASE/t/tmp/unconflicted"
DESCRIPTION="git-imerge test repository without conflicts"

# Set up a test repo with two branches, `a` and `b`, that don't
# conflict with each other:
init_test_repo "$TMP" "$DESCRIPTION"
cd "$TMP"

modify a.txt 0
modify b.txt 0
commit -m 'm⇒0'

git checkout -b a --
for i in $(seq 8)
do
    modify a.txt $i
    commit -m "a⇒$i"
done

git checkout -b b master --
for i in $(seq 5)
do
    modify b.txt $i
    commit -m "b⇒$i"
done

EXPECTED_TREE=e4a7b27799be355bbcbf8bfe9c29d74190082c42

git checkout a
"$GIT_IMERGE" start --first-parent --name=a-b --branch=a-b-merge b
"$GIT_IMERGE" list
"$GIT_IMERGE" diagram --commits --frontier --html=imerge3.html
GIT_EDITOR=cat "$GIT_IMERGE" simplify --goal=merge --branch=a-b-merge
check_tree a-b-merge $EXPECTED_TREE
"$GIT_IMERGE" simplify --goal=rebase --branch=a-b-rebase
check_tree a-b-rebase $EXPECTED_TREE
"$GIT_IMERGE" simplify --goal=rebase-with-history --branch=a-b-rebase-with-history
check_tree a-b-rebase-with-history $EXPECTED_TREE
"$GIT_IMERGE" simplify --goal=border --branch=a-b-border
check_tree a-b-border $EXPECTED_TREE
"$GIT_IMERGE" simplify --goal=border-with-history --branch=a-b-border-with-history
check_tree a-b-border-with-history $EXPECTED_TREE
"$GIT_IMERGE" simplify --goal=border-with-history2 --branch=a-b-border-with-history2
check_tree a-b-border-with-history2 $EXPECTED_TREE
"$GIT_IMERGE" remove

git checkout a
"$GIT_IMERGE" start --goal=full --name=a-b b
"$GIT_IMERGE" list
"$GIT_IMERGE" diagram --commits --frontier --html=imerge4.html
"$GIT_IMERGE" finish --branch=a-b-full
check_tree a-b-full $EXPECTED_TREE

