-
Notifications
You must be signed in to change notification settings - Fork 841
LFS File pre-commit check #13947
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
base: develop
Are you sure you want to change the base?
LFS File pre-commit check #13947
Conversation
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
WalkthroughThis PR adds a Git LFS validation pre-commit hook to detect when binary files are inadvertently committed instead of LFS pointers. It includes a new Python script that checks staged files for LFS attributes and verifies they contain pointer data, plus configuration updates to enable the hook. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Build Artifacts
|
712e629 to
08d3850
Compare
3d5bbe5 to
08d3850
Compare
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
.pre-commit-hooks/check_lfs_pointers.py (1)
98-99: Consider cross-platform terminal color support.The ANSI escape codes (
\033[31m) work well on Unix terminals and Git Bash, but may render as garbled text on Windows CMD. Since pre-commit is often run in various environments, consider either removing the color or using a conditional approach.Option 1 - Remove color for simplicity:
- logger.error(" \033[31m✗\033[0m %s", filepath) + logger.error(" ✗ %s", filepath)Option 2 - Conditional color based on terminal capability:
import os use_color = hasattr(sys.stderr, 'isatty') and sys.stderr.isatty() and os.name != 'nt' marker = "\033[31m✗\033[0m" if use_color else "✗" logger.error(" %s %s", marker, filepath)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.pre-commit-config.yaml(2 hunks).pre-commit-hooks/check_lfs_pointers.py(1 hunks)
🧰 Additional context used
🪛 Ruff (0.14.6)
.pre-commit-hooks/check_lfs_pointers.py
31-31: subprocess call: check for execution of untrusted input
(S603)
32-32: Starting a process with a partial executable path
(S607)
37-37: Consider moving this statement to an else block
(TRY300)
56-56: subprocess call: check for execution of untrusted input
(S603)
57-57: Starting a process with a partial executable path
(S607)
🔇 Additional comments (5)
.pre-commit-hooks/check_lfs_pointers.py (4)
1-17: Well-documented module with clear purpose.Good use of stdlib-only imports for portability. The bytes-based constant correctly handles binary content comparison.
30-39: LGTM - Logic is correct.The static analysis hints (S603, S607, TRY300) are acceptable here:
gitis expected to be on PATH in any git hook context, and filenames come from the pre-commit framework. The try/except structure is clear enough.
42-64: Staged content inspection is correctly implemented.Using
git show :filepathto access the staged blob rather than the working tree file is the right approach. The bytes-based comparison correctly handles binary content.
120-121: Standard entry point pattern.Correctly passes command-line arguments to
main()and propagates the exit code..pre-commit-config.yaml (1)
1-1: Exclude pattern correctly allows font files to be checked.The negative lookahead
(?!assets/fonts)ensuresstatic/assets/fonts/*paths are NOT excluded, allowing the LFS hook to validate font files while other static assets remain excluded from pre-commit checks.
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
|
(we should squash commit this) |
Summary
Implementation details:
git check-attr filterto identify files marked for LFS (no manual .gitattributes parsing required)git show :filepathto verify it starts with the LFS pointer headerThis will prevent the recurring issue where binary files (fonts, fixtures) were accidentally committed as binary data instead of LFS pointers, which has occurred in multiple PRs (#7092, #6802, #6467).
References
Fixes #7099
Reviewer guidance
git lfs uninstalltouch test.woff🤖 This was created by Claude Code. @rtibbles then reviewed the generated output, and did iterative rounds of updates before making it ready for review 🤖