Commit d799a971 authored by Nick Thomas's avatar Nick Thomas

Merge branch 'rd-add-support-for-git-config-options-param' into 'master'

Add support for GitConfigOptions required for git-receive-pack command

See merge request gitlab-org/gitlab-workhorse!281
parents b33b8232 687e6a84
...@@ -153,6 +153,7 @@ func TestPostReceivePackProxiedToGitalySuccessfully(t *testing.T) { ...@@ -153,6 +153,7 @@ func TestPostReceivePackProxiedToGitalySuccessfully(t *testing.T) {
defer gitalyServer.Stop() defer gitalyServer.Stop()
apiResponse.GitalyServer.Address = "unix://" + socketPath apiResponse.GitalyServer.Address = "unix://" + socketPath
apiResponse.GitConfigOptions = []string{"git-config-hello=world"}
ts := testAuthServer(nil, 200, apiResponse) ts := testAuthServer(nil, 200, apiResponse)
defer ts.Close() defer ts.Close()
...@@ -166,22 +167,26 @@ func TestPostReceivePackProxiedToGitalySuccessfully(t *testing.T) { ...@@ -166,22 +167,26 @@ func TestPostReceivePackProxiedToGitalySuccessfully(t *testing.T) {
ws.URL+resource, ws.URL+resource,
map[string]string{ map[string]string{
"Content-Type": "application/x-git-receive-pack-request", "Content-Type": "application/x-git-receive-pack-request",
"Git-Protocol": "fake Git protocol", "Git-Protocol": gitProtocol,
}, },
testhelper.GitalyReceivePackResponseMock, testhelper.GitalyReceivePackResponseMock,
) )
expectedBody := strings.Join([]string{ split := strings.SplitN(body, "\000", 2)
apiResponse.Repository.StorageName, require.Len(t, split, 2)
apiResponse.Repository.RelativePath,
apiResponse.GL_ID, gitalyRequest := &pb.PostReceivePackRequest{}
apiResponse.GL_USERNAME, require.NoError(t, jsonpb.UnmarshalString(split[0], gitalyRequest))
gitProtocol,
string(testhelper.GitalyReceivePackResponseMock), assert.Equal(t, apiResponse.Repository.StorageName, gitalyRequest.Repository.StorageName)
}, "\000") assert.Equal(t, apiResponse.Repository.RelativePath, gitalyRequest.Repository.RelativePath)
assert.Equal(t, apiResponse.GL_ID, gitalyRequest.GlId)
assert.Equal(t, apiResponse.GL_USERNAME, gitalyRequest.GlUsername)
assert.Equal(t, apiResponse.GitConfigOptions, gitalyRequest.GitConfigOptions)
assert.Equal(t, gitProtocol, gitalyRequest.GitProtocol)
assert.Equal(t, 200, resp.StatusCode, "POST %q", resource) assert.Equal(t, 200, resp.StatusCode, "POST %q", resource)
assert.Equal(t, expectedBody, body, "POST %q: response body", resource) require.Equal(t, string(testhelper.GitalyReceivePackResponseMock), split[1])
testhelper.AssertResponseHeader(t, resp, "Content-Type", "application/x-git-receive-pack-result") testhelper.AssertResponseHeader(t, resp, "Content-Type", "application/x-git-receive-pack-result")
} }
......
...@@ -107,6 +107,8 @@ type Response struct { ...@@ -107,6 +107,8 @@ type Response struct {
// RepoPath is the full path on disk to the Git repository the request is // RepoPath is the full path on disk to the Git repository the request is
// about // about
RepoPath string RepoPath string
// GitConfigOptions holds the custom options that we want to pass to the git command
GitConfigOptions []string
// StoreLFSPath is provided by the GitLab Rails application to mark where the tmp file should be placed. // StoreLFSPath is provided by the GitLab Rails application to mark where the tmp file should be placed.
// This field is deprecated. GitLab will use TempPath instead // This field is deprecated. GitLab will use TempPath instead
StoreLFSPath string StoreLFSPath string
......
...@@ -54,7 +54,7 @@ func handleReceivePackWithGitaly(ctx context.Context, a *api.Response, clientReq ...@@ -54,7 +54,7 @@ func handleReceivePackWithGitaly(ctx context.Context, a *api.Response, clientReq
return fmt.Errorf("smarthttp.ReceivePack: %v", err) return fmt.Errorf("smarthttp.ReceivePack: %v", err)
} }
if err := smarthttp.ReceivePack(ctx, &a.Repository, a.GL_ID, a.GL_USERNAME, a.GL_REPOSITORY, clientRequest, clientResponse, gitProtocol); err != nil { if err := smarthttp.ReceivePack(ctx, &a.Repository, a.GL_ID, a.GL_USERNAME, a.GL_REPOSITORY, a.GitConfigOptions, clientRequest, clientResponse, gitProtocol); err != nil {
return fmt.Errorf("smarthttp.ReceivePack: %v", err) return fmt.Errorf("smarthttp.ReceivePack: %v", err)
} }
......
...@@ -43,18 +43,19 @@ func infoRefsReader(stream infoRefsClient) io.Reader { ...@@ -43,18 +43,19 @@ func infoRefsReader(stream infoRefsClient) io.Reader {
}) })
} }
func (client *SmartHTTPClient) ReceivePack(ctx context.Context, repo *pb.Repository, glId string, glUsername string, glRepository string, clientRequest io.Reader, clientResponse io.Writer, gitProtocol string) error { func (client *SmartHTTPClient) ReceivePack(ctx context.Context, repo *pb.Repository, glId string, glUsername string, glRepository string, gitConfigOptions []string, clientRequest io.Reader, clientResponse io.Writer, gitProtocol string) error {
stream, err := client.PostReceivePack(ctx) stream, err := client.PostReceivePack(ctx)
if err != nil { if err != nil {
return err return err
} }
rpcRequest := &pb.PostReceivePackRequest{ rpcRequest := &pb.PostReceivePackRequest{
Repository: repo, Repository: repo,
GlId: glId, GlId: glId,
GlUsername: glUsername, GlUsername: glUsername,
GlRepository: glRepository, GlRepository: glRepository,
GitProtocol: gitProtocol, GitConfigOptions: gitConfigOptions,
GitProtocol: gitProtocol,
} }
if err := stream.Send(rpcRequest); err != nil { if err := stream.Send(rpcRequest); err != nil {
......
...@@ -130,17 +130,17 @@ func (s *GitalyTestServer) PostReceivePack(stream pb.SmartHTTPService_PostReceiv ...@@ -130,17 +130,17 @@ func (s *GitalyTestServer) PostReceivePack(stream pb.SmartHTTPService_PostReceiv
} }
repo := req.GetRepository() repo := req.GetRepository()
if err := validateRepository(req.GetRepository()); err != nil { if err := validateRepository(repo); err != nil {
return err return err
} }
data := []byte(strings.Join([]string{ marshaler := &jsonpb.Marshaler{}
repo.GetStorageName(), jsonString, err := marshaler.MarshalToString(req)
repo.GetRelativePath(), if err != nil {
req.GlId, return err
req.GlUsername, }
req.GitProtocol,
}, "\000") + "\000") data := []byte(jsonString + "\000")
// The body of the request starts in the second message // The body of the request starts in the second message
for { for {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment