#!/bin/sh

set -eu

# This script install user-side git commit hooks. You are supposed to run it
# only once for each repo (and very infrequently afterwards, once each time
# the git hooks change).

if test -d .git; then
  TOPDIR=.
else
  TOPDIR=..
fi

GITDIR=${TOPDIR}/.git

if test ! -d ${GITDIR}; then
   echo "ERROR: Could not find ${GITDIR} in ${TOPDIR}"
   exit 1
fi

echo "Installing hooks in ${GITDIR}/hooks"
mkdir -p ${GITDIR}/hooks
cp ${TOPDIR}/utils/git-hooks/prepare-commit-msg ${GITDIR}/hooks
chmod u+x ${GITDIR}/hooks/prepare-commit-msg
