30 Commits

Author SHA1 Message Date
Mike McQuaid
a1e4e9eaf7
bundle/commands/exec: make environment variables more consistent.
Let's avoid having `exec` and `env`/`sh` subcommands have different
environment variables logic. Instead, let's e.g. add `HOMEBREW_PATH`
and remove `*/Homebrew/shims/*` from the `PATH` for all three
subcommands.

This allows more consistency for users and easier to debug and reason
about behaviour.
2025-04-25 11:53:23 +01:00
Carlo Cabrera
f3c25498f8
bundle/commands/exec: check that Brewfile is installed with --check
`brew bundle exec` behaves correctly only after doing `brew bundle install`.

Running `brew bundle check` can be slow, so let's add a `--check` flag
to `brew bundle exec` which will also run `brew bundle check` before
`brew bundle exec` to ensure that the `Brewfile` has been installed
before proceeding.
2025-04-24 16:34:23 +08:00
Mike McQuaid
dbbffbaca5
Improve HOMEBREW_TEMP handling
- if HOMEBREW_TEMP is not writable, use the default temp directory
- when running `brew bundle exec`, strip various temporary directories
  from the environment if they are not writable
2025-04-14 19:10:58 +01:00
Mike McQuaid
1a1aac9715
bundle/commands/exec: adjust environment variable handling (again)
We need to ensure that we keep around some `HOMEBREW_` variables so that
the e.g. `git` shim still works in `brew bundle exec`.
2025-04-10 16:16:53 +01:00
Mike McQuaid
359b68f827
Improve brew bundle exec/env/sh environment handling
- Rather than maintaining a list of Homebrew environment variables to
  delete, delete all Homebrew (and Portable Ruby) internal variables
  that won't be used by other tools.
- When exporting variables, only export variables that have changed.
- When exporting PATH-like variables, ensure the PATH is appending to
  the existing path rather than replacing it and ensure we only include
  newly added paths.
2025-04-10 15:23:02 +01:00
Mike McQuaid
a1343c94d0
bundle/commands/exec: add missing require.
This should fix the flaky test failures in `exec_spec.rb`.
2025-04-10 13:04:01 +01:00
Bo Anderson
80f5c42f02
bundle/commands/exec: handle no services to start 2025-04-07 14:12:41 +01:00
Bo Anderson
f2513965e8
Revert "Revert "bundle: handle simultaneous exec --services better""
This reverts commit 94db0b2f3408280e20ca3888ed5c91672ab4fca2.
2025-04-07 14:10:42 +01:00
Mike McQuaid
94db0b2f34
Revert "bundle: handle simultaneous exec --services better" 2025-04-04 15:30:47 +01:00
Bo Anderson
1ef00cb55f
bundle: handle simultaneous exec --services better 2025-04-04 08:10:11 +01:00
Mike McQuaid
3012f427df
bundle: fix up formula name for environment variable.
We previously were trying to pass through invalid environment variable
names so let's fix these up and query those instead.
2025-04-03 11:05:07 +01:00
Mike McQuaid
89d0309b9c
Add brew bundle --upgrade-formulae
This flag allows you to specify formulae to upgrade, even if
`$HOMEBREW_BUNDLE_NO_UPGRADE` is set.

This is useful for upgrading specific formulae without upgrading all
formulae.

While we're here, let's add Sorbet signatures to the `Bundle` module
because I needed to add a new method there anyway.
2025-04-02 17:15:36 +01:00
Bo Anderson
4254b75cb8
bundle: add tests for exec --services 2025-04-02 16:09:16 +01:00
Mike McQuaid
c72386e3c3
bundle/commands/cleanup: correctly handle .keepme references.
Extract the relevant logic from `formula.rb`, moving to `keg.rb` and
then use this logic in `bundle/commands/cleanup.rb` to ensure that we
don't say we need to uninstall formulae that should be still kept.
2025-04-01 15:12:12 +01:00
Bo Anderson
650f62bcba
Fold brew bundle services into exec 2025-03-28 05:54:58 +00:00
Bo Anderson
c7e8b66da3
bundle: add --services flag for sh and exec 2025-03-28 05:54:57 +00:00
Bo Anderson
786ad348a5
bundle: use version env for installer service handling 2025-03-28 05:54:52 +00:00
Bo Anderson
615fb764a1
Add brew bundle services helper 2025-03-28 05:21:07 +00:00
Patrick Linnane
ad75e9b337
Merge pull request #19627 from Homebrew/bundle_check_already_output_formulae_errors
Allow callers of `brew bundle check` to filter errors.
2025-03-27 23:52:13 +00:00
Mike McQuaid
d3a64157e1
Allow callers of brew bundle check to filter errors.
If callers of `brew bundle check` have already output some formulae
errors, they can set the
`HOMEBREW_BUNDLE_CHECK_ALREADY_OUTPUT_FORMULAE_ERRORS` environment
variable to the names of the formulae that have already been output.
2025-03-27 15:37:31 +00:00
Patrick Linnane
9821a7e896
fix new offenses
Signed-off-by: Patrick Linnane <patrick@linnane.io>
2025-03-27 03:38:09 +00:00
Mike McQuaid
4c97a795a9
brew bundle env: sort and filter output.
- Sort output by key so it's more readable.
- Skip exporting empty values because shell scripts treat them as unset.
- Skip exporting non-Homebrew things that were already set in the old
  environment to avoid massive duplication and higher chances of e.g.
  bad escapes breaking things.
2025-03-25 13:47:44 +00:00
Mike McQuaid
fcd9b340a8
brew bundle env: quote values correctly.
Otherwise, certain output will break the script when `eval`ed.
2025-03-25 11:55:52 +00:00
Mike McQuaid
df0fe8a802
Add version_file: DSL to Brewfile
This allows writing to e.g. `.ruby-version` files directly from the
`Brewfile`, making it easy to keep these versions in sync.
2025-03-24 17:34:35 +00:00
Carlo Cabrera
f7ee1902e4
bundle: require more lazily
This will hopefully make using `brew bundle` a little bit snappier.
2025-03-24 22:48:58 +08:00
Bo Anderson
7e64051479
bundle: remove include Kernel references 2025-03-21 04:43:08 +00:00
Carlo Cabrera
a4f2797612
bundle/exec: fix command PATH lookup
We are checking `PATH` for the command too early, since the code below
it mutates `PATH`.

Let's defer the check to later to fix this.
2025-03-19 21:55:15 +08:00
Mike McQuaid
d84fac5af4
Look for VSCode variants
We've had requests for this in Homebrew/bundle a few times so let's
implement it both for there and for `brew edit`.

Tested on my machine with `cursor` and working as expected.
2025-03-19 11:42:37 +00:00
Mike McQuaid
7a57af242e
Cleanup some missing references to Homebrew Bundle.
Let's just call it `brew bundle` from now on as it's a normal command.

Also, fix a reference to "Homebrew Services" while we're here.
2025-03-19 09:51:39 +00:00
Mike McQuaid
bdeca530ff
Migrate Homebrew/bundle to Homebrew/brew
Co-authored-by: Bo Anderson <mail@boanderson.me>
2025-03-19 06:47:01 +00:00