Last active
December 31, 2015 08:19
-
-
Save hroncok/7959382 to your computer and use it in GitHub Desktop.
Link the given pre-commit hook to current pwd git repository or to those in arguments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HOOK=/usr/lib/fedpkg-patch-check.py | |
function addhook { | |
hookdir="${1%%/}/.git/hooks" | |
test -d "$hookdir" || (echo "$hookdir doesn't exist or is not a directory" 1>&2 && return 1) | |
test -h "$hookdir/pre-commit" && echo "$hookdir/pre-commit is already a link, skipping" 1>&2 && return 1 | |
test -f "$hookdir/pre-commit" && echo "$hookdir/pre-commit is a file, you should call $HOOK manually from that file depending on what language is your hook written in" 1>&2 && return 1 | |
ln -s $HOOK "$hookdir/pre-commit" || (echo "Could not link the hook into $hookdir" 1>&2 && return 1) | |
chmod +x "$hookdir/pre-commit" | |
} | |
if [ $# -eq 0 ]; then | |
dir="`git rev-parse --show-toplevel`" || exit $? | |
addhook "$dir" | |
else | |
for i in "$@"; do | |
addhook "$i" | |
done | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment