<commit_before>#TODO: should I move all methods that user grit.git to file_access?
require 'grit'
require 'fileutils'
require 'thread'

module DTK
  module Common
    require File.expand_path('require_first',File.dirname(__FILE__))
    class GritAdapter 
      require File.expand_path('grit_adapter/file_access', File.dirname(__FILE__))
      require File.expand_path('grit_adapter/object_access', File.dirname(__FILE__))
      def initialize(repo_dir,branch='master')
        @repo_dir = repo_dir
        @branch = branch
        @grit_repo = nil
        begin
          @grit_repo = ::Grit::Repo.new(repo_dir)
        rescue ::Grit::NoSuchPathError
          repo_name = repo_dir.split("/").last.gsub("\.git","")
          #TODO: change to usage error
          raise Error.new("repo (#{repo_name}) does not exist")
        rescue => e
          raise e
        end
      end

      def self.clone(target_repo_dir,git_server_url,opts={})
        if File.directory?(target_repo_dir)
          if opts[:delete_if_exists]
            FileUtils.rm_rf target_repo_dir
          else
            raise Error.new("trying to create a repo directory (#{target_repo_dir}) that exists already")
          end
        end
        clone_cmd_opts = {:raise => true, :timeout => 60}
        clone_args = [git_server_url,target_repo_dir]
        if branch = opts[:branch] 
          clone_args += ["-b",branch]
        end
        ::Grit::Git.new("").clone(clone_cmd_opts,*clone_args)
        ret = new(*[target_repo_dir,opts[:branch]].compact)
        #make sure remote branch exists; ::Grit::Git.new("").clone silently uses master if remote branch does not exist
        if branch = opts[:branch]
          unless ret.branches().include?(opts[:branch])
            FileUtils.rm_rf target_repo_dir
            raise Error.new("Remote branch (#{opts[:branch]}) does not exist")
          end
        end
        ret
      end
<commit_msg>change to provide more clear error<commit_after>#TODO: should I move all methods that user grit.git to file_access?
require 'grit'
require 'fileutils'
require 'thread'

module DTK
  module Common
    require File.expand_path('require_first',File.dirname(__FILE__))
    class GritAdapter 
      require File.expand_path('grit_adapter/file_access', File.dirname(__FILE__))
      require File.expand_path('grit_adapter/object_access', File.dirname(__FILE__))
      def initialize(repo_dir,branch='master')
        @repo_dir = repo_dir
        @branch = branch
        @grit_repo = nil
        begin
          @grit_repo = ::Grit::Repo.new(repo_dir)
        rescue ::Grit::NoSuchPathError
          repo_name = repo_dir.split("/").last.gsub("\.git","")
          #TODO: change to usage error
          raise Error.new("repo (#{repo_name}) does not exist")
        rescue => e
          raise e
        end
      end

      def self.clone(target_repo_dir,git_server_url,opts={})
        if File.directory?(target_repo_dir)
          if opts[:delete_if_exists]
            FileUtils.rm_rf target_repo_dir
          else
            raise Error.new("trying to create a repo directory (#{target_repo_dir}) that exists already")
          end
        end
        clone_cmd_opts = {:raise => true, :timeout => 60}
        clone_args = [git_server_url,target_repo_dir]
        if branch = opts[:branch] 
          clone_args += ["-b",branch]
        end
        ::Grit::Git.new("").clone(clone_cmd_opts,*clone_args)
        ret = new(*[target_repo_dir,opts[:branch]].compact)
        #make sure remote branch exists; ::Grit::Git.new("").clone silently uses master if remote branch does not exist
        if branch = opts[:branch]
          branches = ret.branches()
          unless branches.include?(opts[:branch])
            FileUtils.rm_rf target_repo_dir
            raise Error.new("Remote branch (#{opts[:branch]}) does not exist")
          end
        end
        ret
      end

{'fraction_non_alphanumeric': 0.11099718021020251, 'fraction_numerical': 0.0010253781081773904, 'mean_word_length': 2.5569735642661806, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, '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': '2714671', 'n_tokens_mistral': 1154, 'n_tokens_neox': 1146, 'n_words': 275}