Added tests for a minimumGit version of 1.8.0.
This commit is contained in:
@@ -8,7 +8,6 @@ require 'homesick/cli'
|
|||||||
# Homesick's top-level module
|
# Homesick's top-level module
|
||||||
module Homesick
|
module Homesick
|
||||||
GITHUB_NAME_REPO_PATTERN = /\A([A-Za-z0-9_-]+\/[A-Za-z0-9_-]+)\Z/
|
GITHUB_NAME_REPO_PATTERN = /\A([A-Za-z0-9_-]+\/[A-Za-z0-9_-]+)\Z/
|
||||||
GIT_VERSION_PATTERN = /[#{Homesick::Actions::GitActions::MAJOR}-9]\.[#{Homesick::Actions::GitActions::MINOR}-9]\.[#{Homesick::Actions::GitActions::PATCH}-9]/
|
|
||||||
SUBDIR_FILENAME = '.homesick_subdir'
|
SUBDIR_FILENAME = '.homesick_subdir'
|
||||||
|
|
||||||
DEFAULT_CASTLE_NAME = 'dotfiles'
|
DEFAULT_CASTLE_NAME = 'dotfiles'
|
||||||
|
|||||||
@@ -4,10 +4,23 @@ module Homesick
|
|||||||
# Git-related helper methods for Homesick
|
# Git-related helper methods for Homesick
|
||||||
module GitActions
|
module GitActions
|
||||||
# Information on the minimum git version required for Homesick
|
# Information on the minimum git version required for Homesick
|
||||||
MAJOR = 2
|
MIN_VERSION = {
|
||||||
MINOR = 0
|
major: 1,
|
||||||
PATCH = 0
|
minor: 8,
|
||||||
STRING = [MAJOR, MINOR, PATCH].compact.join('.')
|
patch: 0
|
||||||
|
}
|
||||||
|
STRING = MIN_VERSION.values.join('.')
|
||||||
|
|
||||||
|
def version_check
|
||||||
|
info = `git --version`.scan(/(\d+)\.(\d+)\.(\d+)/).flatten.map(&:to_i)
|
||||||
|
return false unless info.count == 3
|
||||||
|
current_version = Hash[ [:major, :minor, :patch].zip(info) ]
|
||||||
|
return true if current_version.eql?(MIN_VERSION)
|
||||||
|
current_version.each do |k,v|
|
||||||
|
return true if v > MIN_VERSION[k]
|
||||||
|
end
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
# TODO: move this to be more like thor's template, empty_directory, etc
|
# TODO: move this to be more like thor's template, empty_directory, etc
|
||||||
def git_clone(repo, config = {})
|
def git_clone(repo, config = {})
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ module Homesick
|
|||||||
def initialize(args = [], options = {}, config = {})
|
def initialize(args = [], options = {}, config = {})
|
||||||
super
|
super
|
||||||
# Check if git is installed
|
# Check if git is installed
|
||||||
unless `git --version` =~ GIT_VERSION_PATTERN
|
unless version_check
|
||||||
say_status :error, "Git version >= #{Homesick::Actions::GitActions::STRING} must be installed to use Homesick", :red
|
say_status :error, "Git version >= #{Homesick::Actions::GitActions::STRING} must be installed to use Homesick", :red
|
||||||
exit(1)
|
exit(1)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -28,11 +28,11 @@ describe Homesick::CLI do
|
|||||||
before do
|
before do
|
||||||
# The following line suppresses Thor warnings about overriding methods.
|
# The following line suppresses Thor warnings about overriding methods.
|
||||||
allow($stdout).to receive(:write).at_least(:once)
|
allow($stdout).to receive(:write).at_least(:once)
|
||||||
expect_any_instance_of(Homesick::CLI).to receive(:`).and_return(Homesick::Actions::GitActions::STRING)
|
expect_any_instance_of(Homesick::Actions::GitActions).to receive(:`).and_return("git version #{Homesick::Actions::GitActions::STRING}")
|
||||||
end
|
end
|
||||||
it 'should not raise an exception when Git is installed' do
|
it 'should not raise an exception' do
|
||||||
output = Capture.stdout{ expect{Homesick::CLI.new}.not_to raise_error }
|
output = Capture.stdout{ expect{Homesick::CLI.new}.not_to raise_error }
|
||||||
expect(output.chomp).not_to match(/#{Regexp.escape(Homesick::Actions::GitActions::STRING)}/)
|
expect(output.chomp).not_to include(Homesick::Actions::GitActions::STRING)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
@@ -41,11 +41,11 @@ describe Homesick::CLI do
|
|||||||
before do
|
before do
|
||||||
# The following line suppresses Thor warnings about overriding methods.
|
# The following line suppresses Thor warnings about overriding methods.
|
||||||
allow($stdout).to receive(:write).at_least(:once)
|
allow($stdout).to receive(:write).at_least(:once)
|
||||||
expect_any_instance_of(Homesick::CLI).to receive(:`).and_return('')
|
expect_any_instance_of(Homesick::Actions::GitActions).to receive(:`).and_return("git version 1.0.0")
|
||||||
end
|
end
|
||||||
it 'should raise an exception when Git is not installed' do
|
it 'should raise an exception when' do
|
||||||
output = Capture.stdout{ expect{Homesick::CLI.new}.to raise_error SystemExit }
|
output = Capture.stdout{ expect{Homesick::CLI.new}.to raise_error SystemExit }
|
||||||
expect(output.chomp).to match(/#{Regexp.escape(Homesick::Actions::GitActions::STRING)}/)
|
expect(output.chomp).to include(Homesick::Actions::GitActions::STRING)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user