Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
Merge remote branch 'technicalpickles/repository_type' into tech/repo…
Browse files Browse the repository at this point in the history
…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 ea958dd
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 7 deletions.
25 changes: 23 additions & 2 deletions lib/piston/cli.rb
Expand Up @@ -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
Expand All @@ -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

Expand Down
31 changes: 29 additions & 2 deletions lib/piston/commands/import.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions lib/piston/git/repository.rb
Expand Up @@ -27,6 +27,10 @@ def client
def git(*args)
client.git(*args)
end

def repository_type
'git'
end
end

def git(*args)
Expand Down
6 changes: 3 additions & 3 deletions lib/piston/repository.rb
Expand Up @@ -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

Expand All @@ -29,7 +30,6 @@ def add_handler(handler)
def handlers
@@handlers
end
private :handlers
end

attr_reader :url
Expand Down
4 changes: 4 additions & 0 deletions lib/piston/svn/repository.rb
Expand Up @@ -29,6 +29,10 @@ def client
def svn(*args)
client.svn(*args)
end

def repository_type
'svn'
end
end

def svn(*args)
Expand Down

0 comments on commit ea958dd

Please sign in to comment.