<commit_before>module MGit
  class CheckoutCommand < Command
    def execute(args)
      @commit = args.shift

      if repos.empty?
        perror "Couldn't find commit #{@commit} in any repository."
      else
        checkout_all
      end
    end

    def arity
      [1, 1]
    end

    def usage
      'checkout <commit-sha/obj>'
    end

    def description
      'checkout commit object in all repositories that have it'
    end

    register_command :checkout
    register_alias :co

    private

    def repos
      @rs ||= Registry.select { |r| r.has_commit?(@commit) }
    end

    def checkout_all
      repos.each do |repo|
        begin
          if repo.dirty?
            pwarn "Skipping repository #{repo.name} as it is dirty."
            next
          end

          repo.in_repo { System.git("checkout -q #{@commit}") }
          pinfo "Switched to #{@commit} in repository #{repo.name}."
        rescue GitError
          perror "Failed to checkout #{@commit} in repository #{repo.name}."<commit_msg>Allow to pass git arguments to mgit checkout<commit_after>module MGit
  class CheckoutCommand < Command
    def execute(args)
      @git_args = args.shift if args.length == 2
      @commit = args.shift

      if repos.empty?
        perror "Couldn't find commit #{@commit} in any repository."
      else
        checkout_all
      end
    end

    def arity
      [1, 2]
    end

    def usage
      'checkout [additional git args] <commit-sha/obj>'
    end

    def description
      'checkout commit object in all repositories that have it'
    end

    register_command :checkout
    register_alias :co

    private

    def repos
      @rs ||= Registry.select { |r| r.has_commit?(@commit) }
    end

    def checkout_all
      repos.each do |repo|
        begin
          if repo.dirty?
            pwarn "Skipping repository #{repo.name} as it is dirty."
            next
          end

          repo.in_repo { System.git("checkout -q #{@git_args || ''} #{@commit}") }
          pinfo "Switched to #{@commit} in repository #{repo.name}."
        rescue GitError
          perror "Failed to checkout #{@commit} in repository #{repo.name}."
{'fraction_non_alphanumeric': 0.09321642824180895, 'fraction_numerical': 0.0023073373327180432, 'mean_word_length': 1.9986168741355463, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '3601532', 'n_tokens_mistral': 665, 'n_tokens_neox': 627, 'n_words': 207}