-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpre-commit
executable file
·55 lines (45 loc) · 1.48 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
48
49
50
51
52
53
54
55
#!/usr/bin/php
<?php
$output = array();
$return = 0;
exec('git rev-parse --verify HEAD 2> /dev/null', $output, $return);
$against = $return == 0 ? 'HEAD' : '4b825dc642cb6eb9a060e54bf8d69288fbee4904';
//exec('rm -r build/');
//exec('mkdir -p build/logs');
//exec('phpcpd --log-pmd build/logs/pmd-cpd.xml src/');
//exec('phpcs --report=checkstyle --report-file=build/logs/checkstyle.xml --standard=phpcs.xml --ignore=tests/ src/');
//exec('phpmd src/ xml phpmd.xml --reportfile build/logs/pmd.xml');
//exec('phpcb --log build/logs --source src/ --output build/code-browser');
exec("git diff-index --cached --name-only {$against}", $output);
$filename_pattern = '/\.php$/';
$exit_status = 0;
foreach ($output as $file) {
if (!preg_match($filename_pattern, $file)) {
// don't check files that aren't PHP
continue;
}
$lint_output = array();
exec("php -l " . escapeshellarg($file), $lint_output, $return);
if ($return == 0) {
continue;
}
echo implode("\n", $lint_output), "\n";
$exit_status = 1;
}
if ($exit_status === 1) {
exit($exit_status);
}
foreach ($output as $file) {
if (!preg_match($filename_pattern, $file)) {
// don't check files that aren't PHP
continue;
}
$phpcs_output = array();
exec("phpcs --standard=phpcs.xml -n " . escapeshellarg($file), $phpcs_output, $return);
if ($return == 0) {
continue;
}
echo implode("\n", $phpcs_output) . "\n";
$exit_status = 1;
}
exit($exit_status);