Skip to content

Commit 0989400

Browse files
soda92matzbot
authored andcommitted
[rubygems/rubygems] fix bundle which commands on windows
rubygems/rubygems@9e0018d9fe
1 parent 80cfa57 commit 0989400

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

lib/bundler.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -495,18 +495,27 @@ def mkdir_p(path)
495495
end
496496

497497
def which(executable)
498-
if File.file?(executable) && File.executable?(executable)
499-
executable
500-
elsif paths = ENV["PATH"]
498+
executable_path = find_executable(executable)
499+
return executable_path if executable_path
500+
501+
if (paths = ENV["PATH"])
501502
quote = '"'
502503
paths.split(File::PATH_SEPARATOR).find do |path|
503504
path = path[1..-2] if path.start_with?(quote) && path.end_with?(quote)
504-
executable_path = File.expand_path(executable, path)
505-
return executable_path if File.file?(executable_path) && File.executable?(executable_path)
505+
executable_path = find_executable(File.expand_path(executable, path))
506+
return executable_path if executable_path
506507
end
507508
end
508509
end
509510

511+
def find_executable(path)
512+
extensions = RbConfig::CONFIG["EXECUTABLE_EXTS"]&.split
513+
extensions = [RbConfig::CONFIG["EXEEXT"]] unless extensions&.any?
514+
candidates = extensions.map {|ext| "#{path}#{ext}" }
515+
516+
candidates.find {|candidate| File.file?(candidate) && File.executable?(candidate) }
517+
end
518+
510519
def read_file(file)
511520
SharedHelpers.filesystem_access(file, :read) do
512521
File.open(file, "r:UTF-8", &:read)
@@ -559,7 +568,7 @@ def clear_gemspec_cache
559568

560569
def git_present?
561570
return @git_present if defined?(@git_present)
562-
@git_present = Bundler.which("git#{RbConfig::CONFIG["EXEEXT"]}")
571+
@git_present = Bundler.which("git")
563572
end
564573

565574
def feature_flag

spec/bundler/bundler/bundler_spec.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,13 @@
174174
end
175175
end
176176

177-
let(:expected) { "executable" }
177+
let(:expected) do
178+
if Gem.win_platform?
179+
"executable.exe"
180+
else
181+
"executable"
182+
end
183+
end
178184

179185
before do
180186
ENV["PATH"] = path.join(File::PATH_SEPARATOR)
@@ -200,7 +206,7 @@
200206
context "when the executable in inside a quoted path" do
201207
let(:expected) do
202208
if Gem.win_platform?
203-
"C:/e/executable"
209+
"C:/e/executable.exe"
204210
else
205211
"/e/executable"
206212
end

0 commit comments

Comments
 (0)