Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@

# make sure build.sh retains Unix line endings, even when checked out on windows.
*.sh text eol=lf

# Git hooks must have Unix line endings to work on all platforms
.githooks/* text eol=lf
35 changes: 35 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh
# .githooks/pre-commit — check staged files with lintrunner before commit
#
# Setup (one-time per clone):
# git config core.hooksPath .githooks
#
# Skip when needed:
# git commit --no-verify

if ! command -v lintrunner >/dev/null 2>&1; then
echo "Warning: lintrunner not found - skipping pre-commit lint check."
echo " To install: pip install -r requirements-lintrunner.txt && lintrunner init"
exit 0
fi

# Check if there are any staged files to lint (added, copied, modified, renamed)
STAGED=$(git diff --cached --name-only --diff-filter=ACMR)
if [ -z "$STAGED" ]; then
exit 0
fi

# Run lintrunner in check mode (no auto-fix) on staged files.
# --paths-cmd lets lintrunner handle the file list safely, avoiding
# shell quoting issues with special characters in filenames.
lintrunner --paths-cmd='git diff --cached --name-only --diff-filter=ACMR'
Comment thread
vraspar marked this conversation as resolved.
Outdated
Comment thread
vraspar marked this conversation as resolved.
Outdated
STATUS=$?

if [ "$STATUS" -ne 0 ]; then
echo ""
echo "Pre-commit lint check failed."
echo " To auto-fix: lintrunner -a"
echo " Then re-stage and commit again."
echo " To skip: git commit --no-verify"
exit 1
fi
14 changes: 14 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ We're always looking for your help to improve the product (bug fixes, new featur
* Make sure your PR adheres to the [PR Guidelines](./docs/PR_Guidelines.md) and [Coding Conventions and Standards](./docs/Coding_Conventions_and_Standards.md) established by the team.
* If you're unsure about any of the above and want to contribute, you're welcome to [start a discussion](https://github.com/microsoft/onnxruntime/discussions) with the team.

## Git hooks (recommended)

This repository provides a pre-commit hook that runs [lintrunner](https://github.com/suo/lintrunner) on staged files before each commit. To enable it:
Comment thread
vraspar marked this conversation as resolved.
Outdated

```sh
git config core.hooksPath .githooks
```

The hook checks staged files for lint issues and blocks the commit if any are found. To auto-fix issues, run `lintrunner -a`, re-stage the changes, and commit again.
Comment thread
vraspar marked this conversation as resolved.
Outdated

If you need to bypass the hook (e.g., for a work-in-progress commit), use `git commit --no-verify`.

> **Note:** Setting `core.hooksPath` replaces Git's default hook directory (`.git/hooks/`). If you have existing custom hooks, you may need to integrate them manually.

## Propose a new public API

ONNX Runtime has a collection of [public APIs](./README.md#api-documentation). Some of these APIs make their way back into the Windows OS. We make compatibility commitments for these APIs and follow a structured process when adding to them. Please use the [Feature Request issue template](https://github.com/microsoft/onnxruntime/issues/new?template=feature_request.md) before starting any PRs that affect any of the public APIs.
Expand Down
Loading