Skip to content

Commit

Permalink
Support non-brach head
Browse files Browse the repository at this point in the history
  • Loading branch information
bogdan committed Mar 15, 2012
1 parent 636dd9b commit a634e3b
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/diffbench.rb
Expand Up @@ -25,9 +25,7 @@ def run
puts "Applying stashed changes back"
git_run "stash pop"
end
else
branch = git.current_branch.to_s
raise Error, "No current branch. TODO: support this use case" if branch == "(no branch)"
elsif branch = current_head
puts "Checkout HEAD^"
git_run "checkout 'HEAD^'"
puts "Running benchmark with HEAD^"
Expand All @@ -37,7 +35,8 @@ def run
puts "Checkout to previous HEAD again"
git_run "checkout #{branch}"
end

else
raise Error, "No current branch."
end
puts ""
caption = "Before patch: ".gsub(/./, " ") + Benchmark::Tms::CAPTION
Expand All @@ -50,6 +49,16 @@ def run
end
end

def current_head
branch = git.current_branch.to_s
return branch if !(branch == "(no branch)")
branch = git_run("symbolic-ref HEAD").gsub(/^refs\/head\//, "")
return branch unless branch.empty?
rescue Git::GitExecuteError
branch = git_run("rev-parse HEAD")[0..7]
return branch
end

def run_file
output = `ruby #{@file}`
begin
Expand Down

0 comments on commit a634e3b

Please sign in to comment.