2
#==========================================================================
4
# Copyright Insight Software Consortium
6
# Licensed under the Apache License, Version 2.0 (the "License");
7
# you may not use this file except in compliance with the License.
8
# You may obtain a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0.txt
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS,
14
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
# See the License for the specific language governing permissions and
16
# limitations under the License.
18
#==========================================================================*/
21
egrep "$@" >/dev/null 2>/dev/null
25
echo 'pre-commit hook failure' 1>&2
26
echo '-----------------------' 1>&2
32
#-----------------------------------------------------------------------------
34
# Check that developmer setup is up-to-date.
35
lastSetupForDevelopment=$(git config --get hooks.SetupForDevelopment || echo 0)
36
eval $(grep '^SetupForDevelopment_VERSION=' "${BASH_SOURCE%/*}/../SetupForDevelopment.sh")
37
test -n "$SetupForDevelopment_VERSION" || SetupForDevelopment_VERSION=0
38
if test $lastSetupForDevelopment -lt $SetupForDevelopment_VERSION; then
39
die 'Developer setup in this work tree is out of date. Please re-run
41
Utilities/SetupForDevelopment.sh
45
#-----------------------------------------------------------------------------
46
# Check files added by commit
48
added=$(git diff-index --diff-filter=A --cached HEAD --)
49
added_normal=$(echo "$added" | grep -v '^:...... 160000')
50
added_module=$(echo "$added" | grep '^:...... 160000')
52
# Do not allow adding of files with .txx extension.
53
added_txx=$(echo "$added_normal" | grep '\.txx$')
55
test -n "$added_txx" &&
56
echo "Files with the .txx extension are deprecated -- please use .hxx instead:" &&
57
echo "$added_txx" | awk '{printf(" %s\n",$6)}'
59
test -z "$bad" || die "$bad"
61
# Do not allow addition of submodules.
63
test -n "$added_module" &&
64
echo "Submodules may not be added to SimpleITK at this time:" &&
65
echo "$added_module" | awk '{printf(" %s\n",$6)}'
67
test -z "$bad" || die "$bad"
69
#-----------------------------------------------------------------------------
71
. "${BASH_SOURCE%/*}/pre-commit-style.bash"
75
changes=$(git diff-files -- "$1") &&
76
if test -n "$changes"; then
77
die "Cannot validate '$1' with work tree changes."
79
out=$($python_exe -c "import sys, json; json.load( open( sys.argv[1], 'r' ) )" "$1" 2>&1) || die "JSON Validation error with \"$file\".
83
json_files=$(git diff-index --cached HEAD --diff-filter=AM ) &&
84
if test -n "$json_files"; then
85
validate=$(git config --get --bool hooks.ValidateJSON || echo true) &&
86
if test "$validate" = "true"; then
87
python_exe=$(git config hooks.python || type -p python) &&
88
if test -z "$python_exe"; then
89
die 'Cannont validate SimpleITK JSON files with out Python.
90
Configure the Python location with:
92
git config hooks.python "/path/to/python"
94
It is NOT recommended to disable this check with:
96
git config hooks.validatejson false
100
while read src_mode dst_mode src_obj dst_obj status file; do
101
if echo "$file" | egrep-q '\.json$'; then
102
echo "validating $file"
103
validate_json "$file"