Class: HOC::Git

Inherits:
Object
  • Object
show all
Defined in:
lib/hoc/git.rb

Overview

Git source code base.

Instance Method Summary collapse

Constructor Details

#initialize(dir, exclude) ⇒ Git

Returns a new instance of Git.



30
31
32
33
# File 'lib/hoc/git.rb', line 30

def initialize(dir, exclude)
  @dir = dir
  @exclude = exclude
end

Instance Method Details

#hitsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/hoc/git.rb', line 35

def hits
  version = `git --version`.split(/ /)[2]
  raise "git version #{version} is too old, upgrade it to 2.0+" unless
    Gem::Version.new(version) >= Gem::Version.new('2.0')
  cmd = [
    "cd #{@dir} && git",
    'log', '--pretty=tformat:', '--numstat',
    '--ignore-space-change', '--ignore-all-space',
    '--ignore-submodules', '--no-color',
    '--find-copies-harder', '-M', '--diff-filter=ACDM',
    '--', '.',
    @exclude.map { |e| "':(exclude,glob)#{e}'" }.join(' ')
  ].join(' ')
  [
    Hits.new(
      Time.now,
      `#{cmd}`.split(/\n/).delete_if(&:empty?).map do |t|
        t.split(/\t/).take(2).map(&:to_i).inject(:+)
      end.inject(:+) || 0
    )
  ]
end