From ff13ad2d85d8ca3aaa5c871533c3447156961490 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Farkas=20Szil=C3=A1rd?= Date: Fri, 13 Nov 2015 18:35:10 +0100 Subject: [PATCH] Modify ccd_defs_check.py to work with the pre-commit hook, delete perl version Former-commit-id: c24f667900908830a9db038bd45bab83237306be --- ccd_defs_check.pl | 20 -------------------- ccd_defs_check.py | 5 +++++ hooks/pre-commit | 6 ++++-- 3 files changed, 9 insertions(+), 22 deletions(-) delete mode 100755 ccd_defs_check.pl diff --git a/ccd_defs_check.pl b/ccd_defs_check.pl deleted file mode 100755 index a4ab094c..00000000 --- a/ccd_defs_check.pl +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env perl - -use strict; - -use File::Basename qw( dirname ); -use File::Spec; -use JSON; - -my $dir = dirname($0); -my $ccd_defs = File::Spec->catfile($dir, 'ccd_defs.json'); - -open my $fh, $ccd_defs - or die "Unable to open $ccd_defs : $!"; -local $/; -my $json = <$fh>; # Slurp -close $fh; - -decode_json($json); -print "CCD_DEFS compiles OK\n"; -exit 0; diff --git a/ccd_defs_check.py b/ccd_defs_check.py index acb6f7eb..f0a37f8d 100755 --- a/ccd_defs_check.py +++ b/ccd_defs_check.py @@ -14,7 +14,12 @@ try: ccd_defs = get_ccd_widths() print "CCD_DEFS compiles OK" print "Definitions in file: {0}".format(len(ccd_defs)) + exit_code=0 except IOError as e: print "I/O error with CCD_DEFS file: {0}".format(e.strerror) + exit_code=255 except: print "Error with CCD_DEFS file: {0}".format(sys.exc_info()[1]) + exit_code=255 + +sys.exit(exit_code) diff --git a/hooks/pre-commit b/hooks/pre-commit index 71d12852..97ffde5c 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -11,12 +11,14 @@ exec 1>&2 echo "RUNNING PRE-COMMIT" +EXIT_CODE=0 # Get list of files about to be committed if git diff --cached --name-only --diff-filter=ACM | grep 'ccd_defs.json'; then echo "We changed ccd_defs.json" GIT_ROOT=$(git rev-parse --show-toplevel) - perl $GIT_ROOT/ccd_defs_check.pl + python $GIT_ROOT/ccd_defs_check.py + EXIT_CODE=$(echo $?) fi # non-zero exit fails the commit -exit 0 +exit $EXIT_CODE