Class: Piston::Commands::Import
- Inherits:
-
Base
- Object
- Base
- Piston::Commands::Import
show all
- Defined in:
- lib/piston/commands/import.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from Base
#force, #guess_wc, #initialize, logger, #logger, #quiet, #verbose, #working_copy!
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
6
7
8
|
# File 'lib/piston/commands/import.rb', line 6
def options
@options
end
|
Instance Method Details
#repository_type ⇒ Object
8
9
10
|
# File 'lib/piston/commands/import.rb', line 8
def repository_type
options[:repository_type]
end
|
#run(repository_url, target_revision, wcdir) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/piston/commands/import.rb', line 24
def run(repository_url, target_revision, wcdir)
repository = select_repository(repository_url)
revision = repository.at(target_revision)
wcdir = File.expand_path(wcdir.nil? ? repository.basename : wcdir)
logger.info {"Guessing the working copy type"}
logger.debug {"repository_url: #{repository_url.inspect}, target_revision: #{target_revision.inspect}, wcdir: #{wcdir.inspect}"}
working_copy = guess_wc(wcdir)
if working_copy.exist? && !force then
logger.fatal "Path #{working_copy} already exists and --force not given. Aborting..."
abort
end
working_copy.import(revision, options[:lock])
logger.info {"Imported #{revision} from #{repository}"}
end
|
#select_repository(repository_url) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/piston/commands/import.rb', line 12
def select_repository(repository_url)
if repository_type then
logger.info {"Forced repository type to #{repository_type}"}
repository_class_name = "Piston::#{repository_type.to_s.downcase.capitalize}::Repository"
repository_class = repository_class_name.constantize
repository_class.new(repository_url)
else
logger.info {"Guessing the repository type"}
Piston::Repository.guess(repository_url)
end
end
|
#start(*args) ⇒ Object
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
# File 'lib/piston/commands/import.rb', line 42
def start(*args)
repository_url = args.shift
wcdir = args.shift
raise ArgumentError, "Required REPOSITORY argument missing" if repository_url.blank?
begin
self.run(repository_url, options[:revision] || options[:commit] || :head, wcdir)
rescue Piston::Repository::UnhandledUrl => e
supported_types = Piston::Repository.handlers.collect do |handler|
handler.repository_type
end
puts "Unsure how to handle:"
puts "\t#{repository_url.inspect}."
puts "You should try using --repository-type. Supported types are:"
supported_types.each do |type|
puts "\t#{type}"
end
exit 1
end
end
|