summaryrefslogtreecommitdiff
path: root/lib/gitlab_projects.rb
diff options
context:
space:
mode:
authorSean McGivern <sean@mcgivern.me.uk>2017-03-29 16:35:15 +0000
committerSean McGivern <sean@mcgivern.me.uk>2017-03-29 16:35:15 +0000
commit3d22504d1cebecdfe778e3ee10b9a380efea80dd (patch)
tree904367e4b104eb0d72387aeb2ade6a363690d0b5 /lib/gitlab_projects.rb
parent6acaaa5824ddac516dc0d137701260f553b4619f (diff)
parent9e41159a6d2eb0d7409fe7188f8eedddbef0136b (diff)
downloadgitlab-shell-3d22504d1cebecdfe778e3ee10b9a380efea80dd.tar.gz
Merge branch 'adds-timeout-to-push-branches' into 'master' v5.0.2
adds timeout option to push branches and respective test suite See merge request !124
Diffstat (limited to 'lib/gitlab_projects.rb')
-rw-r--r--lib/gitlab_projects.rb17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb
index eec8a2b..0b11ce3 100644
--- a/lib/gitlab_projects.rb
+++ b/lib/gitlab_projects.rb
@@ -113,16 +113,21 @@ class GitlabProjects
def push_branches
remote_name = ARGV.shift
+ # timeout for push
+ timeout = (ARGV.shift || 120).to_i
+
$logger.info "Pushing branches from #{full_path} to remote #{remote_name}: #{ARGV}"
cmd = %W(git --git-dir=#{full_path} push -- #{remote_name}).concat(ARGV)
pid = Process.spawn(*cmd)
begin
- Process.wait(pid)
+ Timeout.timeout(timeout) do
+ Process.wait(pid)
+ end
$?.exitstatus.zero?
rescue => exception
- $logger.error "Pushing branches to remote #{remote_name} failed due to: #{exception.message}"
+ $logger.error "Pushing branches to remote #{remote_name} failed due to: #{exception.message}."
Process.kill('KILL', pid)
Process.wait
@@ -204,10 +209,8 @@ class GitlabProjects
tags_option = ARGV.include?('--no-tags') ? '--no-tags' : '--tags'
$logger.info "Fetching remote #{@name} for project #{@project_name}."
- cmd = %W(git --git-dir=#{full_path} fetch #{@name})
- cmd << '--prune'
+ cmd = %W(git --git-dir=#{full_path} fetch #{@name} --prune --quiet)
cmd << '--force' if forced
- cmd << '--quiet'
cmd << tags_option
pid = Process.spawn(*cmd)
@@ -217,8 +220,8 @@ class GitlabProjects
end
$?.exitstatus.zero?
- rescue Timeout::Error
- $logger.error "Fetching remote #{@name} for project #{@project_name} failed due to timeout."
+ rescue => exception
+ $logger.error "Fetching remote #{@name} for project #{@project_name} failed due to: #{exception.message}."
Process.kill('KILL', pid)
Process.wait