Skip to content

formula_installer: keep unlinked kegs unlinked - #24514

Merged
dduugg merged 2 commits into
Homebrew:mainfrom
dduugg:keep-unlinked-kegs
Nov 6, 2026
Merged

dduugg merged 2 commits into
Homebrew:mainfrom
dduugg:keep-unlinked-kegs

Conversation

@dduugg

@dduugg dduugg commented Nov 6, 2026 •

Copy link
Copy Markdown
Member
  • 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 followed our Contributing guidelines?
  • 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.


@coderabbitai

coderabbitai Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Summary

Summary by CodeRabbit

  • Bug Fixes
    • 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: Passed 4

Check name Status Explanation
Title check Passed The title describes the main change: keeping unlinked kegs unlinked.
Description check Passed The description covers the linking changes, dependency behaviour, and tests.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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.

Comment thread Library/Homebrew/formula_installer.rb Resolved

@MikeMcQuaid MikeMcQuaid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks looks good! CodeRabbit comment up to you to decide what to do, no rereview needed either way.

Comment thread Library/Homebrew/formula_installer.rb Resolved
- `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
@dduugg
dduugg force-pushed the keep-unlinked-kegs branch from c7e5ce3 to 7eefd44 Compare November 6, 2026 18:55
@dduugg

dduugg commented Nov 6, 2026

Copy link
Copy Markdown
Member Author

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.)

@dduugg
dduugg enabled auto-merge November 6, 2026 18:59

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick comments: 2

Library/Homebrew/test/reinstall_spec.rb: 1

23-32: Trivial · Maintainability & Code Quality · Quick win

Test the unlinked state after reinstall.

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.

Library/Homebrew/test/upgrade_spec.rb: 1

97-115: Trivial · Maintainability & Code Quality · Quick win

Test the unlinked state after an upgrade.

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.

@dduugg dduugg mentioned this pull request Nov 6, 2026
8 tasks done
@dduugg
dduugg added this pull request to the merge queue Nov 6, 2026
Merged via the queue into Homebrew:main with commit 7fa5136 Nov 6, 2026
54 checks passed
@dduugg
dduugg deleted the keep-unlinked-kegs branch November 6, 2026 20:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

⌂ 换网址