blob: f8afe393afcc774a66104179b77f718449d91abb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
package repository
import (
"io"
"os"
"path/filepath"
"gitlab.com/gitlab-org/gitaly/proto/v15/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/v15/internal/gitaly/service"
"gitlab.com/gitlab-org/gitaly/v15/streamio"
)
// GetConfig reads the repository's gitconfig file and returns its contents.
func (s *server) GetConfig(
request *gitalypb.GetConfigRequest,
stream gitalypb.RepositoryService_GetConfigServer,
) error {
repository := request.GetRepository()
if err := service.ValidateRepository(repository); err != nil {
return structerr.NewInvalidArgument("%w", err)
}
repoPath, err := s.locator.GetPath(repository)
if err != nil {
return err
}
configPath := filepath.Join(repoPath, "config")
gitconfig, err := os.Open(configPath)
if err != nil {
if os.IsNotExist(err) {
return structerr.NewNotFound("opening gitconfig: %w", err)
}
return structerr.NewInternal("opening gitconfig: %w", err)
}
writer := streamio.NewWriter(func(p []byte) error {
return stream.Send(&gitalypb.GetConfigResponse{
Data: p,
})
})
if _, err := io.Copy(writer, gitconfig); err != nil {
return structerr.NewInternal("sending config: %w", err)
}
return nil
}
|