We have a nice pre-commit hook for GIT, as well as a nice commit-msg. The pre-commit hook does a syntax validation and the commit-msg does some other business logic. It all works well.
However, I’d like to add Coding Standards validation to the pre-commit hook. In fact, it’s already added. However, I don’t want to strictly enforce our developers to match up with the coding standards, by default I’d like to validate the code for standards but if they would like to pass Coding Standards Validation, I’d like to let them pass by adding a parameter during commit.
Is it possible to capture/interpret any command line parameter which was given during commit to git at the pre-commit hook level in order to skip coding standard validation in the pre-commit hook (optionally?)
Or is it possible only in the pre-commit message hook by analyzing the commit message for a specific substring?
Please share your best practices about how (and where) to create command line controlled conditional code using git pre-commit hook (or other git hooks).
A simple way of doing this would be to simply use an environment variable:
and then in the script (example in Bash, but you could read env vars in whatever language your hook is in):
Git doesn’t normally pass information beyond what is listed in
man githooksto each hook, so trying to do it with a “command line option” a lagit commit --no-standardsor some such wouldn’t work.