-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgit-pre-commit
executable file
·79 lines (64 loc) · 2.48 KB
/
git-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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
# Git pre-commit hook that runs multiple hooks specified in $HOOKS.
# Make sure this script is executable. Bypass hooks with git commit --no-verify.
# This file is part of a set of unofficial pre-commit hooks available
# at github.
# Link: https://github.com/githubbrowser/Pre-commit-hooks
# Contact: David Martin, [email protected]
###########################################################
# SETTINGS:
# pre-commit hooks to be executed. They should be in the same .git/hooks/ folder
# as this script. Hooks should return 0 if successful and nonzero to cancel the
# commit. They are executed in the order in which they are listed.
#HOOKS="pre-commit-default pre-commit-compile pre-commit-uncrustify"
HOOKS="git-pre-commit-nodebug"
###########################################################
# There should be no need to change anything below this line.
function canonicalize_filename () {
local target_file=$1
local physical_directory=""
local result=""
# Need to restore the working directory after work.
pushd `pwd` > /dev/null
cd "$(dirname "$target_file")"
target_file=`basename $target_file`
# Iterate down a (possible) chain of symlinks
while [ -L "$target_file" ]
do
target_file=$(readlink "$target_file")
cd "$(dirname "$target_file")"
target_file=$(basename "$target_file")
done
# Compute the canonicalized name by finding the physical path
# for the directory we're in and appending the target file.
physical_directory=`pwd -P`
result="$physical_directory"/"$target_file"
# restore the working directory after work.
popd > /dev/null
echo "$result"
}
# exit on error
set -e
# Absolute path to this script, e.g. /home/user/bin/foo.sh
SCRIPT="$(canonicalize_filename "$0")"
# Absolute path this script is in, thus /home/user/bin
SCRIPTPATH="$(dirname "$SCRIPT")"
echo "HOOKS: $HOOKS"
for hook in $HOOKS
do
echo "Running hook: $hook"
# run hook if it exists
# if it returns with nonzero exit with 1 and thus abort the commit
if [ -f "$SCRIPTPATH/$hook" ]; then
"$SCRIPTPATH/$hook"
if [ $? != 0 ]; then
exit 1
fi
else
echo "Error: file $hook not found."
echo "Aborting commit. Make sure the hook is in $SCRIPTPATH and executable."
echo "You can disable it by removing it from the list in $SCRIPT."
echo "You can skip all pre-commit hooks with --no-verify (not recommended)."
exit 1
fi
done