diff --git a/PreCommitManager.class.php b/PreCommitManager.class.php index 98b6477..9b4deeb 100644 --- a/PreCommitManager.class.php +++ b/PreCommitManager.class.php @@ -91,7 +91,7 @@ public function processChecks(){ try { require_once $this->getCheckDirectory().DIRECTORY_SEPARATOR.$checkName.'Check.class.php'; $className = $checkName.'Check'; - $check = new $className($mess); + $check = new $className($mess, $this->repoName, $this->trxNum); $check->runCheck($fileChanges); if ($check->fail()){ $this->checksWithError[] = $check; diff --git a/checks/BasePreCommitCheck.class.php b/checks/BasePreCommitCheck.class.php index 3986260..55bfbeb 100644 --- a/checks/BasePreCommitCheck.class.php +++ b/checks/BasePreCommitCheck.class.php @@ -6,9 +6,13 @@ abstract class BasePreCommitCheck { protected $globalError = array(); protected $codeError = array(); protected $options = array(); + protected $repoName = null; + protected $trxNum = null; - public function __construct($svnComment=''){ + public function __construct($svnComment='', $repoName = null, $trxNum = null){ $this->svnComment = $svnComment; + $this->repoName = $repoName; + $this->trxNum = $trxNum; $this->parseOptions(); } diff --git a/checks/SyntaxCheck.class.php b/checks/SyntaxCheck.class.php new file mode 100644 index 0000000..e961851 --- /dev/null +++ b/checks/SyntaxCheck.class.php @@ -0,0 +1,55 @@ +hasOption('no-syntax') ){ + return; + } + + $this->hasPhpBinary(); + + if ($this->getExtension($filename) !== 'php') { + return; + } + + passthru('svnlook cat '.escapeshellarg($this->repoName).' '.escapeshellarg($filename).' -t '.escapeshellarg($this->trxNum).' | php -l', $return); + + if ($return !== 0) { + return 'Syntax error in '.$filename; + } + } + + + private function hasPhpBinary() + { + if (self::$has_php_binary === null) { + passthru('php --version', $return); + + if ($return !== 0) { + throw new Exception('Impossible to find PHP binary'); + } + + self::$has_php_binary = true; + } + } + + public function renderInstructions() + { + return "If you want to force commit with error syntax, add the parameter --no-syntax in your comment"; + } +} \ No newline at end of file diff --git a/pre-commit.tmpl b/pre-commit.tmpl index 33c59c7..0216af0 100644 --- a/pre-commit.tmpl +++ b/pre-commit.tmpl @@ -8,4 +8,4 @@ # * --exculde=XX:ZZZ To list the checks that must be ignore for that repo # -php /{PATH_TO_PHP_SVN_HOOKS_DIR}/svn_pre_commit_hook.php $1 $2 --include=EmptyComment:NoTabs \ No newline at end of file +php /home/svn/hooks/php-svn-hook/svn_pre_commit_hook.php $1 $2 --include=EmptyComment:Syntax