class DerailedBenchmarks::Git::InPath
A class for running commands in a git directory
It’s faster to check if we’re already in that directory instead of having to ‘cd` into each time. twitter.com/schneems/status/1305196730170961920
Example:
in_git_path = InGitPath.new(`bundle info heapy --path`.strip) in_git_path.checkout!("f0f92b06156f2274021aa42f15326da041ee9009") in_git_path.short_sha # => "f0f92b0"
Attributes
path[R]
Public Class Methods
new(path)
click to toggle source
# File lib/derailed_benchmarks/git/in_path.rb, line 15 def initialize(path) @path = path end
Public Instance Methods
branch()
click to toggle source
# File lib/derailed_benchmarks/git/in_path.rb, line 31 def branch branch = run!("git rev-parse --abbrev-ref HEAD") branch == "HEAD" ? nil : branch end
checkout!(ref)
click to toggle source
# File lib/derailed_benchmarks/git/in_path.rb, line 36 def checkout!(ref) run!("git checkout '#{ref}' 2>&1") end
description()
click to toggle source
# File lib/derailed_benchmarks/git/in_path.rb, line 19 def description run!("git log --oneline --format=%B -n 1 HEAD | head -n 1") end
run(cmd)
click to toggle source
# File lib/derailed_benchmarks/git/in_path.rb, line 44 def run(cmd) if Dir.pwd == path out = `#{cmd}`.strip else out = `cd #{path} && #{cmd}`.strip end out end
run!(cmd)
click to toggle source
# File lib/derailed_benchmarks/git/in_path.rb, line 53 def run!(cmd) out = run(cmd) raise "Error while running #{cmd.inspect}: #{out}" unless $?.success? out end
short_sha()
click to toggle source
# File lib/derailed_benchmarks/git/in_path.rb, line 23 def short_sha run!("git rev-parse --short HEAD") end
time()
click to toggle source
# File lib/derailed_benchmarks/git/in_path.rb, line 40 def time DateTime.parse(time_stamp_string) end
time_stamp_string()
click to toggle source
# File lib/derailed_benchmarks/git/in_path.rb, line 27 def time_stamp_string run!("git log -n 1 --pretty=format:%ci") # https://stackoverflow.com/a/25921837/147390 end