Supports in repository patch files#22144
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for formula patch do blocks to reference patch files stored within the same formula repository (e.g., tap-local patches/*.diff), rather than requiring inline patches or external patch URLs. It introduces a new file DSL entry for patch resources and ensures local patch files can be resolved both for locally loaded formulae and for formulae loaded via the API source cache.
Changes:
- Add a
filepatch DSL that produces a newLocalPatchtype, applied like an embedded patch but sourced from a repository-relative file path. - Teach API source formula loading to also fetch referenced local patch files into the API source cache.
- Update FormulaAudit/RuboCop patch auditing and expand test coverage for local patch file behavior and edge cases.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| Library/Homebrew/patch.rb | Creates LocalPatch when a patch block uses file, and rejects incompatible DSL combinations. |
| Library/Homebrew/local_patch.rb | Implements LocalPatch to read patch contents from a repository-relative path with realpath-based escape protection. |
| Library/Homebrew/resource.rb | Extends Resource::Patch with a file DSL method and basic path validation. |
| Library/Homebrew/api/formula.rb | Adds source_download_path helper and fetches local patch files when loading formula source via API cache. |
| Library/Homebrew/rubocops/patches.rb | Avoids assuming every patch do block has a url, so local file patches don’t trigger errors/offenses. |
| Library/Homebrew/test/patch_spec.rb | Adds unit coverage for LocalPatch creation and DSL validation errors. |
| Library/Homebrew/test/patching_spec.rb | Adds system-level coverage for applying local patch files (path-loaded formulae, taps, strip levels, missing files, symlink escape). |
| Library/Homebrew/test/api/formula_spec.rb | Verifies local patch files are fetched/read correctly when formula source is loaded from the API source cache. |
| Library/Homebrew/test/rubocops/patches_spec.rb | Ensures RuboCop patch auditing reports no offenses for local file patches. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Thanks @rexmhall09! looking good so far. a few comments.
|
I'm cleaning up the many commits into a few clear ones. |
|
Looks like the docs failure is from HTML-Proofer hitting 503s on existing Debian wiki links ( |
What does this PR do?
This recreates the local patch file support from closed PR #22136 on top of current
main.It allows formula patches to reference patch files stored in the repository, while keeping the implementation
scoped to the patch-file feature itself. I intentionally left the earlier class-extraction refactor out of this PR
to keep the diff focused and easier to review.
Why is this useful?
This makes larger or reusable patches easier to maintain than embedding them directly in formula files, while
preserving existing patch behavior and test coverage.
Contributing document?
for the same change?
claims must include Hyperfine benchmarks.
brew lgtmwith your changes locally? (not really needed)I used GPT 5.5 via the oh-my-pi coding agent to recreate the local patch file feature from the old closed PR #22136 on top
of current
main, while accounting for maintainer feedback. I manually reviewed the resulting diff, kept theclass-extraction refactor out of this PR, and verified the feature with targeted tests.
Verified with:
./bin/brew tests --only=patch./bin/brew tests --only=patching./bin/brew tests --only=api/formula./bin/brew typecheck./bin/brew style --fix --changed