<commit_before>module Rubycritic
  module SourceControlSystem

    class Git < Base
      register_system

      def self.supported?
        `git branch 2>&1` && $?.success?
      end

      def self.to_s
        "Git"
      end

      def revisions_count(path)
        `git log --follow --format=oneline #{path.shellescape}`.count("\n")
      end

      def date_of_last_commit(path)
        `git log -1 --date=iso --format=%ad #{path.shellescape}`.chomp!
      end

      def has_revision?
        head_reference && $?.success?
      end

      def head_reference
        `git rev-parse --verify HEAD`.chomp!
      end

      def travel_to_head
        stash_successful = stash_changes
        yield
      ensure
        travel_to_original_state if stash_successful
      end

      private

      def stash_changes
        stashes_count_before = stashes_count
        `git stash`
        stashes_count_after = stashes_count
        stashes_count_after > stashes_count_before
      end

      def stashes_count
        `git stash list`.count("\n")
      end

      def travel_to_original_state
        `git stash pop`
      end
    end

  end
end
<commit_msg>Fix #18<commit_after>module Rubycritic
  module SourceControlSystem

    class Git < Base
      register_system

      def self.supported?
        `git branch 2>&1` && $?.success?
      end

      def self.to_s
        "Git"
      end

      def revisions_count(path)
        `git log --follow --format=%h #{path.shellescape}`.count("\n")
      end

      def date_of_last_commit(path)
        `git log -1 --date=iso --format=%ad #{path.shellescape}`.chomp!
      end

      def has_revision?
        head_reference && $?.success?
      end

      def head_reference
        `git rev-parse --verify HEAD`.chomp!
      end

      def travel_to_head
        stash_successful = stash_changes
        yield
      ensure
        travel_to_original_state if stash_successful
      end

      private

      def stash_changes
        stashes_count_before = stashes_count
        `git stash`
        stashes_count_after = stashes_count
        stashes_count_after > stashes_count_before
      end

      def stashes_count
        `git stash list --format=%h`.count("\n")
      end

      def travel_to_original_state
        `git stash pop`
      end
    end

  end
end

{'fraction_non_alphanumeric': 0.0766250538097288, 'fraction_numerical': 0.0034438226431338786, 'mean_word_length': 1.8941469489414695, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, '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': '243132', 'n_tokens_mistral': 731, 'n_tokens_neox': 697, 'n_words': 172}