<commit_before>#!/usr/bin/env ruby

require 'English'
require 'json'
require_relative 'base'

module Commands
  class In < Commands::Base
    attr_reader :destination

    def initialize(destination:, input: Input.instance)
      @destination = destination

      super(input: input)
    end

    def output
      id         = pr['number']
      branch_ref = "pr-#{pr['head']['ref']}"

      raise 'PR has merge conflicts' if pr['mergeable'] == false && fetch_merge

      system("git clone #{depth_flag} #{uri} #{destination} 1>&2")

      raise 'git clone failed' unless $CHILD_STATUS.exitstatus.zero?

      Dir.chdir(File.join(destination, '.git')) do
        system <<-BASH
          echo "#{pr['html_url']}" > url
          echo "#{pr['number']}" > id
          echo "#{pr['head']['ref']}" > branch
          echo "#{pr['base']['ref']}" > base_branch
          echo "#{pr['user']['login']}" > userlogin
          echo "#{pr['head']['sha']}" > head_sha
        BASH
      end

      Dir.chdir(destination) do
        raise 'git clone failed' unless system("git fetch -q origin pull/#{id}/#{remote_ref}:#{branch_ref} 1>&2")

        system <<-BASH
          git checkout #{branch_ref} 1>&2
          git config --add pullrequest.url #{pr['html_url']} 1>&2
          git config --add pullrequest.id #{pr['number']} 1>&2
          git config --add pullrequest.branch #{pr['head']['ref']} 1>&2
          git config --add pullrequest.basebranch #{pr['base']['ref']} 1>&2
          git config --add pullrequest.userlogin #{pr['user']['login']} 1>&2
        BASH

        case input.params.git.submodules
        when 'all', nil
          system("git submodule update --init --recursive #{depth_flag} 1>&2")
        when Array
          input.params.git.submodules.each do |path|
            system("git submodule update --init --recursive #{depth_flag} #{path} 1>&2")
          end
        end

        unless input.params.git.disable_lfs
          system('git lfs fetch 1>&2')
          system('git lfs checkout 1>&2')
        end
      end

      {
        'version' =>  { 'ref' => ref, 'pr' => id.to_s },
        'metadata' => [{ 'name' => 'url', 'value' => pr['html_url'] }]<commit_msg>Apply the depth flag to the branch fetch operation and not just the initial clone.<commit_after>#!/usr/bin/env ruby

require 'English'
require 'json'
require_relative 'base'

module Commands
  class In < Commands::Base
    attr_reader :destination

    def initialize(destination:, input: Input.instance)
      @destination = destination

      super(input: input)
    end

    def output
      id         = pr['number']
      branch_ref = "pr-#{pr['head']['ref']}"

      raise 'PR has merge conflicts' if pr['mergeable'] == false && fetch_merge

      system("git clone #{depth_flag} #{uri} #{destination} 1>&2")

      raise 'git clone failed' unless $CHILD_STATUS.exitstatus.zero?

      Dir.chdir(File.join(destination, '.git')) do
        system <<-BASH
          echo "#{pr['html_url']}" > url
          echo "#{pr['number']}" > id
          echo "#{pr['head']['ref']}" > branch
          echo "#{pr['base']['ref']}" > base_branch
          echo "#{pr['user']['login']}" > userlogin
          echo "#{pr['head']['sha']}" > head_sha
        BASH
      end

      Dir.chdir(destination) do
        raise 'git clone failed' unless system("git fetch #{depth_flag} -q origin pull/#{id}/#{remote_ref}:#{branch_ref} 1>&2")

        system <<-BASH
          git checkout #{branch_ref} 1>&2
          git config --add pullrequest.url #{pr['html_url']} 1>&2
          git config --add pullrequest.id #{pr['number']} 1>&2
          git config --add pullrequest.branch #{pr['head']['ref']} 1>&2
          git config --add pullrequest.basebranch #{pr['base']['ref']} 1>&2
          git config --add pullrequest.userlogin #{pr['user']['login']} 1>&2
        BASH

        case input.params.git.submodules
        when 'all', nil
          system("git submodule update --init --recursive #{depth_flag} 1>&2")
        when Array
          input.params.git.submodules.each do |path|
            system("git submodule update --init --recursive #{depth_flag} #{path} 1>&2")
          end
        end

        unless input.params.git.disable_lfs
          system('git lfs fetch 1>&2')
          system('git lfs checkout 1>&2')
        end
      end

      {
        'version' =>  { 'ref' => ref, 'pr' => id.to_s },
        'metadata' => [{ 'name' => 'url', 'value' => pr['html_url'] }]
{'fraction_non_alphanumeric': 0.16677874915938132, 'fraction_numerical': 0.010759919300605245, 'mean_word_length': 2.4087089381207027, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 51, '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': '4194545', 'n_tokens_mistral': 1391, 'n_tokens_neox': 1340, 'n_words': 365}