Skip to content

Respect installed dependents during autoremove#21719

Merged
MikeMcQuaid merged 2 commits intoHomebrew:mainfrom
rexmhall09:main
Mar 12, 2026
Merged

Respect installed dependents during autoremove#21719
MikeMcQuaid merged 2 commits intoHomebrew:mainfrom
rexmhall09:main

Conversation

@rexmhall09
Copy link
Contributor

@rexmhall09 rexmhall09 commented Mar 12, 2026

This PR adds a safety check to brew cleanup --autoremove. It filters out any formulae that uninstall will later refuse (due to installed dependents). This avoids the error where cleanup lists “1 unneeded formula” that actually can’t be removed.

see closed PR: #13729
AI agent assisted in this PR (tests ran by agents)

cleanup: skip autoremove for formulae required by installed dependents

Use InstalledDependents.find_some_installed_dependents to filter
autoremove candidates before uninstalling. This prevents cleanup from
attempting to remove formulae that uninstall would refuse due to
installed dependents.

Add a spec ensuring required formulae are not printed or uninstalled.
@rexmhall09 rexmhall09 marked this pull request as ready for review March 12, 2026 03:48
Copilot AI review requested due to automatic review settings March 12, 2026 03:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates Homebrew’s cleanup autoremove logic to avoid uninstalling formulae that are still required by installed dependents, and adds a regression test to cover that behavior.

Changes:

  • Filter Cleanup.autoremove candidates by checking for installed dependents via InstalledDependents.find_some_installed_dependents.
  • Add an RSpec example ensuring autoremove produces no output and performs no uninstalls when the candidate is required by an installed dependent.
  • Add required test dependencies for stubbing Utils::Autoremove / uninstall behavior in the cleanup spec.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
Library/Homebrew/cleanup.rb Adds an installed-dependents check to prevent autoremoving formulae still required by installed dependents.
Library/Homebrew/test/cleanup_spec.rb Adds a regression test for Cleanup.autoremove when installed dependents exist.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Thanks! Tweaked style a little. In future please always fill out the PR template.

@MikeMcQuaid MikeMcQuaid enabled auto-merge March 12, 2026 08:41
@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Mar 12, 2026
Merged via the queue into Homebrew:main with commit 83f5d45 Mar 12, 2026
36 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.

3 participants