Created
November 19, 2012 16:17
-
-
Save aroberts/4111564 to your computer and use it in GitHub Desktop.
git command to show information about a week's worth of commits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixed swapped trinary