Skip to content

Read the linked keg version, not the oldest keg - #24

Open
alexmikheen wants to merge 1 commit into
macadmins:mainfrom
alexmikheen:fix/linked-keg-version
Open

alexmikheen wants to merge 1 commit into
macadmins:mainfrom
alexmikheen:fix/linked-keg-version

Conversation

@alexmikheen

@alexmikheen alexmikheen commented Nov 17, 2026 •

Copy link
Copy Markdown

getVersion returned installed[0]. Homebrew sorts installed from oldest to newest (installed_kegs.sort_by(&:scheme_and_version) in Formula#to_hash), so with an old keg still on disk check --min-version compared the oldest version, not the one in use.

Example: git 2.45.0 and 2.52.0 kegs, 2.52.0 linked. check --min-version=2.50 git said "below minimum" and Munki ran an upgrade that was not needed. An old keg stays when cleanup is turned off (HOMEBREW_NO_INSTALL_CLEANUP, or the formula is listed in HOMEBREW_NO_CLEANUP_FORMULAE).

Changes

  • HomebrewFormula gets LinkedKeg (linked_keg). The cache already stores the full brew info output, and a test pins that the cached path keeps the field.
  • check uses the version in use: linked_keg when it is a stable keg that brew lists as installed; otherwise (a keg-only formula, a linked HEAD-… keg, or a link to a keg that is gone) the newest installed stable keg. A HEAD keg is used only when no stable keg exists, because a HEAD version cannot be compared.
  • README (## Check): states that the version in use is checked and that older kegs left on disk are not.

Behaviour changes to be aware of

  • Older kegs left on disk are no longer checked. On main an old keg below the floor made check fail, and the paired carafe upgrade ran brew cleanup <formula>, which removed it. If you want old kegs gone, brew cleanup still does that.
  • The version field in check's JSON output, and the exported InstalledVersion / VersionMeetsOrExceedsMinimum, follow the same rule.
  • The new struct field is additive, but breaks unkeyed HomebrewFormula{...} literals, if anyone uses them.

Tests

  • TestGetVersion: old keg plus newer linked keg; keg-only formula with two kegs; keg-only with stable and HEAD kegs; linked HEAD keg next to a stable keg; linked keg missing from installed; only a HEAD keg.
  • TestInfoOutputCached_KeepsLinkedKeg.
  • On this Mac, linked_keg matched an installed entry for all 118 linked formulae, including versions with a revision (4.0.0_2).
  • go test ./..., -race, golangci-lint run (v2.6.2) and the coverage check pass. Coverage: 79.5% on main, 79.8% with this PR.

Independent of the other two PRs; all three merge together cleanly, and the merged tree passes the same checks (82.0% coverage).

brew info sorts "installed" from oldest to newest, so installed[0]
is the oldest keg. With an old keg left on disk, check --min-version
compared the wrong version and asked for an upgrade that was not
needed.

check now uses the version in use:
- linked_keg, when it is a stable keg that brew lists as installed;
- otherwise (a keg-only formula, a linked HEAD keg, or a link to a
  keg that is gone) the newest installed stable keg. A HEAD keg is
  used only when no stable keg exists, because a HEAD version cannot
  be compared.

Older kegs left on disk are no longer checked; the README says so.
The version field in check's JSON output and the exported
InstalledVersion / VersionMeetsOrExceedsMinimum follow the same
rule. HomebrewFormula gets a LinkedKeg field, and a test pins that
the cached path keeps it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant