-
Notifications
You must be signed in to change notification settings - Fork 26
/
pre-commit.sh
executable file
·45 lines (37 loc) · 995 Bytes
/
pre-commit.sh
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
#!/bin/sh
#
# pre-commit.sh
#
# Hook for git that must pass beofre commit is accepted.
# Save current config
echo "\n\nSaving current config\n\n"
cp config.status tmp.status
# Stash modified files, if any, that are not part of this commit, don't test
# them
STASHED=0
if ! git diff --quiet
then
STASHED=1
echo "\n\nStashing modified files not part of commit\n\n"
git stash -q --keep-index
fi
# Run the commit tests
echo "\n\nRunning commit tests...\n\n"
./commit-tests.sh
RESULT=$?
# Restore modified files not part of this commit
if test $STASHED -eq 1
then
echo "\n\nPopping stashed modified files not part of commit\n"
git stash pop -q
fi
# Restore current config
echo "\nRestoring current config\n"
mv tmp.status config.status
# Don't show output in case error from above
./config.status >/dev/null 2>&1
make clean >/dev/null 2>&1
make -j 8 >/dev/null 2>&1
[ $RESULT -ne 0 ] && echo "\nOops, your commit failed\n" && exit 1
echo "\nCommit tests passed!\n"
exit 0