Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <zegerjan@gitlab.com>2018-05-15 15:27:29 +0300
committerJacob Vosmaer (out of office May 10-14) <jacob@gitlab.com>2018-05-15 15:27:29 +0300
commite327cf40d0b6849afcb36778cdf025dae501f2b6 (patch)
tree92727cdc5fd76493914797efc247a02f8365bb60
parentb53f7e16de877560bce3f9921f7104ccb77b612e (diff)
Unvendor Repository#create implementation
-rw-r--r--CHANGELOG.md2
-rw-r--r--internal/service/repository/create_test.go25
-rw-r--r--ruby/lib/gitaly_server/repository_service.rb2
-rw-r--r--ruby/lib/gitlab/git/repository.rb55
4 files changed, 75 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0f091eac8..9967b902a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
UNRELEASED
+- Unvendor Repository#create implementation
+ https://gitlab.com/gitlab-org/gitaly/merge_requests/713
- Add gitaly-ruby installation debug log messages
https://gitlab.com/gitlab-org/gitaly/merge_requests/710
diff --git a/internal/service/repository/create_test.go b/internal/service/repository/create_test.go
index cfb4ce94b..5f2e6f6fb 100644
--- a/internal/service/repository/create_test.go
+++ b/internal/service/repository/create_test.go
@@ -63,6 +63,31 @@ func TestCreateRepositoryFailure(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
+ storagePath, err := helper.GetStorageByName("default")
+ require.NoError(t, err)
+ fullPath := path.Join(storagePath, "foo.git")
+
+ _, err = os.Create(fullPath)
+ require.NoError(t, err)
+ defer os.RemoveAll(fullPath)
+
+ _, err = client.CreateRepository(ctx, &pb.CreateRepositoryRequest{
+ Repository: &pb.Repository{StorageName: "default", RelativePath: "foo.git"},
+ })
+
+ testhelper.AssertGrpcError(t, err, codes.Unknown, "")
+}
+
+func TestCreateRepositoryFailureInvalidArgs(t *testing.T) {
+ server, serverSocketPath := runRepoServer(t)
+ defer server.Stop()
+
+ client, conn := newRepositoryClient(t, serverSocketPath)
+ defer conn.Close()
+
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
testCases := []struct {
repo *pb.Repository
code codes.Code
diff --git a/ruby/lib/gitaly_server/repository_service.rb b/ruby/lib/gitaly_server/repository_service.rb
index 934870bb9..48ee81a1a 100644
--- a/ruby/lib/gitaly_server/repository_service.rb
+++ b/ruby/lib/gitaly_server/repository_service.rb
@@ -8,7 +8,7 @@ module GitalyServer
bridge_exceptions do
repo_path = GitalyServer.repo_path(call)
- Gitlab::Git::Repository.create(repo_path, bare: true, symlink_hooks_to: Gitlab.config.gitlab_shell.hooks_path)
+ Gitlab::Git::Repository.create(repo_path)
Gitaly::CreateRepositoryResponse.new
end
diff --git a/ruby/lib/gitlab/git/repository.rb b/ruby/lib/gitlab/git/repository.rb
index f82bed70e..35a8b2acc 100644
--- a/ruby/lib/gitlab/git/repository.rb
+++ b/ruby/lib/gitlab/git/repository.rb
@@ -2,14 +2,53 @@ module Gitlab
module Git
# These are monkey patches on top of the vendored version of Repository.
class Repository
- def self.from_gitaly(gitaly_repository, call)
- new(
- gitaly_repository,
- GitalyServer.repo_path(call),
- GitalyServer.gl_repository(call),
- Gitlab::Git::GitlabProjects.from_gitaly(gitaly_repository, call),
- GitalyServer.repo_alt_dirs(call)
- )
+ class << self
+ def from_gitaly(gitaly_repository, call)
+ new(
+ gitaly_repository,
+ GitalyServer.repo_path(call),
+ GitalyServer.gl_repository(call),
+ Gitlab::Git::GitlabProjects.from_gitaly(gitaly_repository, call),
+ GitalyServer.repo_alt_dirs(call)
+ )
+ end
+
+ def create(repo_path)
+ FileUtils.mkdir_p(repo_path, mode: 0770)
+
+ # Equivalent to `git --git-path=#{repo_path} init [--bare]`
+ repo = Rugged::Repository.init_at(repo_path, true)
+ repo.close
+
+ symlink_hooks_to = Gitlab.config.gitlab_shell.hooks_path
+ create_hooks(repo_path, symlink_hooks_to) if symlink_hooks_to.present?
+ end
+
+ def create_hooks(repo_path, global_hooks_path)
+ local_hooks_path = File.join(repo_path, 'hooks')
+ real_local_hooks_path = :not_found
+
+ begin
+ real_local_hooks_path = File.realpath(local_hooks_path)
+ rescue Errno::ENOENT
+ # real_local_hooks_path == :not_found
+ end
+
+ # Do nothing if hooks already exist
+ unless real_local_hooks_path == File.realpath(global_hooks_path)
+ if File.exist?(local_hooks_path)
+ # Move the existing hooks somewhere safe
+ FileUtils.mv(
+ local_hooks_path,
+ "#{local_hooks_path}.old.#{Time.now.to_i}")
+ end
+
+ # Create the hooks symlink
+ FileUtils.ln_sf(global_hooks_path, local_hooks_path)
+ end
+
+ true
+ end
end
attr_reader :path