Respect installed dependents during autoremove#21719
Merged
MikeMcQuaid merged 2 commits intoHomebrew:mainfrom Mar 12, 2026
Merged
Respect installed dependents during autoremove#21719MikeMcQuaid merged 2 commits intoHomebrew:mainfrom
MikeMcQuaid merged 2 commits intoHomebrew:mainfrom
Conversation
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.
Contributor
There was a problem hiding this comment.
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.autoremovecandidates by checking for installed dependents viaInstalledDependents.find_some_installed_dependents. - Add an RSpec example ensuring
autoremoveproduces 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.
MikeMcQuaid
approved these changes
Mar 12, 2026
Member
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Thanks! Tweaked style a little. In future please always fill out the PR template.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
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)