Skip to content

Commit e0824f1

Browse files
jacobvosmaerNick Thomas
authored andcommitted
Remove hooks, they belong to Gitaly now
1 parent 433cc96 commit e0824f1

File tree

11 files changed

+11
-998
lines changed

11 files changed

+11
-998
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ An overview of the four cases described above:
2020

2121
## Git hooks
2222

23-
For historical reasons the gitlab-shell repository also contains the
23+
The gitlab-shell repository used to also contain the
2424
Git hooks that allow GitLab to validate Git pushes (e.g. "is this user
2525
allowed to push to this protected branch"). These hooks also trigger
2626
events in GitLab (e.g. to start a CI pipeline after a push).
@@ -30,17 +30,13 @@ require direct disk access to Git repositories, and that is only
3030
possible on Gitaly servers. It makes no sense to have to install
3131
gitlab-shell on Gitaly servers.
3232

33-
As of GitLab 11.9 [the actual Git hooks are in the Gitaly
33+
As of GitLab 11.10 [the actual Git hooks are in the Gitaly
3434
repository](https://gitlab.com/gitlab-org/gitaly/tree/v1.22.0/ruby/vendor/gitlab-shell/hooks),
3535
but gitlab-shell must still be installed on Gitaly servers because the
3636
hooks rely on configuration data (e.g. the GitLab internal API URL) that
3737
is not yet available in Gitaly itself. Also see the [transition
3838
plan](https://gitlab.com/gitlab-org/gitaly/issues/1226#note_126519133).
3939

40-
This means that for GitLab 11.9 and up, it is pointless to make changes
41-
to Git hook code in the gitlab-shell repository, because the code that
42-
gets run is in the Gitaly repository instead.
43-
4440
## Code status
4541

4642
[![pipeline status](https://gitlab.com/gitlab-org/gitlab-shell/badges/master/pipeline.svg)](https://gitlab.com/gitlab-org/gitlab-shell/commits/master)

hooks/post-receive

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,4 @@
1-
#!/usr/bin/env ruby
1+
#!/bin/sh
2+
echo "The gitlab-shell hooks have been migrated to Gitaly, see https://gitlab.com/gitlab-org/gitaly/issues/1226"
3+
exit 1
24

3-
# This file was placed here by GitLab. It makes sure that your pushed commits
4-
# will be processed properly.
5-
6-
refs = $stdin.read
7-
key_id = ENV.delete('GL_ID')
8-
gl_repository = ENV['GL_REPOSITORY']
9-
repo_path = Dir.pwd
10-
11-
require_relative '../lib/gitlab_custom_hook'
12-
require_relative '../lib/hooks_utils'
13-
require_relative '../lib/gitlab_post_receive'
14-
15-
push_options = HooksUtils.get_push_options
16-
17-
if GitlabPostReceive.new(gl_repository, repo_path, key_id, refs, push_options).exec &&
18-
GitlabCustomHook.new(repo_path, key_id).post_receive(refs)
19-
exit 0
20-
else
21-
exit 1
22-
end

hooks/pre-receive

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,4 @@
1-
#!/usr/bin/env ruby
1+
#!/bin/sh
2+
echo "The gitlab-shell hooks have been migrated to Gitaly, see https://gitlab.com/gitlab-org/gitaly/issues/1226"
3+
exit 1
24

3-
# This file was placed here by GitLab. It makes sure that your pushed commits
4-
# will be processed properly.
5-
6-
refs = $stdin.read
7-
key_id = ENV.delete('GL_ID')
8-
protocol = ENV.delete('GL_PROTOCOL')
9-
repo_path = Dir.pwd
10-
gl_repository = ENV['GL_REPOSITORY']
11-
12-
def increase_reference_counter(gl_repository, repo_path)
13-
result = GitlabNet.new.pre_receive(gl_repository)
14-
15-
result && result['reference_counter_increased']
16-
end
17-
18-
require_relative '../lib/gitlab_custom_hook'
19-
require_relative '../lib/gitlab_access'
20-
require_relative '../lib/gitlab_net'
21-
22-
# It's important that on pre-receive `increase_reference_counter` gets executed
23-
# last so that it only runs if everything else succeeded. On post-receive on the
24-
# other hand, we run GitlabPostReceive first because the push is already done
25-
# and we don't want to skip it if the custom hook fails.
26-
if GitlabAccess.new(gl_repository, repo_path, key_id, refs, protocol).exec &&
27-
GitlabCustomHook.new(repo_path, key_id).pre_receive(refs) &&
28-
increase_reference_counter(gl_repository, repo_path)
29-
exit 0
30-
else
31-
exit 1
32-
end

hooks/update

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,4 @@
1-
#!/usr/bin/env ruby
1+
#!/bin/sh
2+
echo "The gitlab-shell hooks have been migrated to Gitaly, see https://gitlab.com/gitlab-org/gitaly/issues/1226"
3+
exit 1
24

3-
# This file was placed here by GitLab. It makes sure that your pushed commits
4-
# will be processed properly.
5-
6-
ref_name = ARGV[0]
7-
old_value = ARGV[1]
8-
new_value = ARGV[2]
9-
repo_path = Dir.pwd
10-
key_id = ENV.delete('GL_ID')
11-
12-
require_relative '../lib/gitlab_custom_hook'
13-
14-
if GitlabCustomHook.new(repo_path, key_id).update(ref_name, old_value, new_value)
15-
exit 0
16-
else
17-
exit 1
18-
end

lib/gitlab_access.rb

Lines changed: 0 additions & 43 deletions
This file was deleted.

lib/gitlab_custom_hook.rb

Lines changed: 0 additions & 98 deletions
This file was deleted.

lib/gitlab_net.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
require 'json'
44

55
require_relative 'gitlab_config'
6-
require_relative 'gitlab_access'
76
require_relative 'gitlab_lfs_authentication'
87
require_relative 'http_helper'
98

lib/gitlab_post_receive.rb

Lines changed: 0 additions & 125 deletions
This file was deleted.

0 commit comments

Comments
 (0)