diff --git a/lib/updater/git_updater.rb b/lib/updater/git_updater.rb index 4d907070..840746db 100644 --- a/lib/updater/git_updater.rb +++ b/lib/updater/git_updater.rb @@ -21,20 +21,24 @@ require File.expand_path(File.dirname(__FILE__) + '/updater') class GitUpdater < Updater 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 + # 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 - # 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 def update - %x[git "#{repo_directory_arguments()}" pull] + puts %x[git #{repo_directory_arguments()} pull] end protected 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 diff --git a/spec/lib/updater/git_updater_spec.rb b/spec/lib/updater/git_updater_spec.rb index 52a7a033..3a741d9d 100644 --- a/spec/lib/updater/git_updater_spec.rb +++ b/spec/lib/updater/git_updater_spec.rb @@ -2,4 +2,46 @@ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper') 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 + 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 diff --git a/spec/lib/updater/svn_updater_spec.rb b/spec/lib/updater/svn_updater_spec.rb index 142a60f4..b158ac92 100644 --- a/spec/lib/updater/svn_updater_spec.rb +++ b/spec/lib/updater/svn_updater_spec.rb @@ -72,6 +72,9 @@ describe SvnUpdater do ' @expected = "362" end + end + + describe "#update" do end