From 5e3837b9cf22fb8b7ac935859f1e2805f69b7d0b Mon Sep 17 00:00:00 2001 From: Johannes Batzill Date: Wed, 11 Jan 2023 17:09:46 -0800 Subject: [PATCH] [MISC] disable 'update' git hook (#181) --- gitrpc/internal/service/repo.go | 6 +++++- internal/githook/cli.go | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/gitrpc/internal/service/repo.go b/gitrpc/internal/service/repo.go index 93d313f21..d15fb541b 100644 --- a/gitrpc/internal/service/repo.go +++ b/gitrpc/internal/service/repo.go @@ -39,7 +39,11 @@ var ( Email: "system@gitness", } - gitServerHookNames = []string{"pre-receive", "update", "post-receive"} + gitServerHookNames = []string{ + "pre-receive", + // "update", // update is disabled for performance reasons (called once for every ref) + "post-receive", + } // gitSHARegex defines the valid SHA format accepted by GIT (full form and short forms). // Note: as of now SHA is at most 40 characters long, but in the future it's moving to sha256 diff --git a/internal/githook/cli.go b/internal/githook/cli.go index a1caa3379..4d41154ee 100644 --- a/internal/githook/cli.go +++ b/internal/githook/cli.go @@ -68,8 +68,21 @@ func (c *CLI) PreReceive(ctx context.Context) error { // Update executes the update git hook. func (c *CLI) Update(ctx context.Context, ref string, oldSHA string, newSHA string) error { - // Skip update hook as we don't have any per branch operations, and pre-receive is more performant! - return nil + in := &githook.UpdateInput{ + BaseInput: githook.BaseInput{ + RepoID: c.payload.RepoID, + PrincipalID: c.payload.PrincipalID, + }, + RefUpdate: githook.ReferenceUpdate{ + Ref: ref, + Old: oldSHA, + New: newSHA, + }, + } + + out, err := c.client.Update(ctx, in) + + return handleServerHookOutput(out, err) } // PostReceive executes the post-receive git hook.