How to prevent git commit --no-verify command?

后端 未结 1 405
粉色の甜心
粉色の甜心 2021-01-11 23:34

I would like to setup a pre-commit hook for all git repos to validate syntax errors using jshint and phplint. But the issue is that the git has a feature which can skip pre-

相关标签:
1条回答
  • 2021-01-12 00:20

    First off: you can't definitively prevent someone from passing the --no-verify option. That said, it's a good practice to use pre-commit hooks for linting, and it's a good practice to avoid passing the --no-verify option without reason.

    If, however, you want to make it more cumbersome to pass the --no-verify option, you could:

    1. generate a verification token and append it to the commit message in pre-commit;
    2. exit pre-receive with a non-zero exitcode if this token is missing or invalid. (Examples of things you can do in pre-receive hooks: https://github.com/github/platform-samples/tree/master/pre-receive-hooks)

    Someone determined to avoid passing --no-verify could manually do step 1, which is why this isn't 100% effective. I wouldn't recommend setting this up in a professional context, but I'm all for people using the tools at their disposal to instill good habits for themselves, while learning more about git hooks.

    0 讨论(0)
提交回复
热议问题