Skip to content
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

Merged
merged 11 commits into from
Jan 13, 2025
Merged

Add pre-commit hooks script #43656

merged 11 commits into from
Jan 13, 2025

Conversation

srnagar
Copy link
Member

@srnagar srnagar commented Dec 31, 2024

Fixes #41715

@srnagar srnagar marked this pull request as ready for review January 13, 2025 18:13
@srnagar srnagar changed the title Precommit hook Add pre-commit hooks script Jan 13, 2025
eng/scripts/pre-commit Outdated Show resolved Hide resolved
eng/scripts/pre-commit Outdated Show resolved Hide resolved
eng/scripts/pre-commit Show resolved Hide resolved
@srnagar
Copy link
Member Author

srnagar commented Jan 13, 2025

/check-enforcer override

@srnagar srnagar merged commit a596a57 into Azure:main Jan 13, 2025
4 checks passed
@@ -0,0 +1,36 @@
#!/bin/sh
Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

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:

  1. There is no way to automatically setup a git hook so they cannot be relied on because they may not be enabled.
  2. 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.

Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Investigate git pre-commit hooks
4 participants