Skip to content
This repository was archived by the owner on Sep 27, 2019. It is now read-only.

Commit bd75a24

Browse files
committed
Restore git-hook commands
1 parent 38dbf46 commit bd75a24

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

script/git-hooks/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Git Hooks
2+
3+
This directory contains all Git hooks used in Peloton. Git hooks provide
4+
a mechanism to execute custom scripts when important events occur during
5+
your interaction with this Git repository. More details on Git hooks can
6+
be found [here](https://git-scm.com/book/gr/v2/Customizing-Git-Git-Hooks).
7+
8+
### Pre-commit
9+
10+
A pre-commit hook is fired on every commit into your local Git
11+
repository. Peloton's pre-commit hook collects all modified files
12+
(excluding deleted files) and runs them through our source code
13+
validator script in `script/validator/source_validator.py`. *Ideally*,
14+
we should also ensure every commit successfully compiles and, to a
15+
lesser extent, that the commit passes the tests, but this isn't
16+
reasonable for now.
17+
18+
**Installation:** Under the peloton root directory, run
19+
`ln -s ../../script/git-hooks/pre-commit .git/hooks/pre-commit` to
20+
install locally. The pre-commit file should already have executable
21+
permission, but check again to make sure.

script/git-hooks/pre-commit

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/sh
2+
# Source validation pre-commit hook
3+
#
4+
# This script collects all modified files and runs it through our source code
5+
# validation script. The validation script returns 0 on success and 1 on any
6+
# failure.
7+
#
8+
# To enable, symlink this file to '.git/hooks/pre-commit' like so:
9+
# ln -s ../../script/git-hooks/pre-commit .git/hooks/pre-commit
10+
11+
FORMATTER_COMMAND="./script/formatting/formatter.py"
12+
13+
FILES=$(git diff --name-only HEAD --cached --diff-filter=d | grep '\.\(cpp\|h\)$')
14+
if [ -n "$FILES" ]; then
15+
./script/validators/source_validator.py --files $FILES
16+
RESULT=$?
17+
if [ $RESULT -ne 0 ]; then
18+
echo "***************************************"
19+
echo "******* Peloton Pre-Commit Hook *******"
20+
echo "***************************************"
21+
echo "Use \"$FORMATTER_COMMAND -c -f\" to format all staged files."
22+
echo "Or use \"$FORMATTER_COMMAND --no-verify\" to temporarily bypass the pre-commit hook."
23+
echo
24+
echo "Be aware that changed files have to be staged again!"
25+
echo "***************************************"
26+
fi
27+
exit $RESULT
28+
fi
29+
30+
exit 0

0 commit comments

Comments
 (0)