diff options
| author | sodacris <wjxa20152015@gmail.com> | 2024-11-22 19:58:38 +0800 |
|---|---|---|
| committer | git <svn-admin@ruby-lang.org> | 2024-11-22 13:36:21 +0000 |
| commit | 0989400a925cd201defdca9eb28eb87200b30785 (patch) | |
| tree | 53c3144856db822b4ae9eb25e7f073eb213cb55a /lib | |
| parent | 80cfa57234255667a86d46096093099349a7262a (diff) | |
[rubygems/rubygems] fix bundle which commands on windows
https://github.com/rubygems/rubygems/commit/9e0018d9fe
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/bundler.rb | 21 |
1 files changed, 15 insertions, 6 deletions
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 |
