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) {
defer gitalyServer.Stop()
apiResponse.GitalyServer.Address = "unix://" + socketPath
apiResponse.GitConfigOptions = []string{"git-config-hello=world"}
ts := testAuthServer(nil, 200, apiResponse)
defer ts.Close()
......@@ -166,22 +167,26 @@ func TestPostReceivePackProxiedToGitalySuccessfully(t *testing.T) {
ws.URL+resource,
map[string]string{
"Content-Type": "application/x-git-receive-pack-request",
"Git-Protocol": "fake Git protocol",
"Git-Protocol": gitProtocol,
},
testhelper.GitalyReceivePackResponseMock,
)
expectedBody := strings.Join([]string{
apiResponse.Repository.StorageName,
apiResponse.Repository.RelativePath,
apiResponse.GL_ID,
apiResponse.GL_USERNAME,
gitProtocol,
string(testhelper.GitalyReceivePackResponseMock),
}, "\000")
split := strings.SplitN(body, "\000", 2)
require.Len(t, split, 2)
gitalyRequest := &pb.PostReceivePackRequest{}
require.NoError(t, jsonpb.UnmarshalString(split[0], gitalyRequest))
assert.Equal(t, apiResponse.Repository.StorageName, gitalyRequest.Repository.StorageName)
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, 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")
}
......
......@@ -107,6 +107,8 @@ type Response struct {
// RepoPath is the full path on disk to the Git repository the request is
// about
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.
// This field is deprecated. GitLab will use TempPath instead
StoreLFSPath string
......
......@@ -54,7 +54,7 @@ func handleReceivePackWithGitaly(ctx context.Context, a *api.Response, clientReq
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)
}
......
......@@ -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)
if err != nil {
return err
}
rpcRequest := &pb.PostReceivePackRequest{
Repository: repo,
GlId: glId,
GlUsername: glUsername,
GlRepository: glRepository,
GitProtocol: gitProtocol,
Repository: repo,
GlId: glId,
GlUsername: glUsername,
GlRepository: glRepository,
GitConfigOptions: gitConfigOptions,
GitProtocol: gitProtocol,
}
if err := stream.Send(rpcRequest); err != nil {
......
......@@ -130,17 +130,17 @@ func (s *GitalyTestServer) PostReceivePack(stream pb.SmartHTTPService_PostReceiv
}
repo := req.GetRepository()
if err := validateRepository(req.GetRepository()); err != nil {
if err := validateRepository(repo); err != nil {
return err
}
data := []byte(strings.Join([]string{
repo.GetStorageName(),
repo.GetRelativePath(),
req.GlId,
req.GlUsername,
req.GitProtocol,
}, "\000") + "\000")
marshaler := &jsonpb.Marshaler{}
jsonString, err := marshaler.MarshalToString(req)
if err != nil {
return err
}
data := []byte(jsonString + "\000")
// The body of the request starts in the second message
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