<commit_before>class GitRepo
  def initialize(dir)
    @dir = dir
    if !File.exists? File.join(@dir, ".git")
      @dir = git('rev-parse', '--show-toplevel').chomp
      if !File.exists? File.join(@dir, ".git")
        raise GitSmart::RunFailed.new("You need to run this from within a git directory")
      end
    end
  end

  def current_branch
    File.read(File.join(@dir, ".git", "HEAD")).strip.sub(/^.*refs\/heads\//, '')<commit_msg>Add handling for Git submodules<commit_after># encoding: utf-8

require 'yaml'

class GitRepo
  def initialize(dir)
    @dir = dir
    unless File.directory?(git_dir)
      raise GitSmart::RunFailed.new(
        'You need to run this from within a git directory')
    end
  end

  def git_dir
    gitdir = File.join(@dir, '.git')

    unless File.exists?(gitdir)
      @dir = git('rev-parse', '--show-toplevel').chomp
      gitdir = File.join(@dir, '.git')
    end

    if File.file?(gitdir)
      submodule = YAML.load_file(gitdir)
      gitdir = File.join(@dir, submodule['gitdir'])
    end

    gitdir
  end

  def current_branch
    head_file = File.join(git_dir, 'HEAD')
    File.read(head_file).strip.sub(%r(^.*refs/heads/), '')
{'fraction_non_alphanumeric': 0.1548936170212766, 'fraction_numerical': 0.000851063829787234, 'mean_word_length': 2.8940397350993377, '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': '7287826', 'n_tokens_mistral': 412, 'n_tokens_neox': 405, 'n_words': 97}