Skip to content

formula_pin: pin kegs under an alias or old name - #24655

Merged
MikeMcQuaid merged 1 commit into
Homebrew:mainfrom
hyuraku:formula-pin-other-name-racks
Nov 17, 2026
Merged

MikeMcQuaid merged 1 commit into
Homebrew:mainfrom
hyuraku:formula-pin-other-name-racks

Conversation

@hyuraku

@hyuraku hyuraku commented Nov 17, 2026

Copy link
Copy Markdown
Member

If a keg sits in the rack of an alias or old name, brew pin does nothing and prints nothing. A pin that already exists under that name is also ignored: brew upgrade upgrades the formula and brew unpin says it is not pinned. brew list --pinned still lists it, because it reads the rack names.

I found this with automated testing. Kegs stay in alias racks in practice, for example Cellar/postgresql after postgresql became an alias (#24527). pin finds the right keg, but it rebuilds the path from the current name's rack, which does not exist, so it returns early.

To reproduce:

$ brew tap-new --no-git ta/one
$ # add Formula/app.rb
$ brew trust --tap ta/one
$ brew install ta/one/app
$ brew pin app
$ # rename Formula/app.rb to Formula/[email protected] with a newer version and add the alias Aliases/app
$ brew list --pinned
app
$ brew upgrade --dry-run app
==> Would upgrade 1 requested outdated package
ta/one/app 0.2
$ brew unpin app
Warning: ta/one/app@2 not pinned

Now pin links the keg itself under its rack name, and FormulaPin#path looks for a pin under each possible name, like Formula#linked_keg does. With the same steps, brew upgrade --dry-run app prints Not upgrading 1 pinned package and brew unpin app works. brew list --pinned and Migrator already use rack names, so they still match.


  • 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; every commit has a human author or co-author and I will answer maintainer questions and review comments myself without AI/LLM.

AI (Claude Code) found this bug, drafted the fix and test, and checked the steps above before and after the fix. I reviewed the change and ran brew lgtm locally.


@coderabbitai

coderabbitai Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Pinning a formula through an alias now correctly records and recognises the pinned version under that alias.
    • Pinning now leaves an existing pin unchanged and does nothing when no installed version is available.

Formula pin lookup now checks the formula’s possible names. Pin creation links the latest installed keg unless no keg exists or the formula is already pinned. Alias-Rack tests cover pin creation and recognition.

Changes: Formula pin alias support

Layer / File(s) Summary
Pin lookup and creation
Library/Homebrew/formula_pin.rb, Library/Homebrew/test/formula_pin_spec.rb
FormulaPin.path searches possible names for a pinned symlink and falls back to the formula name. pin returns if no keg exists or the formula is already pinned; otherwise, it links the latest keg. Tests cover pinning and recognising an alias-Rack pin.
Merge Risk: Minimal · up to bf212

This change makes pinning work for kegs installed under an alias or old name, so upgrade and unpin recognise those pins. No concrete merge-blocking risk is evident from the supplied context.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: pinning kegs that sit in an alias or old-name rack. The raw summary confirms that FormulaPin#pin now links the keg under its rack name and that FormulaPin#path searche…
Description check Passed The description explains the bug, gives step-by-step reproduction commands, and describes the fix in FormulaPin#pin and FormulaPin#path. It matches the changeset, which the raw summary and objectives …
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.
Full details: Title check

Explanation

The title names the main change: pinning kegs that sit in an alias or old-name rack. The raw summary confirms that FormulaPin#pin now links the keg under its rack name and that FormulaPin#path searches each possible name. The title is specific and matches the changeset.

Full details: Description check

Explanation

The description explains the bug, gives step-by-step reproduction commands, and describes the fix in FormulaPin#pin and FormulaPin#path. It matches the changeset, which the raw summary and objectives confirm, so it is clearly related.

Recent 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: ff761f33-f87a-4469-96ec-7614d5ded31b
Commits

Reviewing files that changed from the base of the PR and between 8655ee4 and bf21276.

Files selected for processing: 2

  • Library/Homebrew/formula_pin.rb
  • Library/Homebrew/test/formula_pin_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.

@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!

@MikeMcQuaid

Copy link
Copy Markdown
Member

@hyuraku please email me at [email protected]! nothing bad 😁

@MikeMcQuaid
MikeMcQuaid added this pull request to the merge queue Nov 17, 2026
Merged via the queue into Homebrew:main with commit b25ccac Nov 17, 2026
86 of 87 checks passed
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