-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpre-commit
executable file
·48 lines (38 loc) · 1.28 KB
/
pre-commit
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
42
43
44
45
46
47
#!/usr/bin/perl -w
#
#
# To enable this hook, copy to "pre-commit" in the repo's git dir and make it executable.
#
# You will need to change $PARSER to the path that you've installed the Kynetx parser.
#
my $against;
if (`git rev-parse --verify HEAD`) {
$against="HEAD";
} else {
# Initial commit: diff against an empty tree object
$against="4b825dc642cb6eb9a060e54bf8d69288fbee4904";
}
my $PARSER="/Users/pjw/prog/kynetx/krl-parse/krl-parse.pl";
my $allownoparse=`git config hooks.allownoparse`;
#print $allownoparse;
my $parse_error = 0;
# Cross platform projects tend to avoid non-ascii filenames; prevent
# them from being added to the repository. We exploit the fact that the
# printable range starts at the space character and ends with tilde.
if (! defined $allownoparse || length($allownoparse) == 0) {
my $file_list = `git diff --name-only --diff-filter=ACM $against`;
my ($parse_result, $file);
foreach $f (split(/\n/, $file_list)) {
next unless $f =~ m/\.krl$/;
$file = $f;
$parse_result = `$PARSER -f $f`;
# print "$f: Parser says $parse_result";
unless ($parse_result =~ m/^OK/) {
$parse_error = 1;
last
}
}
if ($parse_error) {
die "Parse errors in $file: $parse_result\n\nYou can disable checking by setting the hook.allownoparse to true\n";
}
}