Source

hg-compass / tests / test-compass

#!/bin/sh

# -----------------------------------------------------------------------------
# init
# -----------------------------------------------------------------------------

[ -n "$HGRCPATH" ] && cat >> $HGRCPATH <<EOF
[extensions]
hgext.compass=
EOF

export COLUMNS=80

HGDO="hg -q"
HGCI="$HGDO ci -d 1980-1-1 -u test"

rm -rf testrepo
mkdir testrepo
cd testrepo
$HGDO init
cat >> .hg/hgrc << EOF
[bookmarks]
track.current = False
EOF

# -----------------------------------------------------------------------------
# helper functions to setup the test repo
# -----------------------------------------------------------------------------

edit() {
	echo "edit $1"
	echo "edit" >> $1
}

edit_commit() {
	edit  $1
	$HGCI -Am "Edit $1 in `hg branch` ($2)"
}

branch_commit() {
	echo "branching $1"
	OLD=`hg branch`
	$HGDO branch $1
	$HGCI -m "Branch from $OLD to $1"
}

close_branch() {
	BRANCH=`hg branch`
	echo "closing branch $BRANCH"
	$HGCI --close-branch -m "Closing branch $BRANCH"
}

merge_commit() {
	echo "merging $1"
	$HGDO merge $1
	hg_compass
	$HGCI -m "Merge in revision $1"
}

update() {
	echo "update to $1"
	$HGDO up -C -r $1
}

hg_compass() {
    hg compass $1 | sed -r "s/\[[_a-zA-Z0-9 ]+\]/[age]/" # fix age
}

# -----------------------------------------------------------------------------
# first test in virgin repository
# -----------------------------------------------------------------------------

hg_compass

# -----------------------------------------------------------------------------
# make history
# -----------------------------------------------------------------------------

edit_commit f.df "proceed default branch"

branch_commit dev-1.0

edit_commit f.dev-1.0 "proceed dev-1.0"

edit_commit f.dev-1.0 "proceed dev-1.0"

branch_commit dev-1.1 # branch dev-1.0 -> dev-1.1

SPLIT=`hg id -n`

edit_commit f.dev-1.1

update $SPLIT

$HGDO bookmark feature-1.1a

edit_commit f.dev-1.1 "add 2nd head to dev-1.1"

update $SPLIT

edit_commit f.dev-1.1 "add 3rd head to dev-1.1"

update dev-1.0

edit_commit f.dev-1.0 "proceed dev-1.0"

SPLIT=`hg id -n`

edit_commit f.dev-1.0 "proceed dev-1.0"

update $SPLIT

edit_commit f.dev-1.0  "add 2nd head to dev-1.0"

update $SPLIT

edit_commit f.dev-1.0  "add 3rd head to dev-1.0"

merge_commit dev-1.1 # merge 3rd head of dev-1.1 into 3rd head of dev-1.0

edit_commit f.dev-1.0 "proceed merged head"

update $SPLIT

branch_commit dev-2.0 # branch dev-1.0 -> dev-2.0

edit_commit f.dev-2.0 "proceed 1st head of dev-2.0"

close_branch

edit_commit f.dev-2.0 "reopen closed branch dev-2.0"

update $SPLIT

branch_commit dev-1.2 # branch dev-1.0 -> dev-1.2

edit_commit f.dev-1.2 "proceed 1st head of dev-1.2"

close_branch

update $SPLIT

branch_commit feature-foo # branch dev-1.0 -> feature-foo

edit_commit f.feature-foo "proceed 1st head of feature-foo"

close_branch

update dev-1.0

merge_commit feature-foo # merge feature-foo into dev-1.0

# -----------------------------------------------------------------------------
# test compass output
# -----------------------------------------------------------------------------

TIP_REV=`hg tip --template={rev}`

for rev in `seq 0 $TIP_REV` ; do
	echo "-- Updating to $rev"
	$HGDO up -C $rev
	echo "-- hg compass"
	hg_compass
	echo "-- hg compass -v"
	hg_compass -v
	echo "-- hg compass -i"
	hg_compass -i
	echo "-- hg compass -b"
	hg_compass -b
	echo "-- hg compass -c"
	hg_compass -c
	echo "-- hg compass -ibc"
	hg_compass -ibc
done

## check bookmarks track.current option ##

cat >> .hg/hgrc << EOF
[bookmarks]
track.current = True
EOF

$HGDO up -C 7
hg_compass
$HGDO up -C 6
hg_compass
$HGDO up -C feature-1.1a
hg_compass

# -----------------------------------------------------------------------------
# test help output
# -----------------------------------------------------------------------------

echo "-- hg help compass"
hg help compass