[Command] Raise when using git < 1.8.5

parent 2d4d97be
...@@ -37,6 +37,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre` ...@@ -37,6 +37,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
* Fixed code signing issue causing lint failure on macOS. * Fixed code signing issue causing lint failure on macOS.
[Paul Cantrell](https://github.com/pcantrell) [Paul Cantrell](https://github.com/pcantrell)
[#5645](https://github.com/CocoaPods/CocoaPods/issues/5645) [#5645](https://github.com/CocoaPods/CocoaPods/issues/5645)
* Raise an exception when using a git version prior to 1.8.5.
[Danielle Tomlinson](https://github.com/dantoml)
[#6078](https://github.com/CocoaPods/CocoaPods/issues/6078)
## 1.2.0.beta.1 (2016-10-28) ## 1.2.0.beta.1 (2016-10-28)
......
...@@ -45,6 +45,8 @@ module Pod ...@@ -45,6 +45,8 @@ module Pod
def self.run(argv) def self.run(argv)
help! 'You cannot run CocoaPods as root.' if Process.uid == 0 help! 'You cannot run CocoaPods as root.' if Process.uid == 0
verify_minimum_git_version!
verify_xcode_license_approved! verify_xcode_license_approved!
super(argv) super(argv)
...@@ -105,6 +107,28 @@ module Pod ...@@ -105,6 +107,28 @@ module Pod
private private
# Returns a new {Gem::Version} based on the systems `git` version.
#
# @return [Gem::Version]
#
def self.git_version
raw_version = Executable.capture_command('git', ['--version']).first
match = raw_version.scan(/\d+\.\d+\.\d+/).first
Gem::Version.new(match)
end
# Checks that the git version is at least 1.8.5
#
# @raise If the git version is older than 1.8.5
#
# @return [void]
#
def self.verify_minimum_git_version!
if git_version < Gem::Version.new('1.8.5')
raise Informative, 'You need at least git version 1.8.5 to use CocoaPods'
end
end
# Returns a new {Installer} parametrized from the {Config}. # Returns a new {Installer} parametrized from the {Config}.
# #
# @return [Installer] # @return [Installer]
......
...@@ -19,5 +19,50 @@ module Pod ...@@ -19,5 +19,50 @@ module Pod
Command.parse(%w(init )).should.be.instance_of Command::Init Command.parse(%w(init )).should.be.instance_of Command::Init
Command.parse(%w(env )).should.be.instance_of Command::Env Command.parse(%w(env )).should.be.instance_of Command::Env
end end
describe 'git version validation' do
valid_git_versions = [
Gem::Version.new('1.8.5'),
Gem::Version.new('2.10.2'),
Gem::Version.new('2.8.4'),
]
invalid_git_versions = [
Gem::Version.new('1.7.4'),
Gem::Version.new('0.2.9'),
]
valid_git_versions.each do |version|
it "does not raise an error for version #{version}" do
Command.expects(:git_version).returns(version)
lambda { Command.verify_minimum_git_version! }.should.not.raise
end
end
invalid_git_versions.each do |version|
it "raises an error for version #{version}" do
Command.expects(:git_version).returns(version)
lambda { Command.verify_minimum_git_version! }.should.raise Informative
end
end
end
describe 'git version extraction' do
git_versions = [
['git version 1.2.4', Gem::Version.new('1.2.4')],
['git version 1.4.5', Gem::Version.new('1.4.5')],
['git version 1.7.4', Gem::Version.new('1.7.4')],
['git version 2.10.2', Gem::Version.new('2.10.2')],
['git version 2.10.2', Gem::Version.new('2.10.2')],
['git version 2.8.4 (Apple Git-73)', Gem::Version.new('2.8.4')],
]
git_versions.each do |pair|
it "returns the correct version for #{pair[0]}" do
Executable.expects(:capture_command).with('git', ['--version']).returns([pair[0]])
Command.git_version.should == pair[1]
end
end
end
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment