-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathpre-commit
executable file
·49 lines (42 loc) · 1.74 KB
/
pre-commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
#
# This file is part of postpic.
#
# postpic is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# postpic is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with postpic. If not, see <http://www.gnu.org/licenses/>.
#
# Copyright Stephan Kuschel, 2014-2015
# This script is a wrapper around the run-tests.py script.
# It is highly recommended to link it as the git pre-commit hook via:
# ln -s ../../pre-commit .git/hooks/pre-commit
# The difference to the run-tests.py script is that this script stashes
# unstaged changes before testing (see below). Thus only the changeset to be
# commited will be tested. No worries, "git commit -a" will still work ;)
# Stash unstaged changes if and only if(!) necessary (=possible):
# if you dont check that you might uninentionally apply an older stash,
# because this if statement just makes sure, that there are changed to
# be stashed on executing "git staph -q --keep-index". Otherwise it coud
# happen, that git stash is executed, but no stash is created, because
# there were no changes, that could be stashed.
if git diff-index --quiet HEAD --; then
#echo "pre-commit hook without stashing"
./run-tests.py
exitcode=$?
else
#echo "pre-commit hook with stashing"
git stash -q --keep-index
./run-tests.py
exitcode=$?
git stash pop -q
fi
exit $exitcode