#!/bin/sh

echo "[extensions]" >> $HGRCPATH
echo "graphlog=" >> $HGRCPATH
echo "rebase=" >> $HGRCPATH

addcommit () {
    echo $1 > $1
    hg add $1
    hg commit -d "${2} 0" -m $1
}

hg init a
cd a
addcommit "c1" 0
addcommit "c2" 1

addcommit "l1" 2

hg update -C 1
addcommit "r1" 3
addcommit "r2" 4
hg glog --template '{rev}:{desc}\n'

echo
echo '% Rebase with no arguments - single revision in source branch'
hg update -C 2
hg rebase 2>&1 | sed 's/\(saving bundle to \).*/\1/'
hg glog --template '{rev}:{desc}\n'

cd ..
rm -rf a
hg init a
cd a
addcommit "c1" 0
addcommit "c2" 1

addcommit "l1" 2
addcommit "l2" 3

hg update -C 1
addcommit "r1" 4
hg glog --template '{rev}:{desc}\n'

echo
echo '% Rebase with no arguments - single revision in target branch'
hg update -C 3
hg rebase 2>&1 | sed 's/\(saving bundle to \).*/\1/'
hg glog --template '{rev}:{desc}\n'
