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:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2021-01-19 12:35:34 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-01-20 17:52:06 +0300
commit90ac208b34787ee4c7097582495cd4a254ae7bb8 (patch)
tree3b9309df81a79bccf0043828b90985bf461450d1
parentd412364ed6dd7df3d023f58feeaedfe6629ce41f (diff)
operations: Do not execute update hook on secondaries for Ruby RPCs
When we're about to execute git hooks, then we always need to check whether the current Gitaly node takes part in a transaction. If so and if it is not the transaction's primary node, then it mustn't execute hooks as we'd otherwise execute them multiple times. This always used to work for the pre-receive and post-receive hooks, but didn't for the update hook. This was fixed in commit commit 13db4c3c4 (hook: Don't execute custom update hooks on secondaries, 2020-11-19), but the same issue exists in our Ruby sidecar. Fix the issue by correctly passing along transaction information when executing the update hook.
-rw-r--r--internal/gitaly/service/operations/tags_test.go10
-rw-r--r--ruby/lib/gitlab/git/hook.rb6
2 files changed, 4 insertions, 12 deletions
diff --git a/internal/gitaly/service/operations/tags_test.go b/internal/gitaly/service/operations/tags_test.go
index 586a21028..483ae565b 100644
--- a/internal/gitaly/service/operations/tags_test.go
+++ b/internal/gitaly/service/operations/tags_test.go
@@ -405,15 +405,7 @@ func testUserCreateTagWithTransaction(t *testing.T, ctx context.Context) {
contents := testhelper.MustReadFile(t, hooksOutputPath)
require.Equal(t, "pre-receive\nupdate\npost-receive\n", string(contents))
} else {
- if featureflag.IsEnabled(ctx, featureflag.GoUserCreateTag) {
- testhelper.AssertPathNotExists(t, hooksOutputPath)
- } else {
- // There's a bug which causes us to
- // execute the update hook even on
- // secondary nodes.
- contents := testhelper.MustReadFile(t, hooksOutputPath)
- require.Equal(t, "update\n", string(contents))
- }
+ testhelper.AssertPathNotExists(t, hooksOutputPath)
}
// The Ruby implementation only calls the
diff --git a/ruby/lib/gitlab/git/hook.rb b/ruby/lib/gitlab/git/hook.rb
index 07dc0c8a4..3d6da9b9a 100644
--- a/ruby/lib/gitlab/git/hook.rb
+++ b/ruby/lib/gitlab/git/hook.rb
@@ -34,7 +34,7 @@ module Gitlab
when "reference-transaction"
call_reference_transaction_hook(gl_id, gl_username, oldrev, newrev, ref, transaction)
when "update"
- call_update_hook(gl_id, gl_username, oldrev, newrev, ref)
+ call_update_hook(gl_id, gl_username, oldrev, newrev, ref, transaction)
end
end
end
@@ -90,14 +90,14 @@ module Gitlab
call_stdin_hook(["prepared"], changes, vars)
end
- def call_update_hook(gl_id, gl_username, oldrev, newrev, ref)
+ def call_update_hook(gl_id, gl_username, oldrev, newrev, ref, transaction)
options = {
chdir: repo_path
}
args = [ref, oldrev, newrev]
- vars = env_base_vars(gl_id, gl_username)
+ vars = env_base_vars(gl_id, gl_username, transaction)
stdout, stderr, status = Open3.capture3(vars, path, *args, options)
[status.success?, stderr.presence || stdout]