12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- egrep_q() {
- egrep "$@" >/dev/null 2>/dev/null
- }
- die() {
- echo 1>&2 "$@" ; exit 1
- }
- cd "${BASH_SOURCE%/*}" &&
- if url=$(git config --get hooks.url); then
- # Fetch hooks from locally configured repository.
- branch=$(git config hooks.branch || echo hooks)
- elif git for-each-ref refs/remotes/origin/hooks 2>/dev/null |
- egrep_q 'refs/remotes/origin/hooks$'; then
- # Use hooks cloned from origin.
- url=.. && branch=remotes/origin/hooks
- elif url=$(git config -f config --get hooks.url); then
- # Fetch hooks from project-configured repository.
- branch=$(git config -f config hooks.branch || echo hooks)
- else
- die 'This project is not configured to install local hooks.'
- fi &&
- echo 'Setting up git hooks...' &&
- git_dir=$(git rev-parse --git-dir) &&
- mkdir -p "$git_dir/hooks" &&
- cd "$git_dir/hooks" &&
- if ! test -e .git; then
- git init -q || die 'Could not run git init for hooks.'
- fi &&
- git fetch -q "$url" "$branch" &&
- git reset -q --hard FETCH_HEAD || die 'Failed to install hooks'
|