def build_clone(options)
      to_env       = options[:environment]
      version      = options[:version]
      content_view = options[:content_view] || to_env.default_content_view
      to_version   = version || content_view.version(to_env)

      fail _("Cannot clone into the Default Content View") if content_view.default?

      if to_env && version
        fail "Cannot clone into both an environment and a content view version archive"
      end

      if to_version.nil?
        fail _("View %{view} has not been promoted to %{env}") %
                  {:view => content_view.name, :env => to_env.name}
      end

      if to_env && self.clones.in_content_views([content_view]).in_environment(to_env).any?
        fail _("Repository has already been cloned to %{cv_name} in environment %{to_env}") %
                  {:to_env => to_env, :cv_name => content_view.name}
      end

      if self.yum?
        if self.library_instance?
          checksum_type = root.checksum_type || pulp_scratchpad_checksum_type
        else
          checksum_type = self.saved_checksum_type
        end
      end
      clone = Repository.new(:environment => to_env,
                     :library_instance => self.library_instance || self,
                     :root => self.root,
                     :content_view_version => to_version,
                     :saved_checksum_type => checksum_type)

      clone.relative_path = clone.docker? ? clone.generate_docker_repo_path : clone.generate_repo_path
      clone
    end
def build_clone(options)
      to_env       = options[:environment]
      version      = options[:version]
      content_view = options[:content_view] || to_env.default_content_view
      to_version   = version || content_view.version(to_env)

      fail _("Cannot clone into the Default Content View") if content_view.default?

      if to_env && version
        fail "Cannot clone into both an environment and a content view version archive"
      end

      if to_version.nil?
        fail _("View %{view} has not been promoted to %{env}") %
                  {:view => content_view.name, :env => to_env.name}
      end

      if to_env && self.clones.in_content_views([content_view]).in_environment(to_env).any?
        fail _("Repository has already been cloned to %{cv_name} in environment %{to_env}") %
                  {:to_env => to_env, :cv_name => content_view.name}
      end

      if self.yum?
        if self.library_instance?
          checksum_type = root.checksum_type || pulp_scratchpad_checksum_type
        else
          checksum_type = self.saved_checksum_type
        end
      end
      clone = Repository.new(:environment => to_env,
                     :library_instance => self.library_instance || self,
                     :root => self.root,
                     :content_view_version => to_version,
                     :saved_checksum_type => checksum_type)

      clone.relative_path = clone.docker? ? clone.generate_docker_repo_path : clone.generate_repo_path
      clone
    end
TODO: break up method