Commit 08f94e6c authored by Robert Speicher's avatar Robert Speicher

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
parents f532377f a228ac75
v2.6.7
- Exit with non-zero status when import-repository fails
- Add fetch-remote command
v2.6.6 v2.6.6
- Do not clean LANG environment variable for the git hooks when working through the SSH-protocol - Do not clean LANG environment variable for the git hooks when working through the SSH-protocol
- Add git-lfs-authenticate command to white list (this command is used by git-lfs for SSO authentication through SSH-protocol) - Add git-lfs-authenticate command to white list (this command is used by git-lfs for SSO authentication through SSH-protocol)
......
...@@ -59,6 +59,7 @@ class GitlabProjects ...@@ -59,6 +59,7 @@ class GitlabProjects
when 'mv-project'; mv_project when 'mv-project'; mv_project
when 'import-project'; import_project when 'import-project'; import_project
when 'fork-project'; fork_project when 'fork-project'; fork_project
when 'fetch-remote'; fetch_remote
when 'update-head'; update_head when 'update-head'; update_head
else else
$logger.warn "Attempt to execute invalid gitlab-projects command #{@command.inspect}." $logger.warn "Attempt to execute invalid gitlab-projects command #{@command.inspect}."
...@@ -128,6 +129,30 @@ class GitlabProjects ...@@ -128,6 +129,30 @@ class GitlabProjects
url url
end 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 def remove_origin_in_repo
cmd = %W(git --git-dir=#{full_path} remote rm origin) cmd = %W(git --git-dir=#{full_path} remote rm origin)
pid = Process.spawn(*cmd) pid = Process.spawn(*cmd)
...@@ -154,19 +179,23 @@ class GitlabProjects ...@@ -154,19 +179,23 @@ class GitlabProjects
Timeout.timeout(timeout) do Timeout.timeout(timeout) do
Process.wait(pid) Process.wait(pid)
end end
return false unless $?.exitstatus.zero?
rescue Timeout::Error rescue Timeout::Error
$logger.error "Importing project #{@project_name} from <#{masked_source}> failed due to timeout." $logger.error "Importing project #{@project_name} from <#{masked_source}> failed due to timeout."
Process.kill('KILL', pid) Process.kill('KILL', pid)
Process.wait Process.wait
FileUtils.rm_rf(full_path) FileUtils.rm_rf(full_path)
false return false
else end
self.class.create_hooks(full_path) self.class.create_hooks(full_path)
# The project was imported successfully. # The project was imported successfully.
# Remove the origin URL since it may contain password. # Remove the origin URL since it may contain password.
remove_origin_in_repo remove_origin_in_repo
end
true
end end
# Move repository from one directory to another # Move repository from one directory to another
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment