Method: Git::Base.binary_version

Defined in:
lib/git/base.rb

.binary_version(binary_path)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/git/base.rb', line 41

def self.binary_version(binary_path)
  result = nil
  status = nil

  begin
    result, status = Open3.capture2e(binary_path, "-c", "core.quotePath=true", "-c", "color.ui=false", "version")
    result = result.chomp
  rescue Errno::ENOENT
    raise RuntimeError, "Failed to get git version: #{binary_path} not found"
  end

  if status.success?
    version = result[/\d+(\.\d+)+/]
    version_parts = version.split('.').collect { |i| i.to_i }
    version_parts.fill(0, version_parts.length...3)
  else
    raise RuntimeError, "Failed to get git version: #{status}\n#{result}"
  end
end