Skip to content

Commit b20a908

Browse files
committed
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.
1 parent 7b2ca65 commit b20a908

File tree

4 files changed

+25
-8
lines changed

4 files changed

+25
-8
lines changed

Library/Homebrew/bundle/commands/check.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module Homebrew
77
module Bundle
88
module Commands
99
module Check
10-
def self.run(global: false, file: nil, no_upgrade: false, verbose: false)
10+
def self.run(global: false, file: nil, no_upgrade: false, verbose: false, quiet: false)
1111
output_errors = verbose
1212
exit_on_first_error = !verbose
1313
check_result = Homebrew::Bundle::Checker.check(
@@ -37,9 +37,9 @@ def self.run(global: false, file: nil, no_upgrade: false, verbose: false)
3737

3838
puts "Satisfy missing dependencies with `brew bundle install`."
3939
exit 1
40-
else
41-
puts "The Brewfile's dependencies are satisfied."
4240
end
41+
42+
puts "The Brewfile's dependencies are satisfied." unless quiet
4343
end
4444
end
4545
end

Library/Homebrew/bundle/commands/exec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,12 @@ module Exec
4747

4848
PATH_LIKE_ENV_REGEX = /.+#{File::PATH_SEPARATOR}/
4949

50-
def self.run(*args, global: false, file: nil, subcommand: "", services: false)
50+
def self.run(*args, global: false, file: nil, subcommand: "", services: false, check: false)
51+
if check
52+
require "bundle/commands/check"
53+
Homebrew::Bundle::Commands::Check.run(global:, file:, quiet: true)
54+
end
55+
5156
# Cleanup Homebrew's global environment
5257
HOMEBREW_ENV_CLEANUP.each { |key| ENV.delete(key) }
5358

Library/Homebrew/cmd/bundle.rb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,15 @@ class Bundle < AbstractCommand
5151
`brew bundle remove` <name> [...]:
5252
Remove entries that match `name` from your `Brewfile`. Use `--formula`, `--cask`, `--tap`, `--mas`, `--whalebrew` or `--vscode` to remove only entries of the corresponding type. Passing `--formula` also removes matches against formula aliases and old formula names.
5353
54-
`brew bundle exec` <command>:
54+
`brew bundle exec` [--check] <command>:
5555
Run an external command in an isolated build environment based on the `Brewfile` dependencies.
5656
5757
This sanitized build environment ignores unrequested dependencies, which makes sure that things you didn't specify in your `Brewfile` won't get picked up by commands like `bundle install`, `npm install`, etc. It will also add compiler flags which will help with finding keg-only dependencies like `openssl`, `icu4c`, etc.
5858
59-
`brew bundle sh`:
59+
`brew bundle sh` [--check]:
6060
Run your shell in a `brew bundle exec` environment.
6161
62-
`brew bundle env`:
62+
`brew bundle env` [--check]:
6363
Print the environment variables that would be set in a `brew bundle exec` environment.
6464
EOS
6565
flag "--file=",
@@ -121,6 +121,9 @@ class Bundle < AbstractCommand
121121
description: "`dump` does not add `restart_service` to formula lines."
122122
switch "--zap",
123123
description: "`cleanup` casks using the `zap` command instead of `uninstall`."
124+
switch "--check",
125+
description: "Check that all dependencies in the Brewfile are installed before " \
126+
"running `exec`, `sh`, or `env`."
124127

125128
conflicts "--all", "--no-vscode"
126129
conflicts "--vscode", "--no-vscode"
@@ -129,6 +132,8 @@ class Bundle < AbstractCommand
129132
named_args %w[install dump cleanup check exec list sh env edit]
130133
end
131134

135+
BUNDLE_EXEC_COMMANDS = %w[exec sh env].freeze
136+
132137
sig { override.void }
133138
def run
134139
# Keep this inside `run` to keep --help fast.
@@ -139,6 +144,10 @@ def run
139144
raise UsageError, "This command does not take more than 1 subcommand argument."
140145
end
141146

147+
if args.check? && BUNDLE_EXEC_COMMANDS.exclude?(subcommand)
148+
raise UsageError, "`--check` can be used only with #{BUNDLE_EXEC_COMMANDS.join(", ")}."
149+
end
150+
142151
global = args.global?
143152
file = args.file
144153
args.zap?
@@ -213,7 +222,7 @@ def run
213222
when "check"
214223
require "bundle/commands/check"
215224
Homebrew::Bundle::Commands::Check.run(global:, file:, no_upgrade:, verbose:)
216-
when "exec", "sh", "env"
225+
when *BUNDLE_EXEC_COMMANDS
217226
named_args = case subcommand
218227
when "exec"
219228
_subcommand, *named_args = args.named

Library/Homebrew/sorbet/rbi/dsl/homebrew/cmd/bundle.rbi

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)