本地Git添加Hook钩子,提交时自动对修改的PHP文件进行语法检测,如果失败则无法继续Commit
只是为了避免低级错误提交到仓库
1.在本地仓库中编辑.git/hooks/pre-commit
文件,没有则建立,内容如下
#!/bin/sh
changed_files=`git diff-index --cached --name-only HEAD --`
for f in $changed_files ;do
ext=${f##*.}
if test "$ext" = "php" ;then
if test -e "$f";then
php -l $f
fi
fi
done
2.更改权限chmod +x .git/hooks/pre-commit
故意提交一个错误语法试试,会见到报错信息,提交失败,修改后重新提交即可。
PHP Parse error: syntax error, unexpected 'fsdafasdf' (T_STRING), expecting function (T_FUNCTION) in app/controllers/IndexController.php on line 21
Errors parsing app/controllers/IndexController.php