diff options
author | João Valverde <joao.valverde@tecnico.ulisboa.pt> | 2016-01-09 15:04:54 +0000 |
---|---|---|
committer | Alexis La Goutte <alexis.lagoutte@gmail.com> | 2016-01-28 10:38:29 +0000 |
commit | 0a931aa383526a3481ad6a44545f7b9f723032b6 (patch) | |
tree | 59c55a7a6b80848c9dadc482278870a283918e26 /tools/pre-commit | |
parent | 936e4e01231a5df9dead93ac40bb2b4f923c2754 (diff) |
Add fnmatch support to git pre-commit hook
Allows for wildcard pathname matching in ignore list.
Change-Id: I52e47c72c69e16ff9aefadfde22d1bd682df9654
Reviewed-on: https://code.wireshark.org/review/13166
Petri-Dish: João Valverde <j@v6e.pt>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Diffstat (limited to 'tools/pre-commit')
-rwxr-xr-x | tools/pre-commit | 36 |
1 files changed, 11 insertions, 25 deletions
diff --git a/tools/pre-commit b/tools/pre-commit index bfc8aedeaa..796eb5e4ee 100755 --- a/tools/pre-commit +++ b/tools/pre-commit @@ -16,20 +16,19 @@ # http://mark-story.com/posts/view/using-git-commit-hooks-to-prevent-stupid-mistakes # -unset GREP_OPTIONS - # If the commit identifier is not given, use HEAD instead. COMMIT_ID="${1:-HEAD}" + # Path to hook script in the .git directory hook_script=${GIT_DIR:-.git}/hooks/pre-commit +# Path to check script in the tools directory +check_script=./tools/pre-commit-check.py + # 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)" -# Path to excluded files listing -excludes=./tools/pre-commit-checkignore.txt - # 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 @@ -38,26 +37,13 @@ fi exit_status=0 -for FILE in `git diff-index --cached --name-status ${COMMIT_ID} | grep -v "^D" | cut -f2 | grep "\.[ch]$" | grep -v "extcap/"` ; do - - #Skip if listed - if [ -e $excludes ] && grep -Fxq "$FILE" "$excludes"; then - continue - fi - - #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 [ -e "$check_script" ] +then + python "$check_script" ${COMMIT_ID} || exit_status=1 +else + echo "File '$check_script' not found. Aborting." + exit 1 +fi # 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 |