Skip to content

Commit 5f43a1a

Browse files
bcg00dingjcouball
authored andcommitted
fix: open3 errors on binary paths with spaces
1 parent 60b58ba commit 5f43a1a

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

lib/git/base.rb

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,15 @@ def self.config
3737
end
3838

3939
def self.binary_version(binary_path)
40-
git_cmd = "#{binary_path} -c core.quotePath=true -c color.ui=false version 2>&1"
41-
result, status = Open3.capture2(git_cmd)
42-
result = result.chomp
40+
result = nil
41+
status = nil
42+
43+
begin
44+
result, status = Open3.capture2e(binary_path, "-c", "core.quotePath=true", "-c", "color.ui=false", "version")
45+
result = result.chomp
46+
rescue Errno::ENOENT
47+
raise RuntimeError, "Failed to get git version: #{binary_path} not found"
48+
end
4349

4450
if status.success?
4551
version = result[/\d+(\.\d+)+/]
@@ -81,9 +87,12 @@ def self.root_of_worktree(working_dir)
8187
result = working_dir
8288
status = nil
8389

84-
git_cmd = "#{Git::Base.config.binary_path} -c core.quotePath=true -c color.ui=false rev-parse --show-toplevel 2>&1"
85-
result, status = Open3.capture2(git_cmd, chdir: File.expand_path(working_dir))
86-
result = result.chomp
90+
begin
91+
result, status = Open3.capture2e(Git::Base.config.binary_path, "-c", "core.quotePath=true", "-c", "color.ui=false", "rev-parse", "--show-toplevel", chdir: File.expand_path(working_dir))
92+
result = result.chomp
93+
rescue Errno::ENOENT
94+
raise ArgumentError, "Failed to find the root of the worktree: git binary not found"
95+
end
8796

8897
raise ArgumentError, "'#{working_dir}' is not in a git working tree" unless status.success?
8998
result

0 commit comments

Comments
 (0)