summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2015-11-17 15:48:53 +0000
committerRobert Speicher <robert@gitlab.com>2015-11-17 15:48:53 +0000
commit08f94e6cca568243a3764b8f79d6441d1b5fe456 (patch)
tree0d1ab20a7133f112c189a47ec8f9b70e9e7f56bb
parentf532377f9a183654bb2cd6c37134eaf24f64cbca (diff)
parenta228ac7573f84daf72a9ba65d9ba704675d798b3 (diff)
downloadgitlab-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
-rw-r--r--CHANGELOG12
-rw-r--r--lib/gitlab_projects.rb41
2 files changed, 43 insertions, 10 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 1fa2c5d..abfa7e0 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,7 @@
+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+
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