Tech Blog :: Alias to validate PHP and stage to Git in one step
Alias to validate PHP and stage to Git in one step
One of the biggest faux pas that can happen working with PHP apps like Drupal (or any interpreted language for that matter) is deploying invalid syntax that brings down a whole site. So I like to run my PHP files through the PHP validator before committing. I'm working with Git, so this alias (put in .bash_profile for example) validates PHP files and then stages them to Git for committing (or doesn't stage them if there are errors). I'm including the extensions .php, .module, .install, and .inc as PHP files (please let me know if I'm missing any common ones):
[Update 1/9/11: I replaced the original alias syntax with a new function syntax that works more reliably.]
function git-v-add { git st --short | while read FILE; do echo $FILE | awk '{ print $2 }' | grep -E "(\.module|\.php|\.install|\.inc)$" | xargs php -l || return 1; done && \ git add -A && git st }
Then just run git-v-add && git commit.
Google: TheBuckSt0p
Facebook: BenBuckman
LinkedIn
Github: newleafdigital
@thebuckst0p
Delicious: thebuckst0p
Drupal.org: thebuckst0p
This is awesome. I will definitely be adding to my workflow.
Post new comment
Don't bother putting in spam links. They'll be set to
rel=nofollowand will be removed and reported as spam shortly after submitting.