From e74fd7f198f111c021a62224f61746a6ed693105 Mon Sep 17 00:00:00 2001 From: Michal Bugno Date: Sun, 12 Dec 2010 12:54:45 +0100 Subject: [PATCH] Clone support for git < 1.6.5 --- extras/big_tuna/vcs/git.rb | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/extras/big_tuna/vcs/git.rb b/extras/big_tuna/vcs/git.rb index a46023d..ac996c6 100644 --- a/extras/big_tuna/vcs/git.rb +++ b/extras/big_tuna/vcs/git.rb @@ -13,6 +13,22 @@ def self.supported? @_supported end + def self.version_at_least?(version) + if @_version.nil? + output = BigTuna::Runner.execute(Dir.pwd, "git --version").stdout.first + @_version = output.match(/\d+\.\d+\.\d+/)[0].split(".").map { |e| e.to_i } + end + parts = version.split(".").map { |e| e.to_i } + parts.each_with_index do |part, index| + if part > @_version[index] + return false + elsif part < @_version[index] + return true + end + end + return true + end + def head_info info = {} command = "git log --max-count=1 --format=\"%H%n%an%n%ae%n%ad%n%s\" #{self.branch}" @@ -31,7 +47,11 @@ def head_info end def clone(where_to) - command = "git clone --branch #{self.branch} --depth 1 #{self.source} #{where_to}" + if self.class.version_at_least?("1.6.5") + command = "git clone --branch #{self.branch} --depth 1 #{self.source} #{where_to}" + else + command = "mkdir -p #{where_to} && cd #{where_to} && git init && git pull #{self.source} #{self.branch} && git branch -M master #{self.branch}" + end BigTuna::Runner.execute(Dir.pwd, command) end end