Move locking from Satellite::Action to Satellite and add checks
This commit is contained in:
parent
0e9d4f30f4
commit
0ebcc60a33
|
@ -18,18 +18,8 @@ module Gitlab
|
|||
# * Yields the prepared satellite repo
|
||||
def in_locked_and_timed_satellite
|
||||
Grit::Git.with_timeout(options[:git_timeout]) do
|
||||
File.open(lock_file, "w+") do |f|
|
||||
f.flock(File::LOCK_EX)
|
||||
|
||||
unless project.satellite.exists?
|
||||
raise "Satellite doesn't exist"
|
||||
end
|
||||
|
||||
Dir.chdir(project.satellite.path) do
|
||||
repo = Grit::Repo.new('.')
|
||||
|
||||
return yield repo
|
||||
end
|
||||
project.satellite.lock do
|
||||
return yield project.satellite.repo
|
||||
end
|
||||
end
|
||||
rescue Errno::ENOMEM => ex
|
||||
|
@ -40,10 +30,6 @@ module Gitlab
|
|||
return false
|
||||
end
|
||||
|
||||
def lock_file
|
||||
Rails.root.join("tmp", "#{project.path}.lock")
|
||||
end
|
||||
|
||||
# * Clears the satellite
|
||||
# * Updates the satellite from Gitolite
|
||||
# * Sets up Git variables for the user
|
||||
|
|
|
@ -10,6 +10,8 @@ module Gitlab
|
|||
end
|
||||
|
||||
def clear_and_update!
|
||||
raise "Satellite doesn't exist" unless exists?
|
||||
|
||||
delete_heads!
|
||||
clear_working_dir!
|
||||
update_from_source!
|
||||
|
@ -23,10 +25,31 @@ module Gitlab
|
|||
File.exists? path
|
||||
end
|
||||
|
||||
# Locks the satellite and yields
|
||||
def lock
|
||||
raise "Satellite doesn't exist" unless exists?
|
||||
|
||||
File.open(lock_file, "w+") do |f|
|
||||
f.flock(File::LOCK_EX)
|
||||
|
||||
return yield
|
||||
end
|
||||
end
|
||||
|
||||
def lock_file
|
||||
Rails.root.join("tmp", "#{project.path}.lock")
|
||||
end
|
||||
|
||||
def path
|
||||
Rails.root.join("tmp", "repo_satellites", project.path)
|
||||
end
|
||||
|
||||
def repo
|
||||
raise "Satellite doesn't exist" unless exists?
|
||||
|
||||
@repo ||= Grit::Repo.new(path)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Clear the working directory
|
||||
|
@ -39,7 +62,7 @@ module Gitlab
|
|||
# This ensures we have no name clashes or issues updating branches when
|
||||
# working with the satellite.
|
||||
def delete_heads!
|
||||
heads = repo.heads.map{|head| head.name}
|
||||
heads = repo.heads.map(&:name)
|
||||
|
||||
# update or create the parking branch
|
||||
if heads.include? PARKING_BRANCH
|
||||
|
@ -54,15 +77,11 @@ module Gitlab
|
|||
heads.each { |head| repo.git.branch({D: true}, head) }
|
||||
end
|
||||
|
||||
def repo
|
||||
@repo ||= Grit::Repo.new(path)
|
||||
end
|
||||
|
||||
# Updates the satellite from Gitolite
|
||||
#
|
||||
# Note: this will only update remote branches (i.e. origin/*)
|
||||
def update_from_source!
|
||||
repo.git.fetch({}, :origin)
|
||||
repo.git.fetch({timeout: true}, :origin)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue