Skip to content

Add pre-commit git hook to run lintrunner on staged files#28013

Merged
vraspar merged 3 commits intomicrosoft:mainfrom
vraspar:vraspar/add-githooks-precommit
Apr 9, 2026
Merged

Add pre-commit git hook to run lintrunner on staged files#28013
vraspar merged 3 commits intomicrosoft:mainfrom
vraspar:vraspar/add-githooks-precommit

Conversation

@vraspar
Copy link
Copy Markdown
Contributor

@vraspar vraspar commented Apr 8, 2026

Description

Add a pre-commit git hook that runs lintrunner on staged files, catching lint and formatting issues before they reach CI.

The hook runs lintrunner in check-only mode (no auto-fix) to avoid issues with partial staging. If lint issues are found, the commit is blocked and the developer is prompted to run lintrunner -a to fix.

The hook is opt-in. Contributors enable it with: git config core.hooksPath .githooks

Motivation and Context

Follow-up from #27856. Catching lint issues at commit time saves CI cycles and review time.

@vraspar vraspar requested review from Copilot and edgchen1 April 8, 2026 22:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds an opt-in Git pre-commit hook that runs lintrunner against the files being committed, aiming to catch lint/format issues earlier and reduce CI churn.

Changes:

  • Document how to enable/bypass the repo-provided Git hooks via core.hooksPath.
  • Add a .githooks/pre-commit script that runs lintrunner in check-only mode and blocks commits on failure.
  • Ensure .githooks uses LF line endings via .gitattributes.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
CONTRIBUTING.md Documents enabling the pre-commit hook and basic usage/bypass guidance.
.githooks/pre-commit Implements a pre-commit hook that runs lintrunner on paths from the index.
.gitattributes Forces LF endings for hooks to work consistently across platforms.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Copy Markdown
Contributor

@edgchen1 edgchen1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding this!

edgchen1
edgchen1 previously approved these changes Apr 9, 2026
@vraspar vraspar enabled auto-merge (squash) April 9, 2026 18:04
@vraspar vraspar requested a review from edgchen1 April 9, 2026 18:04
@vraspar vraspar merged commit cd20524 into microsoft:main Apr 9, 2026
95 of 96 checks passed
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.

3 participants