Skip to content

Conversation

@AbdelrahmanHafez
Copy link
Contributor

Fixes #21350

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) with your changes locally?

Copilot AI review requested due to automatic review settings January 2, 2026 01:24
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 fixes issue #21350 by preventing autoremove from removing Brewfile packages during cleanup operations. The solution adds protection for Brewfile formulae when running brew bundle cleanup.

Key changes:

  • Adds a protected_formulae parameter to Utils::Autoremove.removable_formulae to exclude specific formulae from removal
  • Implements environment variable-based protection by setting HOMEBREW_NO_CLEANUP_FORMULAE during formula uninstall operations
  • Ensures Brewfile formulae are preserved even if they have installed_on_request: false

Reviewed changes

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

File Description
Library/Homebrew/utils/autoremove.rb Adds optional protected_formulae parameter to removable_formulae method to exclude specific formulae from removal
Library/Homebrew/test/utils/autoremove_spec.rb Adds comprehensive test coverage for the new protected_formulae parameter functionality
Library/Homebrew/bundle/commands/cleanup.rb Implements with_brewfile_formulae_protected helper method to temporarily set HOMEBREW_NO_CLEANUP_FORMULAE environment variable during formula uninstall
Library/Homebrew/test/bundle/commands/cleanup_spec.rb Adds tests verifying that Brewfile formulae are protected via environment variable during uninstall operations

💡 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 for the PR!

I'd prefer Option 2 in #21350.

brew bundle cleanup already has side-effects and there will be other issues with having things in a Brewfile that are not marked as installed-on-request so having cleanup handle this seems appropriate. brew bundle (install) should also handle this, if it doesn't already.

Happy to rereview after that.

Not at all a big deal but for future reference, no need to open an issue if you're going to soon afterwards open a PR to fix your own issue: skip straight to opening a PR in that case.

Thanks again!

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

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.


💡 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! Few style tweaks.

AbdelrahmanHafez and others added 2 commits January 2, 2026 17:58
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
@AbdelrahmanHafez
Copy link
Contributor Author

Thanks for the quick feedback @MikeMcQuaid!

I've implemented Option 2 and addressed your comments. Let me know if there's anything else you'd like changed.

no need to open an issue if you're going to soon afterwards open a PR

Noted, will skip straight to PRs next time. 👍

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! Looking great so far. Few more comments.

AbdelrahmanHafez and others added 2 commits January 2, 2026 18:45
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
- added early returns to `mark_as_installed_on_request!`
- moved the call inside `if formulae.any?` in cleanup.rb
- removed unnecessary mocks from cleanup_spec.rb contexts
- refactored bundle_spec.rb with subject/let/before
@AbdelrahmanHafez
Copy link
Contributor Author

Good points @MikeMcQuaid, all addressed. Let me know if there's anything else we can do better.

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.

Great work here, thanks @AbdelrahmanHafez!

@MikeMcQuaid MikeMcQuaid enabled auto-merge January 3, 2026 10:18
@MikeMcQuaid MikeMcQuaid added this pull request to the merge queue Jan 3, 2026
Merged via the queue into Homebrew:main with commit fe0a384 Jan 3, 2026
36 checks passed
@AbdelrahmanHafez AbdelrahmanHafez deleted the fix/bundle-cleanup branch January 3, 2026 18: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.

[Bug]brew bundle --cleanup triggers autoremove which ignores Brewfile

2 participants