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:
authorJohn Cai <jcai@gitlab.com>2020-03-15 06:04:43 +0300
committerJohn Cai <jcai@gitlab.com>2020-03-15 06:04:43 +0300
commit669559d47428ecbb1886d1c2eafcb33d416f1ea6 (patch)
tree66595c23b6a79fd24eb9b95e906b1eca298d2173
parent9c002c8644b6935bc1104f74603c0d1f319f2291 (diff)
Send GIT_OBJECT_DIRECTORY, GIT_ALTERNATE_OBJECT_DIRECTORIES to ruby hookjc-add-git-attributes-to-prereceive
-rw-r--r--internal/service/hooks/pre_receive.go9
-rw-r--r--internal/service/hooks/pre_receive_test.go5
-rwxr-xr-xinternal/service/hooks/testdata/gitlab-shell/hooks/pre-receive2
3 files changed, 15 insertions, 1 deletions
diff --git a/internal/service/hooks/pre_receive.go b/internal/service/hooks/pre_receive.go
index e855d2584..9718e0bf7 100644
--- a/internal/service/hooks/pre_receive.go
+++ b/internal/service/hooks/pre_receive.go
@@ -5,6 +5,7 @@ import (
"fmt"
"os/exec"
"path/filepath"
+ "strings"
"gitlab.com/gitlab-org/gitaly/internal/config"
"gitlab.com/gitlab-org/gitaly/internal/gitlabshell"
@@ -24,6 +25,13 @@ func hookRequestEnv(req hookRequest) ([]string, error) {
fmt.Sprintf("GL_REPOSITORY=%s", req.GetRepository().GetGlRepository())), nil
}
+func preReceiveEnv(repo *gitalypb.Repository) []string {
+ return []string{
+ fmt.Sprintf("GIT_OBJECT_DIRECTORY=%s", repo.GetGitObjectDirectory()),
+ fmt.Sprintf("GIT_ALTERNATE_OBJECT_DIRECTORIES=%s", strings.Join(repo.GitAlternateObjectDirectories, ":")),
+ }
+}
+
func gitlabShellHook(hookName string) string {
return filepath.Join(config.Config.Ruby.Dir, "gitlab-shell", "hooks", hookName)
}
@@ -43,6 +51,7 @@ func (s *server) PreReceiveHook(stream gitalypb.HookService_PreReceiveHookServer
return helper.ErrInternal(err)
}
+ hookEnv = append(hookEnv, preReceiveEnv(firstRequest.GetRepository())...)
hookEnv = append(hookEnv, fmt.Sprintf("GL_PROTOCOL=%s", firstRequest.GetProtocol()))
stdin := streamio.NewReader(func() ([]byte, error) {
diff --git a/internal/service/hooks/pre_receive_test.go b/internal/service/hooks/pre_receive_test.go
index 08af19aee..72b163654 100644
--- a/internal/service/hooks/pre_receive_test.go
+++ b/internal/service/hooks/pre_receive_test.go
@@ -51,6 +51,11 @@ func TestPreReceive(t *testing.T) {
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ gitObjectDir := "/some/dir"
+ gitAlternateObjectDirs := []string{"a", "b", "c"}
+ testRepo.GitObjectDirectory = gitObjectDir
+ testRepo.GitAlternateObjectDirectories = gitAlternateObjectDirs
+
client, conn := newHooksClient(t, serverSocketPath)
defer conn.Close()
diff --git a/internal/service/hooks/testdata/gitlab-shell/hooks/pre-receive b/internal/service/hooks/testdata/gitlab-shell/hooks/pre-receive
index fc967a761..da4aacbdf 100755
--- a/internal/service/hooks/testdata/gitlab-shell/hooks/pre-receive
+++ b/internal/service/hooks/testdata/gitlab-shell/hooks/pre-receive
@@ -3,7 +3,7 @@
# Tests inputs to pre-receive
abort("FAIL") if $stdin.read.empty?
-abort("FAIL") if %w[GL_ID GL_REPOSITORY GL_PROTOCOL].any? { |k| ENV[k].empty? }
+abort("FAIL") if %w[GL_ID GL_REPOSITORY GL_PROTOCOL GIT_OBJECT_DIRECTORY GIT_ALTERNATE_OBJECT_DIRECTORIES].any? { |k| ENV[k].empty? }
puts "OK"