Commit 510506c1 authored by GitLab Bot's avatar GitLab Bot

Merge remote-tracking branch 'upstream/master' into ce-to-ee-2018-01-10

parents 6dc2e23c be623ef3
...@@ -422,7 +422,7 @@ group :ed25519 do ...@@ -422,7 +422,7 @@ group :ed25519 do
end end
# Gitaly GRPC client # Gitaly GRPC client
gem 'gitaly-proto', '~> 0.64.0', require: 'gitaly' gem 'gitaly-proto', '~> 0.69.0', require: 'gitaly'
gem 'toml-rb', '~> 0.3.15', require: false gem 'toml-rb', '~> 0.3.15', require: false
......
...@@ -308,7 +308,7 @@ GEM ...@@ -308,7 +308,7 @@ GEM
po_to_json (>= 1.0.0) po_to_json (>= 1.0.0)
rails (>= 3.2.0) rails (>= 3.2.0)
gherkin-ruby (0.3.2) gherkin-ruby (0.3.2)
gitaly-proto (0.64.0) gitaly-proto (0.69.0)
google-protobuf (~> 3.1) google-protobuf (~> 3.1)
grpc (~> 1.0) grpc (~> 1.0)
github-linguist (4.7.6) github-linguist (4.7.6)
...@@ -1088,7 +1088,7 @@ DEPENDENCIES ...@@ -1088,7 +1088,7 @@ DEPENDENCIES
gettext (~> 3.2.2) gettext (~> 3.2.2)
gettext_i18n_rails (~> 1.8.0) gettext_i18n_rails (~> 1.8.0)
gettext_i18n_rails_js (~> 1.2.0) gettext_i18n_rails_js (~> 1.2.0)
gitaly-proto (~> 0.64.0) gitaly-proto (~> 0.69.0)
github-linguist (~> 4.7.0) github-linguist (~> 4.7.0)
gitlab-flowdock-git-hook (~> 1.0.1) gitlab-flowdock-git-hook (~> 1.0.1)
gitlab-license (~> 1.0) gitlab-license (~> 1.0)
......
...@@ -110,6 +110,10 @@ class Repository ...@@ -110,6 +110,10 @@ class Repository
"#<#{self.class.name}:#{@disk_path}>" "#<#{self.class.name}:#{@disk_path}>"
end end
def create_hooks
Gitlab::Git::Repository.create_hooks(path_to_repo, Gitlab.config.gitlab_shell.hooks_path)
end
def commit(ref = 'HEAD') def commit(ref = 'HEAD')
return nil unless exists? return nil unless exists?
return ref if ref.is_a?(::Commit) return ref if ref.is_a?(::Commit)
......
---
title: Fix hooks not being set up properly for bare import Rake task
merge_request:
author:
type: fixed
...@@ -16,7 +16,8 @@ codequality: ...@@ -16,7 +16,8 @@ codequality:
- docker:dind - docker:dind
script: script:
- docker pull codeclimate/codeclimate - docker pull codeclimate/codeclimate
- docker run --env CODECLIMATE_CODE="$PWD" --volume "$PWD":/code --volume /var/run/docker.sock:/var/run/docker.sock --volume /tmp/cc:/tmp/cc codeclimate/codeclimate analyze -f json > codeclimate.json || true - docker run --env CODECLIMATE_CODE="$PWD" --volume "$PWD":/code --volume /var/run/docker.sock:/var/run/docker.sock --volume /tmp/cc:/tmp/cc codeclimate/codeclimate:0.69.0 init
- docker run --env CODECLIMATE_CODE="$PWD" --volume "$PWD":/code --volume /var/run/docker.sock:/var/run/docker.sock --volume /tmp/cc:/tmp/cc codeclimate/codeclimate:0.69.0 analyze -f json > codeclimate.json || true
artifacts: artifacts:
paths: [codeclimate.json] paths: [codeclimate.json]
``` ```
......
...@@ -63,6 +63,7 @@ module Gitlab ...@@ -63,6 +63,7 @@ module Gitlab
log " * Created #{project.name} (#{project_full_path})".color(:green) log " * Created #{project.name} (#{project_full_path})".color(:green)
project.write_repository_config project.write_repository_config
project.repository.create_hooks
ProjectCacheWorker.perform_async(project.id) ProjectCacheWorker.perform_async(project.id)
else else
......
...@@ -41,36 +41,6 @@ module Gitlab ...@@ -41,36 +41,6 @@ module Gitlab
io.read io.read
end end
def rm_project
logger.info "Removing repository <#{repository_absolute_path}>."
FileUtils.rm_rf(repository_absolute_path)
end
# Move repository from one directory to another
#
# Example: gitlab/gitlab-ci.git -> randx/six.git
#
# Won't work if target namespace directory does not exist
#
def mv_project(new_path)
new_absolute_path = File.join(shard_path, new_path)
# verify that the source repo exists
unless File.exist?(repository_absolute_path)
logger.error "mv-project failed: source path <#{repository_absolute_path}> does not exist."
return false
end
# ...and that the target repo does not exist
if File.exist?(new_absolute_path)
logger.error "mv-project failed: destination path <#{new_absolute_path}> already exists."
return false
end
logger.info "Moving repository from <#{repository_absolute_path}> to <#{new_absolute_path}>."
FileUtils.mv(repository_absolute_path, new_absolute_path)
end
# Import project via git clone --bare # Import project via git clone --bare
# URL must be publicly cloneable # URL must be publicly cloneable
def import_project(source, timeout) def import_project(source, timeout)
......
...@@ -7,10 +7,12 @@ module Gitlab ...@@ -7,10 +7,12 @@ module Gitlab
@storage = repository.storage @storage = repository.storage
end end
def add_remote(name, url, mirror_refmap) def add_remote(name, url, mirror_refmaps)
request = Gitaly::AddRemoteRequest.new( request = Gitaly::AddRemoteRequest.new(
repository: @gitaly_repo, name: name, url: url, repository: @gitaly_repo,
mirror_refmap: mirror_refmap.to_s name: name,
url: url,
mirror_refmaps: Array.wrap(mirror_refmaps).map(&:to_s)
) )
GitalyClient.call(@storage, :remote_service, :add_remote, request) GitalyClient.call(@storage, :remote_service, :add_remote, request)
......
...@@ -136,7 +136,10 @@ module Gitlab ...@@ -136,7 +136,10 @@ module Gitlab
end end
end end
# Move repository # Move repository reroutes to mv_directory which is an alias for
# mv_namespace. Given the underlying implementation is a move action,
# indescriminate of what the folders might be.
#
# storage - project's storage path # storage - project's storage path
# path - project disk path # path - project disk path
# new_path - new project disk path # new_path - new project disk path
...@@ -146,7 +149,9 @@ module Gitlab ...@@ -146,7 +149,9 @@ module Gitlab
# #
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/873 # Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/873
def mv_repository(storage, path, new_path) def mv_repository(storage, path, new_path)
gitlab_projects(storage, "#{path}.git").mv_project("#{new_path}.git") return false if path.empty? || new_path.empty?
!!mv_directory(storage, "#{path}.git", "#{new_path}.git")
end end
# Fork repository to new path # Fork repository to new path
...@@ -164,7 +169,9 @@ module Gitlab ...@@ -164,7 +169,9 @@ module Gitlab
.fork_repository(forked_to_storage, "#{forked_to_disk_path}.git") .fork_repository(forked_to_storage, "#{forked_to_disk_path}.git")
end end
# Remove repository from file system # Removes a repository from file system, using rm_diretory which is an alias
# for rm_namespace. Given the underlying implementation removes the name
# passed as second argument on the passed storage.
# #
# storage - project's storage path # storage - project's storage path
# name - project disk path # name - project disk path
...@@ -174,7 +181,12 @@ module Gitlab ...@@ -174,7 +181,12 @@ module Gitlab
# #
# Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/873 # Gitaly migration: https://gitlab.com/gitlab-org/gitaly/issues/873
def remove_repository(storage, name) def remove_repository(storage, name)
gitlab_projects(storage, "#{name}.git").rm_project return false if name.empty?
!!rm_directory(storage, "#{name}.git")
rescue ArgumentError => e
Rails.logger.warn("Repository does not exist: #{e} at: #{name}.git")
false
end end
# Add new key to gitlab-shell # Add new key to gitlab-shell
...@@ -313,6 +325,7 @@ module Gitlab ...@@ -313,6 +325,7 @@ module Gitlab
rescue GRPC::InvalidArgument => e rescue GRPC::InvalidArgument => e
raise ArgumentError, e.message raise ArgumentError, e.message
end end
alias_method :rm_directory, :rm_namespace
# Move namespace directory inside repositories storage # Move namespace directory inside repositories storage
# #
...@@ -332,6 +345,7 @@ module Gitlab ...@@ -332,6 +345,7 @@ module Gitlab
rescue GRPC::InvalidArgument rescue GRPC::InvalidArgument
false false
end end
alias_method :mv_directory, :mv_namespace
def url_to_repo(path) def url_to_repo(path)
Gitlab.config.gitlab_shell.ssh_path_prefix + "#{path}.git" Gitlab.config.gitlab_shell.ssh_path_prefix + "#{path}.git"
......
...@@ -74,14 +74,18 @@ describe Gitlab::BareRepositoryImport::Importer, repository: true do ...@@ -74,14 +74,18 @@ describe Gitlab::BareRepositoryImport::Importer, repository: true do
importer.create_project_if_needed importer.create_project_if_needed
end end
it 'creates the Git repo in disk' do it 'creates the Git repo on disk with the proper symlink for hooks' do
create_bare_repository("#{project_path}.git") create_bare_repository("#{project_path}.git")
importer.create_project_if_needed importer.create_project_if_needed
project = Project.find_by_full_path(project_path) project = Project.find_by_full_path(project_path)
repo_path = File.join(project.repository_storage_path, project.disk_path + '.git')
hook_path = File.join(repo_path, 'hooks')
expect(File).to exist(File.join(project.repository_storage_path, project.disk_path + '.git')) expect(File).to exist(repo_path)
expect(File.symlink?(hook_path)).to be true
expect(File.readlink(hook_path)).to eq(Gitlab.config.gitlab_shell.hooks_path)
end end
context 'hashed storage enabled' do context 'hashed storage enabled' do
......
...@@ -25,51 +25,6 @@ describe Gitlab::Git::GitlabProjects do ...@@ -25,51 +25,6 @@ describe Gitlab::Git::GitlabProjects do
it { expect(gl_projects.logger).to eq(logger) } it { expect(gl_projects.logger).to eq(logger) }
end end
describe '#mv_project' do
let(:new_repo_path) { File.join(tmp_repos_path, 'repo.git') }
it 'moves a repo directory' do
expect(File.exist?(tmp_repo_path)).to be_truthy
message = "Moving repository from <#{tmp_repo_path}> to <#{new_repo_path}>."
expect(logger).to receive(:info).with(message)
expect(gl_projects.mv_project('repo.git')).to be_truthy
expect(File.exist?(tmp_repo_path)).to be_falsy
expect(File.exist?(new_repo_path)).to be_truthy
end
it "fails if the source path doesn't exist" do
expected_source_path = File.join(tmp_repos_path, 'bad-src.git')
expect(logger).to receive(:error).with("mv-project failed: source path <#{expected_source_path}> does not exist.")
result = build_gitlab_projects(tmp_repos_path, 'bad-src.git').mv_project('repo.git')
expect(result).to be_falsy
end
it 'fails if the destination path already exists' do
FileUtils.mkdir_p(File.join(tmp_repos_path, 'already-exists.git'))
expected_distination_path = File.join(tmp_repos_path, 'already-exists.git')
message = "mv-project failed: destination path <#{expected_distination_path}> already exists."
expect(logger).to receive(:error).with(message)
expect(gl_projects.mv_project('already-exists.git')).to be_falsy
end
end
describe '#rm_project' do
it 'removes a repo directory' do
expect(File.exist?(tmp_repo_path)).to be_truthy
expect(logger).to receive(:info).with("Removing repository <#{tmp_repo_path}>.")
expect(gl_projects.rm_project).to be_truthy
expect(File.exist?(tmp_repo_path)).to be_falsy
end
end
describe '#push_branches' do describe '#push_branches' do
let(:remote_name) { 'remote-name' } let(:remote_name) { 'remote-name' }
let(:branch_name) { 'master' } let(:branch_name) { 'master' }
......
...@@ -443,32 +443,44 @@ describe Gitlab::Shell do ...@@ -443,32 +443,44 @@ describe Gitlab::Shell do
end end
describe '#remove_repository' do describe '#remove_repository' do
subject { gitlab_shell.remove_repository(project.repository_storage_path, project.disk_path) } let!(:project) { create(:project, :repository) }
let(:disk_path) { "#{project.disk_path}.git" }
it 'returns true when the command succeeds' do it 'returns true when the command succeeds' do
expect(gitlab_projects).to receive(:rm_project) { true } expect(gitlab_shell.exists?(project.repository_storage_path, disk_path)).to be(true)
is_expected.to be_truthy expect(gitlab_shell.remove_repository(project.repository_storage_path, project.disk_path)).to be(true)
expect(gitlab_shell.exists?(project.repository_storage_path, disk_path)).to be(false)
end end
it 'returns false when the command fails' do it 'keeps the namespace directory' do
expect(gitlab_projects).to receive(:rm_project) { false } gitlab_shell.remove_repository(project.repository_storage_path, project.disk_path)
is_expected.to be_falsy expect(gitlab_shell.exists?(project.repository_storage_path, disk_path)).to be(false)
expect(gitlab_shell.exists?(project.repository_storage_path, project.disk_path.gsub(project.name, ''))).to be(true)
end end
end end
describe '#mv_repository' do describe '#mv_repository' do
let!(:project2) { create(:project, :repository) }
it 'returns true when the command succeeds' do it 'returns true when the command succeeds' do
expect(gitlab_projects).to receive(:mv_project).with('project/newpath.git') { true } old_path = project2.disk_path
new_path = "project/new_path"
expect(gitlab_shell.exists?(project2.repository_storage_path, "#{old_path}.git")).to be(true)
expect(gitlab_shell.exists?(project2.repository_storage_path, "#{new_path}.git")).to be(false)
expect(gitlab_shell.mv_repository(project.repository_storage_path, project.disk_path, 'project/newpath')).to be_truthy expect(gitlab_shell.mv_repository(project2.repository_storage_path, old_path, new_path)).to be_truthy
expect(gitlab_shell.exists?(project2.repository_storage_path, "#{old_path}.git")).to be(false)
expect(gitlab_shell.exists?(project2.repository_storage_path, "#{new_path}.git")).to be(true)
end end
it 'returns false when the command fails' do it 'returns false when the command fails' do
expect(gitlab_projects).to receive(:mv_project).with('project/newpath.git') { false } expect(gitlab_shell.mv_repository(project2.repository_storage_path, project2.disk_path, '')).to be_falsy
expect(gitlab_shell.exists?(project2.repository_storage_path, "#{project2.disk_path}.git")).to be(true)
expect(gitlab_shell.mv_repository(project.repository_storage_path, project.disk_path, 'project/newpath')).to be_falsy
end end
end end
......
...@@ -412,6 +412,28 @@ describe Repository do ...@@ -412,6 +412,28 @@ describe Repository do
end end
end end
describe '#create_hooks' do
let(:hook_path) { File.join(repository.path_to_repo, 'hooks') }
it 'symlinks the global hooks directory' do
repository.create_hooks
expect(File.symlink?(hook_path)).to be true
expect(File.readlink(hook_path)).to eq(Gitlab.config.gitlab_shell.hooks_path)
end
it 'replaces existing symlink with the right directory' do
FileUtils.mkdir_p(hook_path)
expect(File.symlink?(hook_path)).to be false
repository.create_hooks
expect(File.symlink?(hook_path)).to be true
expect(File.readlink(hook_path)).to eq(Gitlab.config.gitlab_shell.hooks_path)
end
end
describe "#create_dir" do describe "#create_dir" do
it "commits a change that creates a new directory" do it "commits a change that creates a new directory" do
expect do expect do
......
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