Tightened up git checking to check for a minimum installed version of

Git.
This commit is contained in:
Jeremy Cook
2014-11-23 14:32:47 -05:00
parent b7e2b45e69
commit a808f56caf
4 changed files with 25 additions and 4 deletions

View File

@@ -8,6 +8,7 @@ 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'

View File

@@ -3,6 +3,12 @@ module Homesick
module Actions module Actions
# 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
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 # TODO: move this to be more like thor's template, empty_directory, etc
def git_clone(repo, config = {}) def git_clone(repo, config = {})
config ||= {} config ||= {}

View File

@@ -20,8 +20,8 @@ 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`.size > 0 unless `git --version` =~ GIT_VERSION_PATTERN
say_status :error, 'Git 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
# Hack in support for diffing symlinks # Hack in support for diffing symlinks

View File

@@ -24,6 +24,19 @@ describe Homesick::CLI do
end end
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 context 'when git is not installed' do
before do before do
# The following line suppresses Thor warnings about overriding methods. # 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('') expect_any_instance_of(Homesick::CLI).to receive(:`).and_return('')
end end
it 'should raise an exception when Git is not installed' do 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 end
end end
@@ -695,7 +709,7 @@ describe Homesick::CLI do
describe 'version' do describe 'version' do
it 'prints the current version of homesick' do it 'prints the current version of homesick' do
text = Capture.stdout { homesick.version } 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
end end