Skip to content

Commit 2aca293

Browse files
Moved logic to determine if git command meets required version down into Git::Lib, so other libraries can make use of it.
1 parent cfad767 commit 2aca293

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

lib/git.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,9 @@
2626
require 'git/stashes'
2727
require 'git/stash'
2828

29-
minimum_version = [1, 6, 0, 0]
30-
current_version = Git::Lib.new(nil, nil).command_version
31-
if current_version[0] < minimum_version[0] ||
32-
current_version[1] < minimum_version[1] ||
33-
current_version[2] < minimum_version[2] ||
34-
current_version[3] < minimum_version[3]
35-
$stderr.puts "The git gem requires git #{minimum_version.join('.')} or later, but only found #{current_version.join('.')}. You should probably upgrad.e"
29+
lib = Git::Lib.new(nil, nil)
30+
unless lib.meets_required_version?
31+
$stderr.puts "[WARNING] The git gem requires git #{lib.required_command_version.join('.')} or later, but only found #{lib.current_command_version.join('.')}. You should probably upgrade."
3632
end
3733

3834
# Git/Ruby Library

lib/git/lib.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,12 +645,26 @@ def archive(sha, file = nil, opts = {})
645645
end
646646

647647
# returns the current version of git, as an Array of Fixnums.
648-
def command_version
648+
def current_command_version
649649
output = command('version', [], false)
650650
version = output[/(\d+)\.(\d+)\.(\d+)\.(\d+)/]
651651
version.split('.').collect {|i| i.to_i}
652652
end
653653

654+
def required_command_version
655+
[1, 6, 0, 0]
656+
end
657+
658+
def meets_required_version?
659+
current_version = self.current_command_version
660+
required_version = self.required_command_version
661+
return current_version[0] >= required_version[0] &&
662+
current_version[1] >= required_version[1] &&
663+
current_version[2] >= required_version[2] &&
664+
current_version[3] >= required_version[3]
665+
end
666+
667+
654668
private
655669

656670
def command_lines(cmd, opts = [], chdir = true, redirect = '')

0 commit comments

Comments
 (0)