forked from osmocom/wireshark
![João Valverde](/assets/img/avatar_default.png)
Not all shells support uname -o. Change-Id: Ia6f46f3580f6d7b421da672418dcbee38ad9e60b Reviewed-on: https://code.wireshark.org/review/14143 Reviewed-by: João Valverde <j@v6e.pt>
102 lines
2.8 KiB
Bash
Executable file
102 lines
2.8 KiB
Bash
Executable file
#!/bin/sh
|
|
# Copyright 2013, Alexis La Goutte (See AUTHORS file)
|
|
#
|
|
# For git user: copy tools/pre-commit to .git/hooks/ folder and make it
|
|
# executable. To bypass it for a single commit, use the --no-verify argument.
|
|
#
|
|
# Alternatively, invoke it directly with the commit ID. Example for checking the
|
|
# last commit:
|
|
#
|
|
# tools/pre-commit HEAD~
|
|
#
|
|
# Relative paths are also supported. For instance, if you are in epan/, then you
|
|
# could invoke `../tools/pre-commit HEAD` to check for changes to staged files.
|
|
#
|
|
# From
|
|
# http://mark-story.com/posts/view/using-git-commit-hooks-to-prevent-stupid-mistakes
|
|
#
|
|
|
|
# If the commit identifier is not given, use HEAD instead.
|
|
COMMIT_ID="${1:-HEAD}"
|
|
|
|
UNAME=`uname -a`
|
|
|
|
case "$UNAME" in
|
|
*\ Msys)
|
|
pyvar="pythonw.exe"
|
|
;;
|
|
*)
|
|
pyvar="python"
|
|
;;
|
|
esac
|
|
|
|
PYBIN=${WS_GITHOOK_PYTHON:-$pyvar}
|
|
|
|
# Path to hook script in the .git directory
|
|
hook_script=${GIT_DIR:-.git}/hooks/pre-commit
|
|
|
|
# Always start in the root directory of the source tree, this allows for
|
|
# invocations via relative paths (such as ../tools/pre-commit):
|
|
cd "$(git rev-parse --show-toplevel)"
|
|
|
|
# Check for newer (actually, different) versions of the pre-commit script
|
|
# (but only if invoked as hook, i.e. the commit ID is not given as argument).
|
|
if [ -z "$1" ] && ! cmp -s "$hook_script" tools/pre-commit; then
|
|
echo "Pre-commit hook script is outdated, please update!"
|
|
fi
|
|
|
|
exit_status=0
|
|
|
|
COMMIT_FILES=`git diff-index --cached --name-status ${COMMIT_ID} | grep -v "^D" | cut -f2 | grep "\.[ch]$"`
|
|
|
|
# Path to filter script in the tools directory
|
|
filter_script=${PWD}/tools/pre-commit-ignore.py
|
|
filter_conf=${PWD}/tools/pre-commit-ignore.conf
|
|
|
|
if [ ! -e "$filter_script" ]; then
|
|
echo "File '$filter_script' does not exist. Aborting."
|
|
exit 1
|
|
fi
|
|
|
|
CHECK_FILES=`echo "$COMMIT_FILES" | "$PYBIN" "$filter_script" "$filter_conf"`
|
|
if [ $? -ne 0 ]; then
|
|
exit 1
|
|
fi
|
|
|
|
# On windows python will output \r\n line endings - we don't want that
|
|
CHECK_FILES=`echo "$CHECK_FILES" | sed 's/\r//g'`
|
|
|
|
for FILE in $CHECK_FILES; do
|
|
|
|
#Check if checkhf is good
|
|
./tools/checkhf.pl $FILE || exit_status=1
|
|
|
|
#Check if checkAPIs is good
|
|
./tools/checkAPIs.pl -p $FILE || exit_status=1
|
|
|
|
#Check if fix-encoding-args is good
|
|
./tools/fix-encoding-args.pl $FILE || exit_status=1
|
|
|
|
#Check if checkfiltername is good
|
|
./tools/checkfiltername.pl $FILE || exit_status=1
|
|
|
|
done
|
|
|
|
# If there are whitespace errors, print the offending file names and fail. (from git pre-commit.sample)
|
|
git diff-index --check --cached ${COMMIT_ID} || exit_status=1
|
|
|
|
exit $exit_status
|
|
|
|
#
|
|
# Editor modelines
|
|
#
|
|
# Local Variables:
|
|
# c-basic-offset: 4
|
|
# tab-width: 8
|
|
# indent-tabs-mode: nil
|
|
# End:
|
|
#
|
|
# ex: set shiftwidth=4 tabstop=8 expandtab:
|
|
# :indentSize=4:tabSize=8:noTabs=true:
|
|
#
|