小编Rod*_*ato的帖子

是否有更好的方法来编写一个git pre-commit钩子来检查提交中的任何php文件是否存在解析错误?

到目前为止我所拥有的是什么

#!/bin/sh

php_syntax_check()
{
    retval=0
    for i in $(git-diff-index --name-only --cached HEAD -- | grep -e '\.php$'); do
        if [ -f $i ]; then
            output=$(php -l $i)
            retval=$?
            if [ $retval -gt 0 ]; then
                echo "=============================================================================="
                echo "Unstaging $i for the commit due to the follow parse errors"
                echo "$output"
                git reset -q HEAD $i
            fi
        fi
    done

    if [ $retval -gt 0 ]; then
        exit $retval
    fi
}
php_syntax_check
Run Code Online (Sandbox Code Playgroud)

php git version-control

7
推荐指数
1
解决办法
1526
查看次数

标签 统计

git ×1

php ×1

version-control ×1