From 0989400a925cd201defdca9eb28eb87200b30785 Mon Sep 17 00:00:00 2001 From: sodacris Date: Fri, 22 Nov 2024 19:58:38 +0800 Subject: [rubygems/rubygems] fix bundle which commands on windows https://github.com/rubygems/rubygems/commit/9e0018d9fe --- lib/bundler.rb | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/bundler.rb b/lib/bundler.rb index c1d7c46e4d..1140de5467 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -495,18 +495,27 @@ module Bundler end def which(executable) - if File.file?(executable) && File.executable?(executable) - executable - elsif paths = ENV["PATH"] + executable_path = find_executable(executable) + return executable_path if executable_path + + if (paths = ENV["PATH"]) quote = '"' paths.split(File::PATH_SEPARATOR).find do |path| path = path[1..-2] if path.start_with?(quote) && path.end_with?(quote) - executable_path = File.expand_path(executable, path) - return executable_path if File.file?(executable_path) && File.executable?(executable_path) + executable_path = find_executable(File.expand_path(executable, path)) + return executable_path if executable_path end end end + def find_executable(path) + extensions = RbConfig::CONFIG["EXECUTABLE_EXTS"]&.split + extensions = [RbConfig::CONFIG["EXEEXT"]] unless extensions&.any? + candidates = extensions.map {|ext| "#{path}#{ext}" } + + candidates.find {|candidate| File.file?(candidate) && File.executable?(candidate) } + end + def read_file(file) SharedHelpers.filesystem_access(file, :read) do File.open(file, "r:UTF-8", &:read) @@ -559,7 +568,7 @@ module Bundler def git_present? return @git_present if defined?(@git_present) - @git_present = Bundler.which("git#{RbConfig::CONFIG["EXEEXT"]}") + @git_present = Bundler.which("git") end def feature_flag -- cgit v1.2.3