-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-hooks-pre-commit
More file actions
executable file
·41 lines (36 loc) · 1019 Bytes
/
git-hooks-pre-commit
File metadata and controls
executable file
·41 lines (36 loc) · 1019 Bytes
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
#!/bin/sh
# Copied mostly from .git/hooks/pre-commit.sample
# Should be placed in .git/hooks/pre-commit inside project dir
if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
error_msg() {
RED=$(tput setaf 1)
RESET=$(tput sgr0)
warning=$1
files=$2
echo "${RED}WARNING! Aborting commit."
echo "If everything is good to commit, force commit with 'git commit -n'"
echo
echo "${warning}${RESET}"
echo "${files}"
}
# Redirect output to stderr.
exec 1>&2
files=$(git diff-index --cached $against -S'XXX' --name-only --)
if [ "${files}" ]
then
error_msg "There are warning comments ('XXX') in following files:" "${files}"
exit 1
fi
# If there are whitespace errors, print the offending file names and fail.
files=$(git diff-index --cached $against --check --)
if [ "${files}" ]
then
error_msg "There are whitespace warnings in the following files:" "${files}"
exit 1
fi