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