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
- 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)
......@@ -59,13 +63,13 @@ v2.1.0
- Use secret token with GitLab internal API. Requires GitLab 7.5 or higher
v2.0.1
- Send post-receive changes to redis as a string instead of array
- Send post-receive changes to redis as a string instead of array
v2.0.0
- Works with GitLab v7.3+
- Replace raise with abort when checking path to prevent path exposure
- Handle invalid number of arguments on remote commands
- Replace update hook with pre-receive and post-receive hooks.
- Replace update hook with pre-receive and post-receive hooks.
- Symlink the whole hooks directory
- Ignore missing repositories in create-hooks
- Connect to Redis via sockets by default
......@@ -89,10 +93,10 @@ v1.9.3
- Ignore force push detection for new branch or branch remove push
v1.9.2
- Add support for force push detection
- Add support for force push detection
v1.9.1
- Update hook sends branch and tag name
- Update hook sends branch and tag name
v1.9.0
- Call api in update hook for both ssdh and http push. Requires GitLab 6.7+
......
......@@ -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
......
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