Commit 924e292a authored by Dom Sekotill's avatar Dom Sekotill
Browse files

'git-hooks add' supports scripts from $pkgdatadir/$hook/

Scripts can now be added from the pre-made hooks directories in the
package data directory.
parent 1b7e4d9b
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -22,7 +22,10 @@ SUBDIRS = hook-scripts


.bindir/git-hooks: git-hooks | .bindir
	sed 's|LIBDIR=.*|LIBDIR=$(pkgdatadir)|' $< > $@
	sed \
		-e 's|LIBDIR=.*|LIBDIR="$(pkgdatadir)"|' \
		-e 's|HOOKDIR=.*|HOOKDIR="$(pkgdatadir)"|' \
		$< > $@

.bindir:
	$(mkdir_p) .bindir
+12 −3
Original line number Diff line number Diff line
@@ -19,8 +19,10 @@

set -e

# LIBDIR is populated by the install script
# LIBDIR & HOOKDIR are populated by the install script
LIBDIR=`readlink -f $(dirname $0)`
HOOKDIR="$LIBDIR/hook-scripts"

source $LIBDIR/string_functions
source $LIBDIR/arg_parse_functions

@@ -114,12 +116,19 @@ cmd_add ()
	_basic_check "$@"
	_change_check "$@"

	[ -e "$script" ] || die "unknown script '$script'"
	[ -e "$GIT_DIR"/hooks/$hook.d/"`basename "$script"`" ] && \
		die "the script '`basename "$script"`' (or one with the same name) \
		     already exists in the '$hook' hook directory"

	if [ -e "$script" ]; then
		echo "copying $script"
		cp "$script" "$GIT_DIR"/hooks/$hook.d
	elif [ -e "$HOOKDIR/$hook/$script" ]; then
		echo "linking $script from $HOOKDIR/$hook"
		ln -s "$HOOKDIR/$hook/$script" "$GIT_DIR"/hooks/$hook.d
	else
		die "unknown script '$script'"
	fi
}

cmd_remove ()