Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added support for installing plugins hosted at git repositories (closes
#11294) [danger]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9049 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
dhh committed Mar 17, 2008
1 parent 54ccdd3 commit d07d6e9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 2 additions & 0 deletions railties/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Added support for installing plugins hosted at git repositories #11294 [danger]

* Fixed that script/generate would not look for plugin generators in plugin_paths #11000 [glv]

* Fix database rake tasks to work with charset/collation and show proper error messages on failure. Closes #11301 [matt]
Expand Down
26 changes: 25 additions & 1 deletion railties/lib/commands/plugin.rb
Expand Up @@ -162,14 +162,21 @@ def svn_url?
@uri =~ /svn(?:\+ssh)?:\/\/*/
end

def git_url?
@uri =~ /^git:\/\// || @url =~ /\.git$/
end

def installed?
File.directory?("#{rails_env.root}/vendor/plugins/#{name}") \
or rails_env.externals.detect{ |name, repo| self.uri == repo }
end

def install(method=nil, options = {})
method ||= rails_env.best_install_method?
method = :export if method == :http and svn_url?
if :http == method
method = :export if svn_url?
method = :clone if git_url?
end

uninstall if installed? and options[:force]

Expand Down Expand Up @@ -247,6 +254,10 @@ def install_using_http(options = {})
fetcher.fetch
end
end

def install_using_clone(options = {})
git_command :clone, options
end

def svn_command(cmd, options = {})
root = rails_env.root
Expand All @@ -257,12 +268,23 @@ def svn_command(cmd, options = {})
puts base_cmd if $verbose
system(base_cmd)
end

def git_command(cmd, options = {})
root = rails_env.root
mkdir_p "#{root}/vendor/plugins"
base_cmd = "git #{cmd} --depth 1 #{uri} \"#{root}/vendor/plugins/#{name}\""
puts base_cmd if $verbose
puts "removing: #{root}/vendor/plugins/#{name}/.git"
system(base_cmd)
rm_rf "#{root}/vendor/plugins/#{name}/.git"
end

def guess_name(url)
@name = File.basename(url)
if @name == 'trunk' || @name.empty?
@name = File.basename(File.dirname(url))
end
@name.gsub!(/\.git$/, '') if @name =~ /\.git$/
end

def rails_env
Expand Down Expand Up @@ -447,6 +469,8 @@ def options
o.separator " #{@script_name} install continuous_builder\n"
o.separator " Install a plugin from a subversion URL:"
o.separator " #{@script_name} install http://dev.rubyonrails.com/svn/rails/plugins/continuous_builder\n"
o.separator " Install a plugin from a git URL:"
o.separator " #{@script_name} install git://github.com/SomeGuy/my_awesome_plugin.git\n"
o.separator " Install a plugin and add a svn:externals entry to vendor/plugins"
o.separator " #{@script_name} install -x continuous_builder\n"
o.separator " List all available plugins:"
Expand Down

0 comments on commit d07d6e9

Please sign in to comment.