Skip to content

Instantly share code, notes, and snippets.

@michaeldv
Forked from eladmeidar/gitproductive.rb
Created October 21, 2009 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaeldv/215550 to your computer and use it in GitHub Desktop.
Save michaeldv/215550 to your computer and use it in GitHub Desktop.
class GitProductive
attr_accessor :directory, :lines, :commits
def initialize(directory = Dir.pwd)
raise "#{directory} is not a git repository" unless Dir.entries(directory).include?(".git")
@directory = directory
@lines, @commits = 0, 0
end
def check!(duration = "1 days")
Dir.chdir(@directory)
output = `git log --shortstat --since="#{duration} ago" | grep insertions`.split("\n")
@commits = output.size
output.each do |commit|
@lines += commit.match(/(\d+) insertions/)[0].to_i
end
end
def stats(duration = "1 days")
check!(duration)
'%.2f' % (@commits == 0 ? 0 : @lines / @commits.to_f)
end
end
# Example
# git_productive = GitProductive.new(ARGV[0] || Dir.pwd)
# puts "#{git_productive.stats} lines per commit today"
# puts "#{git_productive.stats('3 weeks')} lines per commit in the last 3 weeks"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment