Commit 1bf19fe7 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

git-hooks init command implemented with single hook

Just the update hook at the moment as could not remember all the hooks
that exist.
parent 9ce47045
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ source $LIBDIR/arg_parse_functions
BIN=`basename "$0"`
GIT="git ${GIT_DIR+--git-dir "${GIT_DIR}"}"
GIT_DIR="${GIT_DIR:-`git rev-parse --git-dir`}"
HOOKS="update"

usage ()
{
@@ -55,9 +56,29 @@ full_usage ()
cmd_init ()
{
	summary="set up git-hook directories in a repository"
	local force
	local force skip
	add_arg FLAG -f force
	add_arg FLAG -s skip
	parse_args "$@"

	cd "$GIT_DIR"/hooks
	for hook in $HOOKS; do
		if ! mkdir $hook.d 2>/dev/null; then
			if [ x$force == xyes ]; then
				mv $hook.d $hook.d.old
				mv $hook $hook.old
				chmod -x $hook.old
				mkdir $hook.d
			elif [ x$skip == xyes ]; then
				continue
			else
				die "$hook.d already exists"
			fi
		fi
		[ -e $hook ] && mv $hook $hook.d/org_$hook
		[ -e $hook.sample ] && mv $hook.sample $hook.d/
		ln -s "$LIBDIR"/run-hooks $hook
	done
}

cmd_add ()