Sha256: bd5a047e86a448aaeff59063b60f89f22edcf2be17d38e593f571019afd2c3c0

Contents?: true

Size: 1.02 KB

Versions: 22

Compression:

Stored size: 1.02 KB

Contents

require 'set'

module Overcommit::HookContext
  # Simulates a pre-commit context pretending that all files have been changed.
  #
  # This results in pre-commit hooks running against the entire repository,
  # which is useful for automated CI scripts.
  class RunAll < Base
    def modified_files
      @modified_files ||= all_files
    end

    # Returns all lines in the file since in this context the entire repo is
    # being scrutinized.
    #
    # @param file [String]
    # @return [Set]
    def modified_lines_in_file(file)
      @modified_lines_in_file ||= {}
      @modified_lines_in_file[file] ||= Set.new(1..count_lines(file))
    end

    def hook_class_name
      'PreCommit'
    end

    def hook_type_name
      'pre_commit'
    end

    def hook_script_name
      'pre-commit'
    end

    def initial_commit?
      return @initial_commit unless @initial_commit.nil?
      @initial_commit = Overcommit::GitRepo.initial_commit?
    end

    private

    def count_lines(file)
      File.foreach(file).count
    end
  end
end

Version data entries

22 entries across 20 versions & 2 rubygems

Version Path
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook_context/run_all.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook_context/run_all.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook_context/run_all.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/overcommit-0.46.0/lib/overcommit/hook_context/run_all.rb
overcommit-0.46.0 lib/overcommit/hook_context/run_all.rb
overcommit-0.45.0 lib/overcommit/hook_context/run_all.rb
overcommit-0.44.0 lib/overcommit/hook_context/run_all.rb
overcommit-0.43.0 lib/overcommit/hook_context/run_all.rb
overcommit-0.42.0 lib/overcommit/hook_context/run_all.rb
overcommit-0.41.0 lib/overcommit/hook_context/run_all.rb
overcommit-0.40.0 lib/overcommit/hook_context/run_all.rb
overcommit-0.39.1 lib/overcommit/hook_context/run_all.rb
overcommit-0.39.0 lib/overcommit/hook_context/run_all.rb
overcommit-0.38.0 lib/overcommit/hook_context/run_all.rb
overcommit-0.37.0 lib/overcommit/hook_context/run_all.rb
overcommit-0.36.0 lib/overcommit/hook_context/run_all.rb
overcommit-0.35.0 lib/overcommit/hook_context/run_all.rb
overcommit-0.34.2 lib/overcommit/hook_context/run_all.rb
overcommit-0.34.1 lib/overcommit/hook_context/run_all.rb
overcommit-0.34.0 lib/overcommit/hook_context/run_all.rb