diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-11-11 16:43:13 +0100 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-11-11 16:43:43 +0100 |
commit | b37608b76833cf7cf97d14748f618317b6b67fcc (patch) | |
tree | e1cb808c173a1dfde989972f3016e61b9c4d6e37 | |
parent | 4599d6430b2a20df653c3b0428898951563850f1 (diff) | |
download | gitlab-shell-b37608b76833cf7cf97d14748f618317b6b67fcc.tar.gz |
Add fetch-remote command
-rw-r--r-- | lib/gitlab_projects.rb | 25 |
1 files changed, 25 insertions, 0 deletions
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) |