Created
August 10, 2011 19:32
-
-
Save voxpelli/1137906 to your computer and use it in GitHub Desktop.
PHPMD Git pre-commit hook with parallell checks thanks to Node.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env node | |
var child_process = require('child_process'), | |
spawn = child_process.spawn, | |
exec = child_process.exec, | |
quitOnError = null, rules; | |
function checkFiles() { | |
if (quitOnError === null || !rules) { | |
return; | |
} | |
var gitPhpmd = spawn('git', ['phpmd', rules]) | |
gitPhpmd.stdout.on('data', function (data) { | |
process.stdout.write(data); | |
}); | |
gitPhpmd.on('exit', function (code) { | |
if (quitOnError) { | |
setTimeout(function () { | |
process.exit(code); | |
}, 10); | |
} | |
}); | |
} | |
exec('git config hooks.phpmdstoponerror', function (error, stdout) { | |
if (error === null) { | |
quitOnError = (stdout.trim() != '0'); | |
checkFiles(); | |
} | |
else { | |
quitOnError = false; | |
} | |
}); | |
exec('git config hooks.phpmd', function (error, stdout) { | |
if (error === null) { | |
rules = stdout.trim(); | |
checkFiles(); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Uses multiphpmd from https://github.com/voxpelli/node-multiphpmd | |
git diff --name-only --staged | multiphpmd $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment