class Drupid::DownloadStrategy::Git

Public Class Methods

new(url, dest, name, download_specs = {}) click to toggle source
Calls superclass method Drupid::DownloadStrategy::Base::new
    # File lib/drupid/download_strategy.rb
252 def initialize url, dest, name, download_specs = {}
253   super
254   @clone = @dest + @name
255 end

Public Instance Methods

fetch() click to toggle source
    # File lib/drupid/download_strategy.rb
265 def fetch
266   raise "You must install Git." unless which "git"
267 
268   blah "Cloning #{@url}"
269 
270   if @clone.exist?
271     Dir.chdir(@clone) do
272       # Check for interrupted clone from a previous install
273       unless system 'git', 'status', '-s'
274         blah "Removing invalid .git repo from cache"
275         FileUtils.rm_rf @clone
276       end
277     end
278   end
279 
280   unless @clone.exist?
281     clone_args = ['clone']
282     clone_args << '--depth' << '1' if support_depth?
283 
284     if @specs.has_key?('branch')
285       clone_args << '--branch' << @specs['branch']
286     elsif @specs.has_key?('tag')
287       clone_args << '--branch' << @specs['tag']
288     end
289 
290     clone_args << @url << @clone
291     git(*clone_args)
292   else
293     blah "Updating #{@clone}"
294     Dir.chdir(@clone) do
295       git 'config', 'remote.origin.url', @url
296 
297       rof =
298         if @specs.has_key?('branch')
299           "+refs/heads/#{@specs['branch']}:refs/remotes/origin/#{@specs['branch']}"
300         elsif @specs.has_key?('tag')
301           "+refs/tags/#{@specs['tag']}:refs/tags/#{@specs['tag']}"
302         else
303           '+refs/heads/master:refs/remotes/origin/master'
304         end
305       git 'config', 'remote.origin.fetch', rof
306 
307       git_args = %w[fetch origin]
308       git(*git_args)
309     end
310   end
311 end
host_supports_depth?() click to toggle source
    # File lib/drupid/download_strategy.rb
261 def host_supports_depth?
262   @url =~ %r(git://) or @url =~ %r(https://github.com/)
263 end
stage(wd = @dest) click to toggle source

Stages this download into the specified directory. Invokes fetch to retrieve the file if needed.

    # File lib/drupid/download_strategy.rb
315 def stage wd = @dest
316   fetch unless @clone.exist?
317   dont_debug { wd.mkpath }
318   debug "Staging into #{wd}"
319   target = wd + @clone.basename
320   Dir.chdir @clone do
321     if @specs.has_key?('branch')
322       git 'checkout', "origin/#{@specs['branch']}", '--'
323     elsif @specs.has_key?('tag')
324       git 'checkout', @specs['tag'], '--'
325     elsif @specs.has_key?('revision')
326       git 'checkout', @specs['revision'], '--'
327     else
328       # otherwise the checkout-index won't checkout HEAD
329       # https://github.com/mxcl/homebrew/issues/7124
330       # must specify origin/HEAD, otherwise it resets to the current local HEAD
331       git 'reset', '--hard', 'origin/HEAD'
332     end
333     # http://stackoverflow.com/questions/160608/how-to-do-a-git-export-like-svn-export
334     git 'checkout-index', '-a', '-f', "--prefix=#{target}/"
335     # check for submodules
336     if File.exist?('.gitmodules')
337       git 'submodule', 'init'
338       git 'submodule', 'update'
339       sub_cmd = "git checkout-index -a -f \"--prefix=#{target}/$path/\""
340       git 'submodule', '--quiet', 'foreach', '--recursive', sub_cmd
341     end
342   end
343   @staged_path = target
344 end
support_depth?() click to toggle source
    # File lib/drupid/download_strategy.rb
257 def support_depth?
258   !(@specs.has_key?('revision')) and host_supports_depth?
259 end