Class: Piston::Commands::Import

Inherits:
Base
  • Object
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!

Constructor Details

This class inherits a constructor from Piston::Commands::Base

Instance Attribute Details

#optionsObject (readonly)

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_typeObject



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
# 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])
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.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