2012-10-26 00:10:40 +02:00
|
|
|
module Gitlab
|
|
|
|
module Satellite
|
|
|
|
class Action
|
|
|
|
DEFAULT_OPTIONS = { git_timeout: 30.seconds }
|
|
|
|
|
2012-10-26 00:24:02 +02:00
|
|
|
attr_accessor :options, :project, :user
|
2012-10-26 00:10:40 +02:00
|
|
|
|
2012-10-26 00:26:47 +02:00
|
|
|
def initialize(user, project, options = {})
|
|
|
|
@options = DEFAULT_OPTIONS.merge(options)
|
2012-10-26 00:10:40 +02:00
|
|
|
@project = project
|
2012-10-26 00:24:02 +02:00
|
|
|
@user = user
|
2012-10-26 00:10:40 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
# * Sets a 30s timeout for Git
|
|
|
|
# * Locks the satellite repo
|
|
|
|
# * Yields the prepared satellite repo
|
|
|
|
def in_locked_and_timed_satellite
|
|
|
|
Grit::Git.with_timeout(options[:git_timeout]) do
|
2012-10-26 01:44:20 +02:00
|
|
|
project.satellite.lock do
|
|
|
|
return yield project.satellite.repo
|
2012-10-26 00:10:40 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
rescue Errno::ENOMEM => ex
|
|
|
|
Gitlab::GitLogger.error(ex.message)
|
|
|
|
return false
|
|
|
|
rescue Grit::Git::GitTimeout => ex
|
|
|
|
Gitlab::GitLogger.error(ex.message)
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2012-10-26 00:24:02 +02:00
|
|
|
# * Clears the satellite
|
|
|
|
# * Updates the satellite from Gitolite
|
|
|
|
# * Sets up Git variables for the user
|
|
|
|
#
|
|
|
|
# Note: use this within #in_locked_and_timed_satellite
|
|
|
|
def prepare_satellite!(repo)
|
2012-10-26 01:32:33 +02:00
|
|
|
project.satellite.clear_and_update!
|
2012-10-26 00:24:02 +02:00
|
|
|
|
|
|
|
repo.git.config({}, "user.name", user.name)
|
|
|
|
repo.git.config({}, "user.email", user.email)
|
|
|
|
end
|
2012-10-26 00:10:40 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|