You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Stop brew upgrade and brew reinstall relinking kegs that were unlinked with brew unlink, as FormulaInstaller treats link_keg: false as the default for non-keg-only formulae.
Make link_keg nilable: nil uses the default and false does not link.
Pass nil from install_dependency unless the dependency was linked, so new dependencies still link.
Update the formula_installer_spec.rb example that expected link_keg: false to link and add upgrade and reinstall examples for an unlinked keg.
Reproduce with brew install foo, brew unlink foo and brew reinstall foo (or brew upgrade foo once it is outdated): brew link --dry-run foo then reports Already linked.
Have you checked for other open Pull Requests for the same change?
Have you explained what your changes do? Performance claims (e.g. "this is faster") must include brew benchmark results.
Have you explained why you'd like these changes included, not just what they do?
For bug fixes, have you given step-by-step brew commands to reproduce the bug?
Have you written new tests (excluding integration tests)? Here's an example.
Have you successfully run brew lgtm (style, typechecking and tests) locally?
I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.
Claude Code with Sonnet 5.5 and Opus 5.5, with local review and testing.
Installation, reinstallation and upgrades now preserve an explicit choice to keep a formula unlinked. When no linking choice is specified, the default linking behaviour continues to follow the formula’s eligibility. This keeps the formula’s requested linking state consistent across these installation workflows.
FormulaInstaller now distinguishes an omitted link_keg value from explicit false. During dependency installation, it passes the previous linked state, or nil when that state is false or unavailable. Tests cover initializer defaults and unlinked kegs during reinstall and upgrade.
Changes: Link keg defaults
Layer / File(s)
Summary
Initializer link defaults Library/Homebrew/formula_installer.rb, Library/Homebrew/test/formula_installer_spec.rb
FormulaInstaller#initialize accepts a nullable link_keg value. It derives the default only when the value is nil and preserves explicit false. The spec checks that false remains false.
Dependency link state Library/Homebrew/formula_installer.rb, Library/Homebrew/test/reinstall_spec.rb, Library/Homebrew/test/upgrade_spec.rb
Dependency installation passes the previous linked state, or nil when that state is false or unavailable. Reinstall and upgrade tests check the resulting installer’s link_keg value for an unlinked keg.
Merge Risk: Minimal · previous review 7eefd
Direct upgrades and reinstalls preserve the unlinked state. Unlinked dependencies can still be relinked as before; additional lifecycle tests are recommended.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title describes the main change: keeping unlinked kegs unlinked.
Description check
The description covers the linking changes, dependency behaviour, and tests.
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Tip
🎯 Customize your risk assessments
Guide how CodeRabbit assesses merge risk and security architecture risk. Highlight sensitive changes and explain your security boundaries using Merge Risk Instructions and Security Risk Instructions in your review settings. Security architecture risk assessments require the Advanced plan or above.
✅ Automatic approvals, with your rules
Let CodeRabbit approve pull requests once required threads are resolved, pre-merge checks pass, and your risk limits are met. Enable Automatic approvals in review settings, with overrides for teams or file paths.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 057e2023-f19e-4e67-9d1e-2fab37aff750
Commits
Reviewing files that changed from the base of the PR and between 88f401f and c7e5ce3.
Files selected for processing: 4
Library/Homebrew/formula_installer.rb
Library/Homebrew/test/formula_installer_spec.rb
Library/Homebrew/test/reinstall_spec.rb
Library/Homebrew/test/upgrade_spec.rb
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
- `FormulaInstaller` treated `link_keg: false` as the default for
non-keg-only formulae, so `brew upgrade` and `brew reinstall`
relinked kegs the user had unlinked
- make `link_keg` nilable: `nil` uses the default and `false` does
not link
- pass `nil` from `install_dependency` unless the dependency was
linked, so new dependencies still link
- add upgrade and reinstall examples for an unlinked keg
I've corrected the description: !formula.keg_only? || link_keg dates from the 2020 FormulaInstaller refactor, so link_keg: false has been the default for non-keg-only formulae for a long time. (#21684 restored that after #21676, which makes this a behaviour change rather than a fix for a regression.)
Run reinstall on a linked, then unlinked, keg. Assert that the opt link remains and that the ordinary prefix links and linked-keg record are absent. The current test only checks the installer flag, so it can pass if the reinstall lifecycle creates ordinary links.
This test checks the installer flag but does not run the upgrade. A regression in the install or finish path could create ordinary links without failing this test. Add an upgrade test with an older opt-linked, unlinked keg. Assert that the new version is installed and opt-linked, but has no linked-keg record or ordinary prefix links.
Review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: d8392c45-2063-4ef9-90fc-7dfef818d46f
Commits
Reviewing files that changed from the base of the PR and between c7e5ce3 and 7eefd44.
Files selected for processing: 1
Library/Homebrew/formula_installer.rb
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
brew upgradeandbrew reinstallrelinking kegs that were unlinked withbrew unlink, asFormulaInstallertreatslink_keg: falseas the default for non-keg-only formulae.link_kegnilable:niluses the default andfalsedoes not link.nilfrominstall_dependencyunless the dependency was linked, so new dependencies still link.formula_installer_spec.rbexample that expectedlink_keg: falseto link and add upgrade and reinstall examples for an unlinked keg.brew install foo,brew unlink fooandbrew reinstall foo(orbrew upgrade fooonce it is outdated):brew link --dry-run foothen reportsAlready linked.brew benchmarkresults.brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?Claude Code with Sonnet 5.5 and Opus 5.5, with local review and testing.