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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
package localrepo
import (
"context"
"fmt"
"testing"
"gitlab.com/gitlab-org/gitaly/internal/command"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/catfile"
"gitlab.com/gitlab-org/gitaly/internal/git/repository"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/storage"
)
// Repo represents a local Git repository.
type Repo struct {
repository.GitRepo
gitCmdFactory git.CommandFactory
cfg config.Cfg
locator storage.Locator
catfileCache catfile.Cache
}
// New creates a new Repo from its protobuf representation.
func New(gitCmdFactory git.CommandFactory, catfileCache catfile.Cache, repo repository.GitRepo, cfg config.Cfg) *Repo {
return &Repo{
GitRepo: repo,
cfg: cfg,
gitCmdFactory: gitCmdFactory,
catfileCache: catfileCache,
locator: config.NewLocator(cfg),
}
}
// NewTestRepo constructs a Repo. It is intended as a helper function for tests which assembles
// dependencies ad-hoc from the given config.
func NewTestRepo(t testing.TB, cfg config.Cfg, repo repository.GitRepo) *Repo {
gitCmdFactory := git.NewExecCommandFactory(cfg)
return New(gitCmdFactory, catfile.NewCache(cfg), repo, cfg)
}
// Path returns the on-disk path of the repository.
func (repo *Repo) Path() (string, error) {
return repo.locator.GetRepoPath(repo)
}
// Exec creates a git command with the given args and Repo, executed in the
// Repo. It validates the arguments in the command before executing.
func (repo *Repo) Exec(ctx context.Context, cmd git.Cmd, opts ...git.CmdOpt) (*command.Command, error) {
return repo.gitCmdFactory.New(ctx, repo, cmd, opts...)
}
// ExecAndWait is similar to Exec, but waits for the command to exit before
// returning.
func (repo *Repo) ExecAndWait(ctx context.Context, cmd git.Cmd, opts ...git.CmdOpt) error {
command, err := repo.Exec(ctx, cmd, opts...)
if err != nil {
return err
}
return command.Wait()
}
// Config returns executor of the 'config' sub-command.
func (repo *Repo) Config() Config {
return Config{repo: repo}
}
// Remote returns executor of the 'remote' sub-command.
func (repo *Repo) Remote() Remote {
return Remote{repo: repo}
}
func errorWithStderr(err error, stderr []byte) error {
return fmt.Errorf("%w, stderr: %q", err, stderr)
}
|