Method: Externals::Ext#init

Defined in:
lib/externals/ext.rb

#init(args, options = {}) ⇒ Object



697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
# File 'lib/externals/ext.rb', line 697

def init args, options = {}
  raise ".externals already exists" if File.exist?('.externals')

  scm = options[:scm]
  type = options[:type]

  if !scm
    possible_project_classes = self.class.project_classes.select do |project_class|
      project_class.detected?
    end

    raise "Could not determine this project's scm" if  possible_project_classes.empty?
    if possible_project_classes.size > 1
      raise "This project appears to be managed by multiple SCMs: #{
      possible_project_classes.map(&:to_s).join(',')}
Please explicitly declare the SCM (using --git or --svn, or, by creating .externals manually"
    end

    scm = possible_project_classes.first.scm
  end

  if !type
    possible_project_types = self.class.project_types.select do |project_type|
      self.class.project_type_detector(project_type).detected?
    end

    if possible_project_types.size > 1
      raise "We found multiple project types that this could be: #{possible_project_types.join(',')}
Please use the --type option to tell ext which to use."
    elsif possible_project_types.size == 0
      puts "WARNING: We could not automatically determine the project type.
      Be sure to specify paths when adding subprojects to your .externals file"
    else
      type = possible_project_types.first
    end
  end

  config = Configuration::Configuration.new_empty
  raise ".externals already exists" if File.exist?('.externals')

  config.add_empty_section '.'

  # TODO: If we are using subversion, we should warn about not setting a branch
  if scm == "svn"
    if options[:branch]
      config['.'][:repository] = SvnProject.extract_repository(
        SvnProject.info_url,
        options[:branch]
      )
    elsif args[0]
      config['.'][:repository] = args[0].strip
    end
  end

  config['.'][:scm] = scm
  config['.'][:type] = type if type

  config.write '.externals'
  reload_configuration
end