diff --git a/git-hooks/README.md b/git-hooks/README.md new file mode 100644 index 0000000..70e744b --- /dev/null +++ b/git-hooks/README.md @@ -0,0 +1,11 @@ + + +# Git Hooks + +This directory contains hooks which git will execute at various times. To +install the hooks, run `./install-hooks.sh`. diff --git a/git-hooks/install-hooks.sh b/git-hooks/install-hooks.sh new file mode 100755 index 0000000..8b18f09 --- /dev/null +++ b/git-hooks/install-hooks.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Copyright 2018 the authors. See the 'Copyright and license' section of the +# README.md file at the top-level directory of this repository. +# +# Licensed under the Apache License, Version 2.0 (the LICENSE-APACHE file) or +# the MIT license (the LICENSE-MIT file) at your option. This file may not be +# copied, modified, or distributed except according to those terms. + +# source: http://stackoverflow.com/a/957978/836390 +ROOT=$(git rev-parse --show-toplevel) || exit 1 + +if [ "$ROOT" == "" ]; then + echo "`git rev-parse --show-toplevel` returned empty root path" >&2 + exit 1 +fi + +cd $ROOT/.git/hooks || exit 1 + +ln -s ../../git-hooks/pre-commit.sh pre-commit || exit 1 diff --git a/git-hooks/pre-commit.sh b/git-hooks/pre-commit.sh new file mode 100755 index 0000000..575dd4c --- /dev/null +++ b/git-hooks/pre-commit.sh @@ -0,0 +1,31 @@ +#!/bin/bash + +# Copyright 2018 the authors. See the 'Copyright and license' section of the +# README.md file at the top-level directory of this repository. +# +# Licensed under the Apache License, Version 2.0 (the LICENSE-APACHE file) or +# the MIT license (the LICENSE-MIT file) at your option. This file may not be +# copied, modified, or distributed except according to those terms. + +echo "Executing pre-commit hooks..." + +# source: http://stackoverflow.com/a/957978/836390 +ROOT="$(git rev-parse --show-toplevel)" || exit 1 + +if [ "$ROOT" == "" ]; then + echo "`git rev-parse --show-toplevel` returned empty root path" >&2 + exit 1 +fi + +cd "$ROOT" + +function die { + if [ $# -eq 1 ]; then + rm "$1" + fi + echo "commit aborted" >&1 + exit 1 +} + +echo " Running ./test-scripts/check-copyright-comments.sh..." +./test-scripts/check-copyright-comments.sh