Merge pull request #127 from JCook21/CheckGit
In lieu of other comments I'm going to go ahead and merge this.
This commit is contained in:
@@ -3,6 +3,25 @@ module Homesick
|
||||
module Actions
|
||||
# Git-related helper methods for Homesick
|
||||
module GitActions
|
||||
# Information on the minimum git version required for Homesick
|
||||
MIN_VERSION = {
|
||||
major: 1,
|
||||
minor: 8,
|
||||
patch: 0
|
||||
}
|
||||
STRING = MIN_VERSION.values.join('.')
|
||||
|
||||
def git_version_correct?
|
||||
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
|
||||
def git_clone(repo, config = {})
|
||||
config ||= {}
|
||||
|
||||
@@ -19,8 +19,13 @@ module Homesick
|
||||
|
||||
def initialize(args = [], options = {}, config = {})
|
||||
super
|
||||
self.shell = Thor::Shell::Color.new
|
||||
# Check if git is installed
|
||||
unless git_version_correct?
|
||||
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
|
||||
self.shell = Thor::Shell::Color.new
|
||||
class << shell
|
||||
def show_diff(destination, content)
|
||||
destination = Pathname.new(destination)
|
||||
|
||||
@@ -13,7 +13,7 @@ describe Homesick::CLI do
|
||||
|
||||
before { allow(homesick).to receive(:repos_dir).and_return(castles) }
|
||||
|
||||
describe 'smoke test' do
|
||||
describe 'smoke tests' do
|
||||
context 'when running bin/homesick' do
|
||||
before do
|
||||
bin_path = Pathname.new(__FILE__).parent.parent
|
||||
@@ -23,6 +23,26 @@ describe Homesick::CLI do
|
||||
expect(@output.length).to be > 0
|
||||
end
|
||||
end
|
||||
|
||||
context 'when git is not installed' do
|
||||
before do
|
||||
expect_any_instance_of(Homesick::Actions::GitActions).to receive(:`).and_return("git version 1.0.0")
|
||||
end
|
||||
it 'should raise an exception when' do
|
||||
output = Capture.stdout{ expect{Homesick::CLI.new}.to raise_error SystemExit }
|
||||
expect(output.chomp).to include(Homesick::Actions::GitActions::STRING)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when git is installed' do
|
||||
before do
|
||||
expect_any_instance_of(Homesick::Actions::GitActions).to receive(:`).at_least(:once).and_return("git version #{Homesick::Actions::GitActions::STRING}")
|
||||
end
|
||||
it 'should not raise an exception' do
|
||||
output = Capture.stdout{ expect{Homesick::CLI.new}.not_to raise_error }
|
||||
expect(output.chomp).not_to include(Homesick::Actions::GitActions::STRING)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'clone' do
|
||||
@@ -684,7 +704,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