Skip to content

Instantly share code, notes, and snippets.

@aroberts
Created November 19, 2012 16:17
Show Gist options
  • Save aroberts/4111564 to your computer and use it in GitHub Desktop.
Save aroberts/4111564 to your computer and use it in GitHub Desktop.
git command to show information about a week's worth of commits
#!/usr/bin/env ruby
require 'optparse'
require 'date'
def date_of_last(day)
date = Date.parse(day)
delta = date > Date.today ? 7 : 0
(date - delta)
end
glog_default = ["log", "--graph", "--pretty=format:'%Cred%h%Creset",
"-%C(yellow)%d%Creset", "%s", "%Cgreen(%cr)", "%C(bold blue)<%an>%Creset'",
"--abbrev-commit", "--date=relative"]
weeks_back = 0
committer = `whoami`.strip
has_glog = system "git glog -n 1 &>/dev/null"
if has_glog
command = "glog"
else
command = glog_default.join(' ')
end
parser = OptionParser.new do |p|
p.banner = "Usage: git report [<options>]"
p.on("-w", "--weeks <n>",
"Number of weeks before " +
"the current week to report on [#{weeks_back}]") do |weeks|
weeks_back = weeks.to_i
end
p.on("-a", "--author [<name>]",
"Filter by committer (blank for any author) [#{committer}]") do |author|
committer = author
end
p.on("-c", "--changes", "Show full commit diffs") do
command = "whatchanged -p"
end
p.on("-h", "--help") { puts p; exit 0 }
end
args = ARGV
parser.order!(args)
start = date_of_last("Monday") - (7 * weeks_back)
stop = start + 7
system "git #{command} --author=#{committer} --since=#{start.to_s} --until=#{stop.to_s} #{args}"
@aroberts
Copy link
Author

Fixed swapped trinary

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment