#! /bin/sh
#
# .git/hooks/post-checkout
BRANCH=`git symbolic-ref HEAD 2> /dev/null | sed -e 's/^.*\///'`
GITPATH="`git rev-parse --git-dir 2>/dev/null`/.."
if [ "$BRANCH" == "" ]; then
echo "no branch name. do nothing"
exit 0
fi
if [ -f "$GITPATH/config/database.yml" ] && [ ! -L "$GITPATH/config/database.yml" ]; then
echo "database.yml exists and not a symlink. do nothing."
exit 0
fi
echo "look for $GITPATH/config/database.$BRANCH.yml"
if [ -f "$GITPATH/config/database.$BRANCH.yml" ]; then
echo "switch database configuration file to config/database.$BRANCH.yml"
rm -f "$GITPATH/config/database.yml";
ln -s "$GITPATH/config/database.$BRANCH.yml" \
"$GITPATH/config/database.yml"
fi