<commit_before>class Git
  def clone(repository, branch = 'master')
    background do
      base_dir = "#{Dir.tmpdir}/reviewit"
      project_dir_name = "#{branch}_#{SecureRandom.hex}"
      dir = "#{base_dir}/#{project_dir_name}"
      FileUtils.rm_rf dir
      FileUtils.mkdir_p dir

      @branch = branch
      @dir = base_dir
      @ready = call("git clone --branch #{branch} --depth 1 #{repository} #{project_dir_name}")
      @dir = dir

      yield(self)
      FileUtils.rm_rf(dir) if cloned
    end
  end

  attr_reader :dir

  def ready?
    @ready
  end

  def am(patch)
    contents = patch.formatted
    file = Tempfile.new('patch')
    file.puts contents
    file.close
    call("git am #{file.path}")
  end

  def push(branch, forced = nil)
    call("git push #{forced ? '-f' : ''} origin #{@branch}:#{branch}")
  end

  def rm_branch(branch)
    call("git push origin :#{branch}")
  end

  def sha1(branch = 'HEAD')
    `cd #{@dir} && git rev-parse #{branch}`.strip
  end
<commit_msg>Fix error removing cloned repositories.<commit_after>class Git
  def clone(repository, branch = 'master')
    background do
      base_dir = "#{Dir.tmpdir}/reviewit"
      project_dir_name = "#{branch}_#{SecureRandom.hex}"
      dir = "#{base_dir}/#{project_dir_name}"
      FileUtils.rm_rf dir
      FileUtils.mkdir_p dir

      @branch = branch
      @dir = base_dir
      @ready = call("git clone --branch #{branch} --depth 1 #{repository} #{project_dir_name}")
      @dir = dir

      yield(self)
      FileUtils.rm_rf(dir) if @ready
    end
  end

  attr_reader :dir

  def ready?
    @ready
  end

  def am(patch)
    contents = patch.formatted
    file = Tempfile.new('patch')
    file.puts contents
    file.close
    call("git am #{file.path}")
  end

  def push(branch, forced = nil)
    call("git push #{forced ? '-f' : ''} origin #{@branch}:#{branch}")
  end

  def rm_branch(branch)
    call("git push origin :#{branch}")
  end

  def sha1(branch = 'HEAD')
    `cd #{@dir} && git rev-parse #{branch}`.strip
  end

{'fraction_non_alphanumeric': 0.14511352418558737, 'fraction_numerical': 0.0019743336623889436, 'mean_word_length': 2.795880149812734, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1153442', 'n_tokens_mistral': 694, 'n_tokens_neox': 685, 'n_words': 174}