diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-01-29 13:01:44 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-02-03 09:52:57 +0300 |
commit | 09fe366d75acde2fef04eae8f628af6870c74dfa (patch) | |
tree | fe787fa03cdb3031d55500afc3af87a845d72971 | |
parent | 6d61ab918b5d1fb9d1725ae3fcdf4dd60dc2dbc9 (diff) |
git: Use `configureHooks()` to set up pack-objects hooks
The pack-objects hook sets up the command's hook configuration manually,
but most of this setup is duplicated with what `configureHooks()` would
do. This has been implemented such because previous to the preceding
commit, we didn't allow to configure hooks for read-only commands. Now
that we do, let's refactor the code to also use `configureHooks()`.
Note that this brings with it two changes: first, we now get the
safeguard to not allow configuration of hooks multiple times for free.
Second, we now potentially inject transaction information into the
HookPayload. Given that the hook is read-only, this information wouldn't
ever be used, so it's harmless.
-rw-r--r-- | internal/git/hooks_options.go | 12 |
1 files changed, 2 insertions, 10 deletions
diff --git a/internal/git/hooks_options.go b/internal/git/hooks_options.go index ca8e2e408..67a23a986 100644 --- a/internal/git/hooks_options.go +++ b/internal/git/hooks_options.go @@ -46,18 +46,10 @@ func WithPackObjectsHookEnv(ctx context.Context, repo *gitalypb.Repository, cfg return fmt.Errorf("missing repo: %w", ErrInvalidArg) } - payload, err := NewHooksPayload(cfg, repo, nil, nil, nil).Env() - if err != nil { - return err + if err := cc.configureHooks(ctx, repo, cfg, nil); err != nil { + return fmt.Errorf("pack-objects hook configuration: %w", err) } - cc.env = append( - cc.env, - payload, - "GITALY_BIN_DIR="+cfg.BinDir, - fmt.Sprintf("%s=%s", log.GitalyLogDirEnvKey, cfg.Logging.Dir), - ) - cc.globals = append(cc.globals, ConfigPair{ Key: "uploadpack.packObjectsHook", Value: filepath.Join(cfg.BinDir, "gitaly-hooks"), |