2012-05-26 12:37:49 +02:00
|
|
|
module Gitlab
|
2012-04-22 15:14:01 +02:00
|
|
|
class Satellite
|
2012-09-26 20:52:01 +02:00
|
|
|
|
2012-04-22 15:14:01 +02:00
|
|
|
PARKING_BRANCH = "__parking_branch"
|
|
|
|
|
|
|
|
attr_accessor :project
|
|
|
|
|
|
|
|
def initialize project
|
|
|
|
self.project = project
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
`git clone #{project.url_to_repo} #{path}`
|
|
|
|
end
|
|
|
|
|
|
|
|
def path
|
2012-09-26 20:52:01 +02:00
|
|
|
Rails.root.join("tmp", "repo_satellites", project.path)
|
2012-04-22 15:14:01 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def exists?
|
|
|
|
File.exists? path
|
|
|
|
end
|
|
|
|
|
|
|
|
#will be deleted all branches except PARKING_BRANCH
|
|
|
|
def clear
|
|
|
|
Dir.chdir(path) do
|
|
|
|
heads = Grit::Repo.new(".").heads.map{|head| head.name}
|
|
|
|
if heads.include? PARKING_BRANCH
|
|
|
|
`git checkout #{PARKING_BRANCH}`
|
|
|
|
else
|
|
|
|
`git checkout -b #{PARKING_BRANCH}`
|
|
|
|
end
|
|
|
|
heads.delete(PARKING_BRANCH)
|
|
|
|
heads.each do |head|
|
|
|
|
`git branch -D #{head}`
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2012-09-26 20:52:01 +02:00
|
|
|
|
2012-04-22 15:14:01 +02:00
|
|
|
end
|
|
|
|
end
|