Sha256: 5045aca0c71cb66ac737a7934e924f079e3499b586c3781f6ad812ef1a26d8f7

Contents?: true

Size: 584 Bytes

Versions: 6

Compression:

Stored size: 584 Bytes

Contents

module PreCommit
  module Utils
    module StagedFiles

      def staged_files
        @staged_files ||= begin
          files = `git diff --cached --name-only --diff-filter=ACM`.split
          files.reject { |f| size = File.size(f); size > 1_000_000 || (size > 20 && binary?(f)) }
        end
      end

    private
      # from https://github.com/djberg96/ptools/blob/master/lib/ptools.rb#L90
      def binary?(file)
        s = (File.read(file, File.stat(file).blksize) || "").split(//)
        ((s.size - s.grep(" ".."~").size) / s.size.to_f) > 0.30
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pre-commit-0.16.1 lib/pre-commit/utils/staged_files.rb
pre-commit-0.16.0 lib/pre-commit/utils/staged_files.rb
pre-commit-0.15.0 lib/pre-commit/utils/staged_files.rb
pre-commit-0.14.1 lib/pre-commit/utils/staged_files.rb
pre-commit-0.14.0 lib/pre-commit/utils/staged_files.rb
pre-commit-0.13.0 lib/pre-commit/utils/staged_files.rb