Sha256: 21c303babc2bb965ad76b91e668f01eaf9bcd1b266e872b33f48010367ce1f8c

Contents?: true

Size: 1.11 KB

Versions: 12

Compression:

Stored size: 1.11 KB

Contents

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 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

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
rubycritic-2.6.0 lib/rubycritic/source_control_systems/git.rb
rubycritic-2.5.0 lib/rubycritic/source_control_systems/git.rb
rubycritic-2.4.1 lib/rubycritic/source_control_systems/git.rb
rubycritic-2.4.0 lib/rubycritic/source_control_systems/git.rb
rubycritic-2.3.0 lib/rubycritic/source_control_systems/git.rb
rubycritic-2.2.0 lib/rubycritic/source_control_systems/git.rb
rubycritic-2.1.0 lib/rubycritic/source_control_systems/git.rb
rubycritic-2.0.0 lib/rubycritic/source_control_systems/git.rb
rubycritic-1.4.0 lib/rubycritic/source_control_systems/git.rb
rubycritic-1.3.0 lib/rubycritic/source_control_systems/git.rb
rubycritic-1.2.1 lib/rubycritic/source_control_systems/git.rb
rubycritic-1.2.0 lib/rubycritic/source_control_systems/git.rb