Tightened up git checking to check for a minimum installed version of
Git.
This commit is contained in:
@@ -8,6 +8,7 @@ require 'homesick/cli'
|
||||
# Homesick's top-level module
|
||||
module Homesick
|
||||
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'
|
||||
|
||||
DEFAULT_CASTLE_NAME = 'dotfiles'
|
||||
|
||||
@@ -3,6 +3,12 @@ module Homesick
|
||||
module Actions
|
||||
# Git-related helper methods for Homesick
|
||||
module GitActions
|
||||
# Information on the minimum git version required for Homesick
|
||||
MAJOR = 2
|
||||
MINOR = 0
|
||||
PATCH = 0
|
||||
STRING = [MAJOR, MINOR, PATCH].compact.join('.')
|
||||
|
||||
# TODO: move this to be more like thor's template, empty_directory, etc
|
||||
def git_clone(repo, config = {})
|
||||
config ||= {}
|
||||
|
||||
@@ -20,8 +20,8 @@ module Homesick
|
||||
def initialize(args = [], options = {}, config = {})
|
||||
super
|
||||
# Check if git is installed
|
||||
unless `git --version`.size > 0
|
||||
say_status :error, 'Git must be installed to use Homesick', :red
|
||||
unless `git --version` =~ GIT_VERSION_PATTERN
|
||||
say_status :error, "Git version >= #{Homesick::Actions::GitActions::STRING} must be installed to use Homesick", :red
|
||||
exit(1)
|
||||
end
|
||||
# Hack in support for diffing symlinks
|
||||
|
||||
@@ -24,6 +24,19 @@ describe Homesick::CLI do
|
||||
end
|
||||
end
|
||||
|
||||
context 'when git is installed' do
|
||||
before do
|
||||
# The following line suppresses Thor warnings about overriding methods.
|
||||
allow($stdout).to receive(:write).at_least(:once)
|
||||
expect_any_instance_of(Homesick::CLI).to receive(:`).and_return(Homesick::Actions::GitActions::STRING)
|
||||
end
|
||||
it 'should not raise an exception when Git is installed' do
|
||||
output = Capture.stdout{ expect{Homesick::CLI.new}.not_to raise_error }
|
||||
expect(output.chomp).not_to match(/#{Regexp.escape(Homesick::Actions::GitActions::STRING)}/)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context 'when git is not installed' do
|
||||
before do
|
||||
# The following line suppresses Thor warnings about overriding methods.
|
||||
@@ -31,7 +44,8 @@ describe Homesick::CLI do
|
||||
expect_any_instance_of(Homesick::CLI).to receive(:`).and_return('')
|
||||
end
|
||||
it 'should raise an exception when Git is not installed' do
|
||||
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)}/)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -695,7 +709,7 @@ describe Homesick::CLI do
|
||||
describe 'version' do
|
||||
it 'prints the current version of homesick' do
|
||||
text = Capture.stdout { homesick.version }
|
||||
expect(text.chomp).to match(/\d+\.\d+\.\d+/)
|
||||
expect(text.chomp).to match(/#{Regexp.escape(Homesick::Version::STRING)}/)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user