Created
October 31, 2012 19:38
-
-
Save duncanmak/3989324 to your computer and use it in GitHub Desktop.
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
def log(text) | |
puts "#{'=' * 3} #{text} #{'=' * 3}" | |
$stdout.flush | |
end | |
def git_root | |
root = File.join(ENV['ProgramFiles(x86)'] || ENV['ProgramFiles'], "Git", "bin") | |
return root if File.exists?(root) | |
raise "Cannot find git" | |
end | |
def git(*args) | |
log "Running git #{args.join(' ')}" | |
cmd = File.join(git_root, "git") | |
`"#{cmd}" #{args.join(' ')}` | |
end | |
def record_commit_distance!(repo, output_file, src_commit, dest_commit = 'HEAD') | |
Dir.chdir(repo) do | |
commits = git 'log', '--format="%H"', "#{src_commit}..#{dest_commit}", "2>&1" | |
distance = commits.split("\n") | |
log "Writing #{distance.inspect} to #{output_file}" | |
File.open(output_file, "w") do |f| | |
f.write(commits) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment