GitUpdater implemented
This commit is contained in:
@@ -21,20 +21,24 @@ require File.expand_path(File.dirname(__FILE__) + '/updater')
|
|||||||
class GitUpdater < Updater
|
class GitUpdater < Updater
|
||||||
|
|
||||||
def is_installed?
|
def is_installed?
|
||||||
%x[git status "#{repo_directory_arguments()}" 2>&1] =~ /On branch/ ? true : false
|
%x[git #{repo_directory_arguments()} status 2>&1] =~ /On branch/ ? true : false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Git has not a revsion number like SVN, so we will take the 7 first chars of the last commit hash
|
||||||
def local_revision_number
|
def local_revision_number
|
||||||
# TODO - not sure if git has revision numbers? maybe we don't have to check and just do a pull?
|
git_log = %x[git #{repo_directory_arguments()} log -1 2>&1]
|
||||||
|
git_log[/commit ([0-9a-z]{7})/i, 1].to_s
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
%x[git "#{repo_directory_arguments()}" pull]
|
puts %x[git #{repo_directory_arguments()} pull]
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
def repo_directory_arguments
|
def repo_directory_arguments
|
||||||
'--git-dir="#{@repo_directory}.git" --work-tree="#{@repo_directory}"'
|
if @repo_directory
|
||||||
|
return "--git-dir=\"#{@repo_directory}/.git\" --work-tree=\"#{@repo_directory}\""
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,4 +2,46 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
|||||||
|
|
||||||
describe GitUpdater do
|
describe GitUpdater do
|
||||||
|
|
||||||
|
before :each do
|
||||||
|
@git_updater = GitUpdater.new
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#is_installed?" do
|
||||||
|
after :each do
|
||||||
|
stub_system_command(@git_updater, /^git .* status/, @stub_value)
|
||||||
|
@git_updater.is_installed?.should === @expected
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return false if the command is not found" do
|
||||||
|
@stub_value = "git: command not found"
|
||||||
|
@expected = false
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return true if the repo is a git one" do
|
||||||
|
@stub_value = "# On branch master\n# Changed but not updated:"
|
||||||
|
@expected = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#local_revision_number" do
|
||||||
|
after :each do
|
||||||
|
stub_system_command(@git_updater, /^git .* log/, @stub_value)
|
||||||
|
@git_updater.local_revision_number.should === @expected
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return 79c01f3" do
|
||||||
|
@stub_value = "
|
||||||
|
commit 79c01f3ed535a8e33876ea091d8217cae7df4028
|
||||||
|
Author: Moi <tadimm>
|
||||||
|
Date: Wed Jul 11 23:22:16 2012 +0100"
|
||||||
|
@expected = "79c01f3"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#update" do
|
||||||
|
#it "should do nothing xD" do
|
||||||
|
#stub_system_command(@git_updater, /^git .* pull/, "Already up-to-date.")
|
||||||
|
#@git_updater.update
|
||||||
|
#end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -72,6 +72,9 @@ describe SvnUpdater do
|
|||||||
</info>'
|
</info>'
|
||||||
@expected = "362"
|
@expected = "362"
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#update" do
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user