diff options
author | Robert Speicher <robert@gitlab.com> | 2015-11-17 15:48:53 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2015-11-17 15:48:53 +0000 |
commit | 08f94e6cca568243a3764b8f79d6441d1b5fe456 (patch) | |
tree | 0d1ab20a7133f112c189a47ec8f9b70e9e7f56bb /lib | |
parent | f532377f9a183654bb2cd6c37134eaf24f64cbca (diff) | |
parent | a228ac7573f84daf72a9ba65d9ba704675d798b3 (diff) | |
download | gitlab-shell-08f94e6cca568243a3764b8f79d6441d1b5fe456.tar.gz |
Merge branch 'mirror-repository' into 'master'
Add fetch-remote command for repo mirroring
Also exits `import-repository` with non-zero status when import fails.
See merge request !29
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab_projects.rb | 41 |
1 files changed, 35 insertions, 6 deletions
diff --git a/lib/gitlab_projects.rb b/lib/gitlab_projects.rb index 8bf000d..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) @@ -154,19 +179,23 @@ class GitlabProjects Timeout.timeout(timeout) do Process.wait(pid) end + + return false unless $?.exitstatus.zero? rescue Timeout::Error $logger.error "Importing project #{@project_name} from <#{masked_source}> failed due to timeout." Process.kill('KILL', pid) Process.wait FileUtils.rm_rf(full_path) - false - else - self.class.create_hooks(full_path) - # The project was imported successfully. - # Remove the origin URL since it may contain password. - remove_origin_in_repo + return false end + + self.class.create_hooks(full_path) + # The project was imported successfully. + # Remove the origin URL since it may contain password. + remove_origin_in_repo + + true end # Move repository from one directory to another |