|
1 | 1 | # Git Hooks |
2 | 2 |
|
3 | | -This directory contains Git hooks for the ExecuTorch repository. |
| 3 | +This directory contains Git hooks for the ExecuTorch repository. It is used as |
| 4 | +`core.hooksPath`, so git looks here instead of `.git/hooks/`. |
4 | 5 |
|
5 | | -## Pre-commit Hook |
| 6 | +## Hooks |
6 | 7 |
|
7 | | -The pre-commit hook automatically updates the PyTorch commit pin in `.ci/docker/ci_commit_pins/pytorch.txt` whenever `torch_pin.py` is modified. |
| 8 | +### pre-commit |
8 | 9 |
|
9 | | -### How It Works |
| 10 | +Runs on every commit: |
10 | 11 |
|
11 | | -1. When you commit changes to `torch_pin.py`, the hook detects the change |
12 | | -2. It parses the `NIGHTLY_VERSION` field (e.g., `dev20251004`) |
13 | | -3. Converts it to a date string (e.g., `2025-10-04`) |
14 | | -4. Fetches the corresponding commit hash from the PyTorch nightly branch at https://github.com/pytorch/pytorch/tree/nightly |
15 | | -5. Updates `.ci/docker/ci_commit_pins/pytorch.txt` with the new commit hash |
16 | | -6. Automatically stages the updated file for commit |
| 12 | +1. **torch_pin sync** — when `torch_pin.py` is staged, updates the PyTorch commit |
| 13 | + pin in `.ci/docker/ci_commit_pins/pytorch.txt` and syncs grafted c10 files. |
| 14 | +2. **lintrunner** — runs `lintrunner -a --revision HEAD^ --skip MYPY` on changed |
| 15 | + files. Auto-fixes formatting and blocks on lint errors. Soft-fails if lintrunner |
| 16 | + is not installed. Runs `lintrunner init` automatically when `.lintrunner.toml` |
| 17 | + changes. |
17 | 18 |
|
18 | | -### Installation |
| 19 | +### pre-push |
19 | 20 |
|
20 | | -To install the Git hooks, run: |
| 21 | +Delegates to `.git/hooks/pre-push` if one exists. This allows backend-specific |
| 22 | +pre-push hooks (e.g., ARM's license and commit message checks) to work alongside |
| 23 | +the repo-wide hooks. |
| 24 | + |
| 25 | +## Installation |
| 26 | + |
| 27 | +Hooks are installed automatically by `./install_executorch.sh`. |
| 28 | + |
| 29 | +To install manually: |
21 | 30 |
|
22 | 31 | ```bash |
23 | | -.githooks/install.sh |
| 32 | +git config core.hooksPath .githooks |
24 | 33 | ``` |
25 | 34 |
|
26 | | -This will copy the pre-commit hook to `.git/hooks/` and make it executable. |
| 35 | +### ARM backend pre-push |
27 | 36 |
|
28 | | -### Manual Usage |
29 | | - |
30 | | -You can also run the update script manually at any time: |
| 37 | +ARM contributors should additionally install the ARM-specific pre-push hook: |
31 | 38 |
|
32 | 39 | ```bash |
33 | | -python .github/scripts/update_pytorch_pin.py |
| 40 | +cp backends/arm/scripts/pre-push .git/hooks/ |
34 | 41 | ``` |
35 | 42 |
|
36 | | -### Uninstalling |
| 43 | +## Bypassing |
37 | 44 |
|
38 | | -To remove the pre-commit hook: |
| 45 | +To skip hooks for a single commit or push: |
39 | 46 |
|
40 | 47 | ```bash |
41 | | -rm .git/hooks/pre-commit |
| 48 | +git commit --no-verify |
| 49 | +git push --no-verify |
42 | 50 | ``` |
43 | 51 |
|
44 | 52 | ## Troubleshooting |
45 | 53 |
|
46 | | -If the hook fails during a commit: |
| 54 | +If the torch_pin hook fails: |
47 | 55 |
|
48 | 56 | 1. Check that Python 3 is available in your PATH |
49 | 57 | 2. Ensure you have internet connectivity to fetch commits from GitHub |
50 | 58 | 3. Verify that the `NIGHTLY_VERSION` in `torch_pin.py` is in the correct format (`devYYYYMMDD`) |
51 | | -4. Make sure the corresponding nightly release exists in the PyTorch nightly branch |
52 | 59 |
|
53 | | -You can run the script manually to see detailed error messages: |
| 60 | +If lintrunner fails: |
54 | 61 |
|
55 | | -```bash |
56 | | -python .github/scripts/update_pytorch_pin.py |
57 | | -``` |
| 62 | +1. Run `lintrunner init` to install linter tools |
| 63 | +2. Check that your virtual environment is activated |
0 commit comments