|
| 1 | +#!/bin/sh |
| 2 | +# |
| 3 | +# hooks/precommit hook script of https-everywhere. |
| 4 | +# |
| 5 | +# Copyright (C) 2013, Jonathan Davies <jpdavs@gmail.com> |
| 6 | +# |
| 7 | +# This program is free software: you can redistribute it and/or modify |
| 8 | +# it under the terms of the GNU General Public License as published by |
| 9 | +# the Free Software Foundation, either version 3 of the License, or |
| 10 | +# (at your option) any later version. |
| 11 | +# |
| 12 | +# This program is distributed in the hope that it will be useful, |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +# GNU General Public License for more details. |
| 16 | +# |
| 17 | +# You should have received a copy of the GNU General Public License |
| 18 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | +# |
| 20 | + |
| 21 | +# Stash changes unrelated to the commit in Git. |
| 22 | +echo "$(date -R): Stashing unrelated changes in Git..." |
| 23 | +git stash -q --keep-index |
| 24 | + |
| 25 | +# On exit, revert the stash done above. |
| 26 | +trap 'echo "$(date -R): Reverting Git stash..."; git stash pop -q' EXIT |
| 27 | + |
| 28 | +RULESET_PATTERN="src/chrome/content/rules/" |
| 29 | +CHANGED_RULESETS="$(git diff --cached --name-only | grep $RULESET_PATTERN)" |
| 30 | + |
| 31 | +if [ "$CHANGED_RULESETS" ]; then |
| 32 | + # Only run tests if our rulesets have been changed. |
| 33 | + echo "$(date -R): Running ruleset validation tests on changed rulesets:" |
| 34 | + |
| 35 | + for FILE in $CHANGED_RULESETS; do |
| 36 | + if [ ! -f $FILE ]; then |
| 37 | + # File may have been removed from Git. |
| 38 | + echo "$(date -R): Skipped validation of $FILE - not found." |
| 39 | + continue |
| 40 | + fi |
| 41 | + |
| 42 | + # Errors will go to stderr. |
| 43 | + ./utils/trivial-validate.py $FILE > /dev/null |
| 44 | + RESULT=$? |
| 45 | + |
| 46 | + if [ $RESULT -eq 1 ]; then |
| 47 | + echo "$(date -R): Failure encountered during ruleset validation." |
| 48 | + exit $RESULT |
| 49 | + fi |
| 50 | + done |
| 51 | + |
| 52 | + echo "$(date -R): Ruleset validation successful." |
| 53 | +else |
| 54 | + echo "$(date -R): Skipped ruleset validation tests, no changes in" \ |
| 55 | + "$RULESET_PATTERN." |
| 56 | +fi |
| 57 | + |
| 58 | +exit 0 |
0 commit comments