diff options
author | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-02-05 12:16:06 +0300 |
---|---|---|
committer | Zeger-Jan van de Weg <git@zjvandeweg.nl> | 2019-05-10 17:10:12 +0300 |
commit | 02517d1a7b527efe6b5a418971f3e0e1a1fde077 (patch) | |
tree | 753cd3b2408cd718884493f73b218d0e3f0e1b7b /ruby | |
parent | 6f8f5ae53799e8275ed1f83a99cdaa96467125b2 (diff) |
Stop symlinking hooks on repository creation
In an earlier MR[1] hooks are executed not through the symlink, but
leveraging the `-c` flag on the `git` binary. This works well, but when
`#run_git` was executed in Gitaly-Ruby the hooks weren't executed the
new way.
Luckily this was covered by tests, and the symlinking strategy remained
employed. This commit fixes the bug where the hooks weren't executed and
now allows the removal of the code that set the hooks.
Part of: #1226
[1]: !886
Diffstat (limited to 'ruby')
-rw-r--r-- | ruby/lib/gitlab/git/repository.rb | 31 | ||||
-rw-r--r-- | ruby/spec/lib/gitlab/git/repository_spec.rb | 47 |
2 files changed, 0 insertions, 78 deletions
diff --git a/ruby/lib/gitlab/git/repository.rb b/ruby/lib/gitlab/git/repository.rb index 73373a0a9..f511b3ef6 100644 --- a/ruby/lib/gitlab/git/repository.rb +++ b/ruby/lib/gitlab/git/repository.rb @@ -61,37 +61,6 @@ module Gitlab # Equivalent to `git --git-path=#{repo_path} init [--bare]` repo = Rugged::Repository.init_at(repo_path, true) repo.close - - # TODO: stop symlinking to the old hooks location in or after GitLab 12.0. - # https://gitlab.com/gitlab-org/gitaly/issues/1392 - create_hooks(repo_path, Gitlab::Git::Hook.legacy_hooks_directory) - 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 diff --git a/ruby/spec/lib/gitlab/git/repository_spec.rb b/ruby/spec/lib/gitlab/git/repository_spec.rb index 962be8fc6..57b88ef59 100644 --- a/ruby/spec/lib/gitlab/git/repository_spec.rb +++ b/ruby/spec/lib/gitlab/git/repository_spec.rb @@ -37,53 +37,6 @@ describe Gitlab::Git::Repository do # rubocop:disable Metrics/BlockLength end end - describe '.create_hooks' do - let(:repo_path) { File.join(storage_path, 'hook-test.git') } - let(:hooks_dir) { File.join(repo_path, 'hooks') } - let(:target_hooks_dir) { Gitlab::Git::Hook.legacy_hooks_directory } - let(:existing_target) { File.join(repo_path, 'foobar') } - - before do - GitlabShellHelper.setup_gitlab_shell - - FileUtils.rm_rf(repo_path) - FileUtils.mkdir_p(repo_path) - end - - context 'hooks is a directory' do - let(:existing_file) { File.join(hooks_dir, 'my-file') } - - before do - FileUtils.mkdir_p(hooks_dir) - FileUtils.touch(existing_file) - described_class.create_hooks(repo_path, target_hooks_dir) - end - - it { expect(File.readlink(hooks_dir)).to eq(target_hooks_dir) } - it { expect(Dir[File.join(repo_path, "hooks.old.*/my-file")].count).to eq(1) } - end - - context 'hooks is a valid symlink' do - before do - FileUtils.mkdir_p existing_target - File.symlink(existing_target, hooks_dir) - described_class.create_hooks(repo_path, target_hooks_dir) - end - - it { expect(File.readlink(hooks_dir)).to eq(target_hooks_dir) } - end - - context 'hooks is a broken symlink' do - before do - FileUtils.rm_f(existing_target) - File.symlink(existing_target, hooks_dir) - described_class.create_hooks(repo_path, target_hooks_dir) - end - - it { expect(File.readlink(hooks_dir)).to eq(target_hooks_dir) } - end - end - describe "Respond to" do subject { repository } |