Permalink
Browse files

Merge remote branch 'technicalpickles/repository_type' into tech/repo…

…type

* technicalpickles/repository_type:
  Added nice error message for when can't guess the type of a repository.
  Repositories know what 'type' of repository they handle, ie Piston::Svn::Repository handles 'git'. When don't know how to handle a repository, suggests to use --repository-type and gives valid types.
  Added support for specifying what type of repository you are trying to import.
  • Loading branch information...
francois committed Apr 21, 2008
2 parents 9cfa8f3 + ba77f51 commit ea958dd2711364eab793c135e07171c9603a23e3
Showing with 63 additions and 7 deletions.
  1. +23 −2 lib/piston/cli.rb
  2. +29 −2 lib/piston/commands/import.rb
  3. +4 −0 lib/piston/git/repository.rb
  4. +3 −3 lib/piston/repository.rb
  5. +4 −0 lib/piston/svn/repository.rb
View
@@ -65,6 +65,12 @@ def target_revision
default false
description "Automatically lock down the revision/commit to protect against blanket updates"
end
option("repository-type") do
argument :required
default nil
description "Force a specific repository type, for when it's not possible to guess"
end
logger_level Logger::DEBUG
def run
@@ -78,8 +84,23 @@ def run
:verbose => params["verbose"].value,
:quiet => params["quiet"].value,
:force => params["force"].value,
:dry_run => params["dry-run"].value)
cmd.run(params[:repository].value, self.target_revision, params[:directory].value)
:dry_run => params["dry-run"].value,
:repository_type => params["repository-type"].value)
begin
cmd.run(params[:repository].value, self.target_revision, params[:directory].value)
rescue Piston::Repository::UnhandledUrl => e
supported_types = Piston::Repository.handlers.collect do |handler|
handler.repository_type
end
puts "Unsure how to handle:"
puts "\t#{params[:repository].value.inspect}."
puts "You should try using --repository-type. Supported types are:"
supported_types.each do |type|
puts "\t#{type}"
end
exit_failure!
end
end
end
@@ -8,10 +8,26 @@ class Import < Piston::Commands::Base
def temp_dir_name(working_copy)
working_copy.path.parent + ".#{working_copy.path.basename}.tmp"
end
def repository_type
options[:repository_type]
end
def determine_repository(repository_url)
if repository_type
logger.info {"Forced repository type to #{repository_type}"}
repository_class_name = "Piston::#{repository_type.downcase.capitalize}::Repository"
repository_class = constantize(repository_class_name)
repository = repository_class.new(repository_url)
else
logger.info {"Guessing the repository type"}
repository = Piston::Repository.guess(repository_url)
end
repository
end
def run(repository_url, target_revision, wcdir)
logger.info {"Guessing the repository type"}
repository = Piston::Repository.guess(repository_url)
repository = determine_repository(repository_url)
revision = repository.at(target_revision)
wcdir = wcdir.nil? ? repository.basename : wcdir
@@ -49,6 +65,17 @@ def run(repository_url, target_revision, wcdir)
tmpdir.rmtree rescue nil
end
end
protected
# riped out of activesupport
def constantize(camel_cased_word)
unless /\A(?:::)?([A-Z]\w*(?:::[A-Z]\w*)*)\z/ =~ camel_cased_word
raise NameError, "#{camel_cased_word.inspect} is not a valid constant name!"
end
Object.module_eval("::#{$1}", __FILE__, __LINE__)
end
end
end
end
@@ -27,6 +27,10 @@ def client
def git(*args)
client.git(*args)
end
def repository_type
'git'
end
end
def git(*args)
View
@@ -16,8 +16,9 @@ def guess(url)
logger.debug {"Asking #{handler}"}
handler.understands_url?(url)
end
raise UnhandledUrl, "No internal handlers found for #{url.inspect}. Do you want to help ?" if handler.nil?
raise UnhandledUrl unless handler
handler.new(url)
end
@@ -29,7 +30,6 @@ def add_handler(handler)
def handlers
@@handlers
end
private :handlers
end
attr_reader :url
@@ -29,6 +29,10 @@ def client
def svn(*args)
client.svn(*args)
end
def repository_type
'svn'
end
end
def svn(*args)

0 comments on commit ea958dd

Please sign in to comment.