Git: pre-receive hook with PHP_CodeSniffer

后端 未结 10 1613
情话喂你
情话喂你 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:43

    In the Drupal project, we've recently migrated to Git and are looking at similar problems. In our case, we don't want anyone checking in a LICENSE.txt file for a module since our packaging scripts do that automatically. After some back and forth, what we came up with was a receive hook that doesn't reject a bad commit, but every time it detects a bad commit (for some definition of "bad") it automatically files a critical bug in our bug tracker. That way the code is still committed, but the module maintainer and the appropriate webmaster team both get notified immediately that something is amiss and should be fixed. You could just as easily send an email or send a tweet or whatever other notification you want.

    Actually we haven't implemented that quite yet, but that's the plan we're working on as soon as our Git implementation team has time. :-)

    Basically, there is no good solution for the problem you describe other than rephrasing it; instead of "block detectable violations" it becomes "report detectable violations." I think that's the best you can do.

提交回复
热议问题