]> Tony Duckles's Git Repositories (git.nynim.org) - dotfiles.git/blob - bin/git-push-log
bin/svn-wrapper: Misc fixes
[dotfiles.git] / bin / git-push-log
1 #!/usr/bin/env ruby
2 # Usage: git-push-log
3 # Show reflog information for all branch heads by date. This is useful on bare
4 # remotes to determine when / who pushed and when.
5 require 'time'
6
7 # change into git reflog dir to make everything easier
8 ENV['GIT_DIR'] ||= `git rev-parse --git-dir`.chomp
9 Dir.chdir(ENV['GIT_DIR'] + '/logs/refs/heads')
10
11 # find all reflog files
12 logs = Dir['**'].select { |f| File.file?(f) }
13
14 # build master list of all reflog entries for all refs
15 records = []
16 logs.each do |log|
17 entries = File.read(log).split("\n")
18 entries.each do |line|
19 before, after, rest = line.split(' ', 3)
20 push_info, message = rest.split("\t", 1)
21 if push_info =~ /^(.*?) (<.*>) (\d+) ([0-9+-]+)/
22 name, email, timestamp, offset = $1, $2, $3.to_i, $4
23 date = Time.at(timestamp)
24 end
25 records << [log, before, after, name, email, date]
26 end
27 end
28
29 # sort and output reflog entries with some formatting
30 begin
31 records = records.sort_by { |r| r.last }.reverse
32 records.each do |ref, before, after, name, email, date|
33 printf "%-20s %7s:%7s %-30s %s\n",
34 date.iso8601, before[0,7], after[0,7], ref, email
35 end
36 rescue Errno::EPIPE
37 exit 1
38 end