summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xhooks/update13
-rw-r--r--lib/gitlab_update.rb58
-rw-r--r--spec/gitlab_projects_spec.rb3
-rw-r--r--spec/gitlab_update_spec.rb25
-rw-r--r--spec/names_helper_spec.rb2
5 files changed, 3 insertions, 98 deletions
diff --git a/hooks/update b/hooks/update
deleted file mode 100755
index 6f762e8..0000000
--- a/hooks/update
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/usr/bin/env ruby
-
-# This file was placed here by GitLab. It makes sure that your pushed commits
-# will be processed properly.
-# You can add your own hooks to this file, but be careful when updating gitlab-shell!
-
-refname = ARGV[0]
-key_id = ENV['GL_ID']
-repo_path = Dir.pwd
-
-require_relative '../lib/gitlab_update'
-
-GitlabUpdate.new(repo_path, key_id, refname).exec
diff --git a/lib/gitlab_update.rb b/lib/gitlab_update.rb
deleted file mode 100644
index cd7a1e5..0000000
--- a/lib/gitlab_update.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-require_relative 'gitlab_init'
-require_relative 'gitlab_net'
-require_relative 'names_helper'
-require 'json'
-
-class GitlabUpdate
- include NamesHelper
-
- attr_reader :config, :repo_path, :repo_name,
- :ref, :ref_name, :oldrev, :newrev
-
- def initialize(repo_path, actor, ref)
- @config = GitlabConfig.new
- @repo_path, @actor, @ref = repo_path.strip, actor, ref
- @repo_name = extract_repo_name(@repo_path.dup, config.repos_path.to_s)
- @ref_name = extract_ref_name(ref)
- @oldrev = ARGV[1]
- @newrev = ARGV[2]
- end
-
- def forced_push?
- if @oldrev !~ /00000000/ && @newrev !~ /00000000/
- missed_refs = IO.popen(%W(git rev-list #{@oldrev} ^#{@newrev})).read
- missed_refs.split("\n").size > 0
- else
- false
- end
- end
-
- def exec
- # reset GL_ID env since we already
- # get value from it
- ENV['GL_ID'] = nil
-
- if api.allowed?('git-receive-pack', @repo_name, @actor, @ref_name, @oldrev, @newrev, forced_push?)
- update_redis
- exit 0
- else
- puts "GitLab: You are not allowed to access #{@ref_name}!"
- exit 1
- end
- end
-
- protected
-
- def api
- GitlabNet.new
- end
-
- def update_redis
- queue = "#{config.redis_namespace}:queue:post_receive"
- msg = JSON.dump({'class' => 'PostReceive', 'args' => [@repo_path, @oldrev, @newrev, @ref, @actor]})
- unless system(*config.redis_command, 'rpush', queue, msg, err: '/dev/null', out: '/dev/null')
- puts "GitLab: An unexpected error occurred (redis-cli returned #{$?.exitstatus})."
- exit 1
- end
- end
-end
diff --git a/spec/gitlab_projects_spec.rb b/spec/gitlab_projects_spec.rb
index 3101b0b..0060fa9 100644
--- a/spec/gitlab_projects_spec.rb
+++ b/spec/gitlab_projects_spec.rb
@@ -295,7 +295,8 @@ describe GitlabProjects do
FileUtils.mkdir_p(File.join(tmp_repos_path, 'forked-to-namespace'))
gl_projects_fork.exec.should be_true
File.exists?(dest_repo).should be_true
- File.exists?(File.join(dest_repo, '/hooks/update')).should be_true
+ File.exists?(File.join(dest_repo, '/hooks/pre-receive')).should be_true
+ File.exists?(File.join(dest_repo, '/hooks/post-receive')).should be_true
end
it "should not fork if a project of the same name already exists" do
diff --git a/spec/gitlab_update_spec.rb b/spec/gitlab_update_spec.rb
deleted file mode 100644
index 580d8c9..0000000
--- a/spec/gitlab_update_spec.rb
+++ /dev/null
@@ -1,25 +0,0 @@
-require 'spec_helper'
-require 'gitlab_update'
-
-describe GitlabUpdate do
- let(:repository_path) { "/home/git/repositories" }
- let(:repo_name) { 'dzaporozhets/gitlab-ci' }
- let(:repo_path) { File.join(repository_path, repo_name) + ".git" }
- let(:ref) { 'refs/heads/awesome-feature' }
- let(:gitlab_update) { GitlabUpdate.new(repo_path, 'key-123', ref) }
-
- before do
- ARGV[1] = 'd1e3ca3b25'
- ARGV[2] = 'c2b3653b25'
- GitlabConfig.any_instance.stub(repos_path: repository_path)
- end
-
- describe :initialize do
- it { gitlab_update.repo_name.should == repo_name }
- it { gitlab_update.repo_path.should == repo_path }
- it { gitlab_update.ref.should == ref }
- it { gitlab_update.ref_name.should == 'awesome-feature' }
- it { gitlab_update.oldrev.should == 'd1e3ca3b25' }
- it { gitlab_update.newrev.should == 'c2b3653b25' }
- end
-end
diff --git a/spec/names_helper_spec.rb b/spec/names_helper_spec.rb
index db2a692..081dac9 100644
--- a/spec/names_helper_spec.rb
+++ b/spec/names_helper_spec.rb
@@ -1,5 +1,5 @@
require 'spec_helper'
-require 'gitlab_update'
+require 'names_helper'
describe NamesHelper do
include NamesHelper