-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add pre-commit hooks script #43656
Add pre-commit hooks script #43656
Conversation
/check-enforcer override |
@@ -0,0 +1,36 @@ | |||
#!/bin/sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@srnagar can you give more context on this? In general we have avoided git hooks because they are very fragile and cannot be relied on. From all our other trials they have caused more problems than they have helped.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a MQ task. More details on this can be found in this issue - #41715
The main reason was to ensure we did some basic validation like cred scanner and spell checks done before the changes are committed as these are more sensitive and don't want it to be part of commit history. This PR only contains a script and doesn't automatically enable pre-commit hooks for everyone. It is an opt-in feature.
Could you please let me know what were some of the problems this caused in the past?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a number of issues:
- There is no way to automatically setup a git hook so they cannot be relied on because they may not be enabled.
- Running random tools during this pre-commit time cause random failures. Anytime a failure occurs in one of these tools the commits also fail. This leads to often needing to explicitly disabling the hooks do to get a commit in.
We have tried to use these in .NET and JS repos in the past and they both decided to revert using them because of a lot of issues. I also have had nothing but issues with these in my past teams as well which is why I don't recommend them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to close the loop on this, we discussed this in the Java team meeting and will keep the script (with some improvements) in the eng/scripts
directory. This will not automatically be used and will allow users of the repo to opt in to using this, if needed. If we run into issues, it's easy to opt out.
Fixes #41715