File tree Expand file tree Collapse file tree 3 files changed +108
-0
lines changed
Expand file tree Collapse file tree 3 files changed +108
-0
lines changed Original file line number Diff line number Diff line change 1+ # Git Hooks
2+
3+ This directory contains Git hooks for the ExecuTorch repository.
4+
5+ ## Pre-commit Hook
6+
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+
9+ ### How It Works
10+
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
17+
18+ ### Installation
19+
20+ To install the Git hooks, run:
21+
22+ ``` bash
23+ .githooks/install.sh
24+ ```
25+
26+ This will copy the pre-commit hook to ` .git/hooks/ ` and make it executable.
27+
28+ ### Manual Usage
29+
30+ You can also run the update script manually at any time:
31+
32+ ``` bash
33+ python .github/scripts/update_pytorch_pin.py
34+ ```
35+
36+ ### Uninstalling
37+
38+ To remove the pre-commit hook:
39+
40+ ``` bash
41+ rm .git/hooks/pre-commit
42+ ```
43+
44+ ## Troubleshooting
45+
46+ If the hook fails during a commit:
47+
48+ 1 . Check that Python 3 is available in your PATH
49+ 2 . Ensure you have internet connectivity to fetch commits from GitHub
50+ 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+
53+ You can run the script manually to see detailed error messages:
54+
55+ ``` bash
56+ python .github/scripts/update_pytorch_pin.py
57+ ```
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ # Script to install Git hooks from .githooks directory
4+
5+ set -e
6+
7+ SCRIPT_DIR=" $( cd " $( dirname " ${BASH_SOURCE[0]} " ) " && pwd) "
8+ GIT_DIR=" $( git rev-parse --git-dir) "
9+ HOOKS_DIR=" ${GIT_DIR} /hooks"
10+
11+ echo " Installing Git hooks..."
12+
13+ # Install pre-commit hook
14+ echo " 📦 Installing pre-commit hook..."
15+ cp " ${SCRIPT_DIR} /pre-commit" " ${HOOKS_DIR} /pre-commit"
16+ chmod +x " ${HOOKS_DIR} /pre-commit"
17+ echo " ✅ pre-commit hook installed"
18+
19+ echo " "
20+ echo " 🎉 Git hooks installed successfully!"
21+ echo " "
22+ echo " The pre-commit hook will automatically update .ci/docker/ci_commit_pins/pytorch.txt"
23+ echo " whenever you commit changes to torch_pin.py"
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bash
2+
3+ # Pre-commit hook to automatically update PyTorch commit pin when torch_pin.py changes
4+
5+ # Check if torch_pin.py is being committed
6+ if git diff --cached --name-only | grep -q " ^torch_pin.py$" ; then
7+ echo " 🔍 Detected changes to torch_pin.py"
8+ echo " 📝 Updating PyTorch commit pin..."
9+
10+ # Run the update script
11+ if python .github/scripts/update_pytorch_pin.py; then
12+ # Check if pytorch.txt was modified
13+ if ! git diff --quiet .ci/docker/ci_commit_pins/pytorch.txt; then
14+ echo " ✅ PyTorch commit pin updated successfully"
15+ # Stage the updated file
16+ git add .ci/docker/ci_commit_pins/pytorch.txt
17+ echo " 📌 Staged .ci/docker/ci_commit_pins/pytorch.txt"
18+ else
19+ echo " ℹ️ PyTorch commit pin unchanged"
20+ fi
21+ else
22+ echo " ❌ Failed to update PyTorch commit pin"
23+ echo " Please run: python .github/scripts/update_pytorch_pin.py"
24+ exit 1
25+ fi
26+ fi
27+
28+ exit 0
You can’t perform that action at this time.
0 commit comments