<commit_before>module Seed
  class Core
    @source_files = {}

    def self.install
      seeds = read_seedfile.split('\r\n')
      seeds.each { |line| eval line }
      self.configure_project
    end

    def self.read_seedfile
      begin
        File.read('Seedfile')
      rescue
        puts 'No Seedfile.'
        exit 1
      end
    end

    def self.github(repo, tag, options=nil)
      url = "https://github.com/#{repo}"
      name = repo.split('/')[1]
      dir = "Seeds/#{name}"

      if File.exist?(dir)
        current_tag = `cd #{dir} && git describe --tags --abbrev=0 2>&1`
        current_tag.strip!
        if current_tag == tag
          puts "Using #{name} (#{tag})"
        else
          puts "Installing #{name} #{tag} (was #{current_tag})".green
          `cd #{dir} 2>&1 &&\
           git reset HEAD --hard 2>&1 &&\
           git checkout . 2>&1 &&\
           git clean -fd 2>&1 &&\
           git fetch origin #{tag} 2>&1 &&\
           git checkout #{tag} 2>&1`
        end
      else
        puts "Installing #{name} (#{tag})".green
        `git clone #{url} -b #{tag} #{dir} 2>&1`
      end

      if not options.nil?
        files = options[:files]
        if not files.nil?
          if files.kind_of?(String)
            files = [files]
          end

          files.each do |file|
            file_list = `ls #{dir}/#{file} 2>&1 2>/dev/null`
            absoulte_files = file_list.split(/\r?\n/)
            @source_files[name] = absoulte_files
          end
        end
      end

      if not @source_files[name]
        @source_files[name] = dir
      end
    end

    def self.configure_project
      # detect Xcode project
      project_filename = `ls | grep .xcodeproj`.split(/\r?\n/)[0]
      if not project_filename
        puts "Couldn't find .xcodeproj file.".red
        exit 1
      end<commit_msg>Show error messages when failed to git clone.<commit_after>module Seed
  class Core
    @source_files = {}

    def self.install
      seeds = read_seedfile.split('\r\n')
      seeds.each { |line| eval line }
      self.configure_project
    end

    def self.read_seedfile
      begin
        File.read('Seedfile')
      rescue
        puts 'No Seedfile.'
        exit 1
      end
    end

    def self.github(repo, tag, options=nil)
      url = "https://github.com/#{repo}"
      name = repo.split('/')[1]
      dir = "Seeds/#{name}"

      if File.exist?(dir)
        current_tag = `cd #{dir} && git describe --tags --abbrev=0 2>&1`
        current_tag.strip!
        if current_tag == tag
          puts "Using #{name} (#{tag})"
        else
          puts "Installing #{name} #{tag} (was #{current_tag})".green
          `cd #{dir} 2>&1 &&\
           git reset HEAD --hard 2>&1 &&\
           git checkout . 2>&1 &&\
           git clean -fd 2>&1 &&\
           git fetch origin #{tag} 2>&1 &&\
           git checkout #{tag} 2>&1`
        end
      else
        puts "Installing #{name} (#{tag})".green
        output = `git clone #{url} -b #{tag} #{dir} 2>&1`
        if output.include?("not found")
          if output.include?("repository")
            puts "[!] #{name}: Couldn't find the repository.".red
          elsif output.include?("upstream")
            puts "[!] #{name}: Couldn't find the tag `#{tag}`.".red
          end
        end
      end

      if not options.nil?
        files = options[:files]
        if not files.nil?
          if files.kind_of?(String)
            files = [files]
          end

          files.each do |file|
            file_list = `ls #{dir}/#{file} 2>&1 2>/dev/null`
            absoulte_files = file_list.split(/\r?\n/)
            @source_files[name] = absoulte_files
          end
        end
      end

      if not @source_files[name]
        @source_files[name] = dir
      end
    end

    def self.configure_project
      # detect Xcode project
      project_filename = `ls | grep .xcodeproj`.split(/\r?\n/)[0]
      if not project_filename
        puts "Couldn't find .xcodeproj file.".red
        exit 1
      end
{'fraction_non_alphanumeric': 0.13835072031793344, 'fraction_numerical': 0.011922503725782414, 'mean_word_length': 1.6633597883597884, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5072960', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1284, 'n_words': 339}