lib/bait/build.rb in bait-0.5.12 vs lib/bait/build.rb in bait-0.5.13
- old
+ new
@@ -14,11 +14,11 @@
adapter :memory,
Moneta.new(:YAML, :file => Bait.db_file('builds'))
attribute :simplecov, Boolean, default: false
- attribute :ref, String, default: "master"
+ attribute :ref, String, default: "refs/heads/master"
attribute :owner_name, String
attribute :owner_email, String
attribute :name, String
attribute :clone_url, String
attribute :output, String, default: ""
@@ -34,13 +34,16 @@
after_destroy do
self.broadcast(:remove)
self.cleanup!
end
+ def branch
+ self.ref.gsub('refs/heads/', '')
+ end
+
def summary
- branch = self.ref ? self.ref.split('/').last : "n/a"
- output = %{#{self.name} (#{branch}) #{self.status}}
+ output = %{#{self.name} (#{self.branch}) #{self.status}}
case self.status
when "passed"
output.green
when "failed"
output.red
@@ -89,10 +92,13 @@
return if cloned?
unless Dir.exists?(sandbox_directory)
FileUtils.mkdir_p sandbox_directory
end
begin
- Git.clone(clone_url, name, :path => sandbox_directory)
+ g = Git.clone(clone_url, name, :path => sandbox_directory)
+ if g.branch.name != self.branch
+ g.checkout("origin/#{self.branch}")
+ end
rescue => ex
msg = "Failed to clone #{clone_url}"
self.output << "#{msg}\n\n#{ex.message}\n\n#{ex.backtrace.join("\n")}"
self.status = "failed to clone"
self.save