Git: pre-receive hook with PHP_CodeSniffer

后端 未结 10 1607
情话喂你
情话喂你 2021-02-04 07:51

Since switching from SVN to Git, we lost the ability to enforce our coding standards through a pre-commit hook on the subversion server.

With Git, you only

10条回答
  •  北海茫月
    2021-02-04 08:38

    I have experimented with this too. I don't have the code at hand at the moment, but I used one of the hooks (not pre-receive, I think it was the update one) to do a temporary checkout of the new ref. You can speed this up by having a checked out tree which you just have to update and by just doing shallow clones.

    This allows access to the whole source tree and you can not only run CS on the files changed with the push, but also run the unit or smoke tests.

    I also agree with some of the other comments that these tests should be kept to a minimum, because nothing is more annoying than being blocked by commit hooks. Any further checks should be happening in your CI server or deployment system.

提交回复
热议问题