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.
This commit is contained in:
parent
14fe53b9fd
commit
a4f2797612
@ -59,15 +59,6 @@ module Homebrew
|
|||||||
|
|
||||||
command = args.first
|
command = args.first
|
||||||
|
|
||||||
# For commands which aren't either absolute or relative
|
|
||||||
if command.exclude? "/"
|
|
||||||
# Save the command path, since this will be blown away by superenv
|
|
||||||
command_path = which(command)
|
|
||||||
raise "command was not found in your PATH: #{command}" if command_path.blank?
|
|
||||||
|
|
||||||
command_path = command_path.dirname.to_s
|
|
||||||
end
|
|
||||||
|
|
||||||
@dsl = Brewfile.read(global:, file:)
|
@dsl = Brewfile.read(global:, file:)
|
||||||
|
|
||||||
require "formula"
|
require "formula"
|
||||||
@ -111,8 +102,11 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
# rubocop:enable Homebrew/MoveToExtendOS
|
# rubocop:enable Homebrew/MoveToExtendOS
|
||||||
|
|
||||||
# Ensure the Ruby path we saved goes before anything else, if the command was in the PATH
|
# For commands which aren't either absolute or relative
|
||||||
ENV.prepend_path "PATH", command_path if command_path.present?
|
# Add the command directory to PATH, since it may get blown away by superenv
|
||||||
|
if command.exclude?("/") && (which_command = which(command)).present?
|
||||||
|
ENV.prepend_path "PATH", which_command.dirname.to_s
|
||||||
|
end
|
||||||
|
|
||||||
# Replace the formula versions from the environment variables
|
# Replace the formula versions from the environment variables
|
||||||
formula_versions = {}
|
formula_versions = {}
|
||||||
@ -155,6 +149,9 @@ module Homebrew
|
|||||||
ENV.append_path "PATH", homebrew_path
|
ENV.append_path "PATH", homebrew_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# For commands which aren't either absolute or relative
|
||||||
|
raise "command was not found in your PATH: #{command}" if command.exclude?("/") && which(command).nil?
|
||||||
|
|
||||||
if subcommand == "env"
|
if subcommand == "env"
|
||||||
ENV.each do |key, value|
|
ENV.each do |key, value|
|
||||||
puts "export #{key}=\"#{value}\""
|
puts "export #{key}=\"#{value}\""
|
||||||
|
|||||||
@ -77,7 +77,7 @@ RSpec.describe Homebrew::Bundle::Commands::Exec do
|
|||||||
|
|
||||||
it "prepends the path of the requested command to PATH before running" do
|
it "prepends the path of the requested command to PATH before running" do
|
||||||
expect(described_class).to receive(:exec).with("bundle", "install").and_return(nil)
|
expect(described_class).to receive(:exec).with("bundle", "install").and_return(nil)
|
||||||
expect(described_class).to receive(:which).and_return(Pathname("/usr/local/bin/bundle"))
|
expect(described_class).to receive(:which).twice.and_return(Pathname("/usr/local/bin/bundle"))
|
||||||
allow(ENV).to receive(:prepend_path).with(any_args).and_call_original
|
allow(ENV).to receive(:prepend_path).with(any_args).and_call_original
|
||||||
expect(ENV).to receive(:prepend_path).with("PATH", "/usr/local/bin").once.and_call_original
|
expect(ENV).to receive(:prepend_path).with("PATH", "/usr/local/bin").once.and_call_original
|
||||||
described_class.run("bundle", "install")
|
described_class.run("bundle", "install")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user