Skip to content

Commit

Permalink
git-hooks: Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
joshlf committed Feb 28, 2018
1 parent dfb59d6 commit 6f85313
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
11 changes: 11 additions & 0 deletions git-hooks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- 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. -->

# Git Hooks

This directory contains hooks which git will execute at various times. To
install the hooks, run `./install-hooks.sh`.
20 changes: 20 additions & 0 deletions git-hooks/install-hooks.sh
Original file line number Diff line number Diff line change
@@ -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
31 changes: 31 additions & 0 deletions git-hooks/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6f85313

Please sign in to comment.