Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11294: git_support_for_railties_plugin_install.diff

File git_support_for_railties_plugin_install.diff, 1.7 kB (added by danger, 6 months ago)

Using "--depth 1" to get a shallow checkout of the git repo

  • railties/lib/commands/plugin.rb

    old new  
    162162    @uri =~ /svn(?:\+ssh)?:\/\/*/ 
    163163  end 
    164164   
     165  def git_url? 
     166    @uri =~ /^git:\/\// || @url =~ /\.git$/ 
     167  end 
     168   
    165169  def installed? 
    166170    File.directory?("#{rails_env.root}/vendor/plugins/#{name}") \ 
    167171      or rails_env.externals.detect{ |name, repo| self.uri == repo } 
     
    169173   
    170174  def install(method=nil, options = {}) 
    171175    method ||= rails_env.best_install_method? 
    172     method   = :export if method == :http and svn_url? 
     176    if :http == method 
     177      method = :export if svn_url? 
     178      method = :clone  if git_url? 
     179    end 
    173180 
    174181    uninstall if installed? and options[:force] 
    175182 
     
    247254        fetcher.fetch 
    248255      end 
    249256    end 
     257     
     258    def install_using_clone(options = {}) 
     259      git_command :clone, options 
     260    end 
    250261 
    251262    def svn_command(cmd, options = {}) 
    252263      root = rails_env.root 
     
    257268      puts base_cmd if $verbose 
    258269      system(base_cmd) 
    259270    end 
     271     
     272    def git_command(cmd, options = {}) 
     273      root = rails_env.root 
     274      mkdir_p "#{root}/vendor/plugins" 
     275      base_cmd = "git #{cmd} --depth 1 #{uri} \"#{root}/vendor/plugins/#{name}\"" 
     276      puts base_cmd if $verbose 
     277      puts "removing: #{root}/vendor/plugins/#{name}/.git" 
     278      system(base_cmd) 
     279      rm_rf "#{root}/vendor/plugins/#{name}/.git" 
     280    end 
    260281 
    261282    def guess_name(url) 
    262283      @name = File.basename(url) 
    263284      if @name == 'trunk' || @name.empty? 
    264285        @name = File.basename(File.dirname(url)) 
    265286      end 
     287      @name.gsub!(/\.git$/, '') if @name =~ /\.git$/ 
    266288    end 
    267289     
    268290    def rails_env