Skip to content

Instantly share code, notes, and snippets.

@duncanmak
Created October 31, 2012 19:38
Show Gist options
  • Save duncanmak/3989324 to your computer and use it in GitHub Desktop.
Save duncanmak/3989324 to your computer and use it in GitHub Desktop.
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