From 608c2bf79a7bc172b9d1046ede7d8ef7b46be411 Mon Sep 17 00:00:00 2001 From: Nicolas Cavigneaux Date: Tue, 28 Oct 2008 14:42:24 +0100 Subject: [PATCH] Added Hg (Mercurial) support in script/plugin --- railties/lib/commands/plugin.rb | 34 +++++++++++++++++++++++++++++++++- 1 files changed, 33 insertions(+), 1 deletions(-) diff --git a/railties/lib/commands/plugin.rb b/railties/lib/commands/plugin.rb index 9ff4739..046f177 100644 --- a/railties/lib/commands/plugin.rb +++ b/railties/lib/commands/plugin.rb @@ -176,6 +176,16 @@ class Plugin @uri =~ /^git:\/\// || @uri =~ /\.git$/ end + def hg_url? + # Check if hg is installed + if system('hg version') + # Test integrity of remote repo + ret = system("hg id -r 000000 #{@uri}") + return ret + end + false + end + def installed? File.directory?("#{rails_env.root}/vendor/plugins/#{name}") \ or rails_env.externals.detect{ |name, repo| self.uri == repo } @@ -186,6 +196,7 @@ class Plugin if :http == method method = :export if svn_url? method = :git if git_url? + method = :hg if hg_url? end uninstall if installed? and options[:force] @@ -285,6 +296,27 @@ class Plugin end end end + + def install_using_hg(options = {}) + root = rails_env.root + install_path = mkdir_p "#{root}/vendor/plugins/#{name}" + Dir.chdir install_path do + init_cmd = "hg init" + init_cmd += " -q" if options[:quiet] and not $verbose + puts init_cmd if $verbose + system(init_cmd) + base_cmd = "hg pull #{uri}" + base_cmd += " -q" if options[:quiet] and not $verbose + base_cmd += " -r #{options[:revision]}" if options[:revision] + puts base_cmd if $verbose + if system(base_cmd) + puts "removing: .hg" if $verbose + rm_rf ".hg" + else + rm_rf install_path + end + end + end def svn_command(cmd, options = {}) root = rails_env.root @@ -964,4 +996,4 @@ class RecursiveHTTPFetcher end end -Commands::Plugin.parse! +Commands::Plugin.parse! \ No newline at end of file -- 1.6.0.1