From b37608b76833cf7cf97d14748f618317b6b67fcc Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Wed, 11 Nov 2015 16:43:13 +0100 Subject: Add fetch-remote command --- lib/gitlab_projects.rb | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'lib/gitlab_projects.rb') diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb index 53fe815..67fd298 100644 --- a/lib/gitlab_projects.rb +++ b/lib/gitlab_projects.rb @@ -59,6 +59,7 @@ class GitlabProjects when 'mv-project'; mv_project when 'import-project'; import_project when 'fork-project'; fork_project + when 'fetch-remote'; fetch_remote when 'update-head'; update_head else $logger.warn "Attempt to execute invalid gitlab-projects command #{@command.inspect}." @@ -128,6 +129,30 @@ class GitlabProjects url end + def fetch_remote + @name = ARGV.shift + + # timeout for fetch + timeout = (ARGV.shift || 120).to_i + $logger.info "Fetching remote #{@name} for project #{@project_name}." + cmd = %W(git --git-dir=#{full_path} fetch #{@name} --tags) + pid = Process.spawn(*cmd) + + begin + Timeout.timeout(timeout) do + Process.wait(pid) + end + + $?.exitstatus.zero? + rescue Timeout::Error + $logger.error "Fetching remote #{@name} for project #{@project_name} failed due to timeout." + + Process.kill('KILL', pid) + Process.wait + false + end + end + def remove_origin_in_repo cmd = %W(git --git-dir=#{full_path} remote rm origin) pid = Process.spawn(*cmd) -- cgit v1.2.1