diff options
author | Pavlo Strokov <pstrokov@gitlab.com> | 2021-02-05 18:00:13 +0300 |
---|---|---|
committer | Pavlo Strokov <pstrokov@gitlab.com> | 2021-02-05 18:00:13 +0300 |
commit | ad75eb15e8e667620e7cd1386e8361aaef7598d9 (patch) | |
tree | 104590d69582e03cecc0e1cadbecbc247f8dbf91 | |
parent | 9cd95f79308630c410da807146175758e34bf19a (diff) | |
parent | 77a83c6d33b6c3ce323c771114d1253d932d41ed (diff) |
Merge branch 'ps-git-cmd-factory-injection' into 'master'
Injection of the git.CommandFactory abstraction into the dependent services
See merge request gitlab-org/gitaly!3088
48 files changed, 170 insertions, 147 deletions
diff --git a/cmd/gitaly-ssh/upload_pack_test.go b/cmd/gitaly-ssh/upload_pack_test.go index 01936a7e8..231399501 100644 --- a/cmd/gitaly-ssh/upload_pack_test.go +++ b/cmd/gitaly-ssh/upload_pack_test.go @@ -36,7 +36,8 @@ func TestVisibilityOfHiddenRefs(t *testing.T) { existingSha := "1e292f8fedd741b75372e19097c76d327140c312" keepAroundRef := fmt.Sprintf("%s/%s", keepAroundNamespace, existingSha) - updater, err := updateref.New(ctx, config.Config, testRepo) + gitCmdFactory := git.NewExecCommandFactory(config.Config) + updater, err := updateref.New(ctx, config.Config, gitCmdFactory, testRepo) require.NoError(t, err) require.NoError(t, updater.Create(git.ReferenceName(keepAroundRef), existingSha)) @@ -85,7 +86,7 @@ func TestVisibilityOfHiddenRefs(t *testing.T) { } stdout := &bytes.Buffer{} - cmd, err := git.NewCommandWithoutRepo(ctx, nil, git.SubCmd{ + cmd, err := gitCmdFactory.NewWithoutRepo(ctx, nil, git.SubCmd{ Name: "ls-remote", Args: []string{ fmt.Sprintf("%s:%s", "git@localhost", testRepoPath), diff --git a/internal/git/objectpool/fetch.go b/internal/git/objectpool/fetch.go index 9acb1e9e1..67382b925 100644 --- a/internal/git/objectpool/fetch.go +++ b/internal/git/objectpool/fetch.go @@ -152,7 +152,7 @@ func (o *ObjectPool) rescueDanglingObjects(ctx context.Context, repo repository. return err } - updater, err := updateref.New(ctx, o.cfg, repo, updateref.WithDisabledTransactions()) + updater, err := updateref.New(ctx, o.cfg, o.gitCmdFactory, repo, updateref.WithDisabledTransactions()) if err != nil { return err } diff --git a/internal/git/updateref/updateref.go b/internal/git/updateref/updateref.go index f1a3db68c..e556d27ea 100644 --- a/internal/git/updateref/updateref.go +++ b/internal/git/updateref/updateref.go @@ -40,7 +40,7 @@ func WithDisabledTransactions() UpdaterOpt { // // It is important that ctx gets canceled somewhere. If it doesn't, the process // spawned by New() may never terminate. -func New(ctx context.Context, conf config.Cfg, repo repository.GitRepo, opts ...UpdaterOpt) (*Updater, error) { +func New(ctx context.Context, conf config.Cfg, gitCmdFactory git.CommandFactory, repo repository.GitRepo, opts ...UpdaterOpt) (*Updater, error) { var cfg updaterConfig for _, opt := range opts { opt(&cfg) @@ -51,7 +51,7 @@ func New(ctx context.Context, conf config.Cfg, repo repository.GitRepo, opts ... txOption = git.WithDisabledHooks() } - cmd, err := git.NewCommand(ctx, repo, nil, + cmd, err := gitCmdFactory.New(ctx, repo, nil, git.SubCmd{ Name: "update-ref", Flags: []git.Option{git.Flag{Name: "-z"}, git.Flag{Name: "--stdin"}}, diff --git a/internal/git/updateref/updateref_test.go b/internal/git/updateref/updateref_test.go index f183ca652..24f3f2c52 100644 --- a/internal/git/updateref/updateref_test.go +++ b/internal/git/updateref/updateref_test.go @@ -47,7 +47,7 @@ func TestCreate(t *testing.T) { headCommit, err := log.GetCommit(ctx, gitCmdFactory, testRepo, "HEAD") require.NoError(t, err) - updater, err := New(ctx, config.Config, testRepo) + updater, err := New(ctx, config.Config, git.NewExecCommandFactory(config.Config), testRepo) require.NoError(t, err) ref := git.ReferenceName("refs/heads/_create") @@ -70,7 +70,7 @@ func TestUpdate(t *testing.T) { headCommit, err := log.GetCommit(ctx, gitCmdFactory, testRepo, "HEAD") require.NoError(t, err) - updater, err := New(ctx, config.Config, testRepo) + updater, err := New(ctx, config.Config, git.NewExecCommandFactory(config.Config), testRepo) require.NoError(t, err) ref := git.ReferenceName("refs/heads/feature") @@ -104,7 +104,7 @@ func TestDelete(t *testing.T) { ctx, testRepo, _, teardown := setup(t) defer teardown() - updater, err := New(ctx, config.Config, testRepo) + updater, err := New(ctx, config.Config, git.NewExecCommandFactory(config.Config), testRepo) require.NoError(t, err) ref := git.ReferenceName("refs/heads/feature") @@ -124,7 +124,7 @@ func TestBulkOperation(t *testing.T) { headCommit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, "HEAD") require.NoError(t, err) - updater, err := New(ctx, config.Config, testRepo) + updater, err := New(ctx, config.Config, git.NewExecCommandFactory(config.Config), testRepo) require.NoError(t, err) for i := 0; i < 1000; i++ { @@ -148,7 +148,7 @@ func TestContextCancelAbortsRefChanges(t *testing.T) { require.NoError(t, err) childCtx, childCancel := context.WithCancel(ctx) - updater, err := New(childCtx, config.Config, testRepo) + updater, err := New(childCtx, config.Config, git.NewExecCommandFactory(config.Config), testRepo) require.NoError(t, err) ref := git.ReferenceName("refs/heads/_shouldnotexist") @@ -177,7 +177,7 @@ func TestUpdater_closingStdinAbortsChanges(t *testing.T) { ref := git.ReferenceName("refs/heads/shouldnotexist") - updater, err := New(ctx, config.Config, testRepo) + updater, err := New(ctx, config.Config, git.NewExecCommandFactory(config.Config), testRepo) require.NoError(t, err) require.NoError(t, updater.Create(ref, headCommit.Id)) diff --git a/internal/gitaly/service/cleanup/apply_bfg_object_map_stream.go b/internal/gitaly/service/cleanup/apply_bfg_object_map_stream.go index b6820cd73..d1a13ea13 100644 --- a/internal/gitaly/service/cleanup/apply_bfg_object_map_stream.go +++ b/internal/gitaly/service/cleanup/apply_bfg_object_map_stream.go @@ -5,6 +5,7 @@ import ( "io" "github.com/golang/protobuf/proto" + "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/gitaly/service/cleanup/internalrefs" "gitlab.com/gitlab-org/gitaly/internal/gitaly/service/cleanup/notifier" "gitlab.com/gitlab-org/gitaly/internal/helper" @@ -47,7 +48,7 @@ func (s *server) ApplyBfgObjectMapStream(server gitalypb.CleanupService_ApplyBfg // It doesn't matter if new internal references are added after this RPC // starts running - they shouldn't point to the objects removed by the BFG - cleaner, err := internalrefs.NewCleaner(ctx, s.cfg, repo, notifier.Notify) + cleaner, err := internalrefs.NewCleaner(ctx, s.cfg, git.NewExecCommandFactory(s.cfg), repo, notifier.Notify) if err != nil { return helper.ErrInternal(err) } diff --git a/internal/gitaly/service/cleanup/internalrefs/cleaner.go b/internal/gitaly/service/cleanup/internalrefs/cleaner.go index 498402125..33dfc4516 100644 --- a/internal/gitaly/service/cleanup/internalrefs/cleaner.go +++ b/internal/gitaly/service/cleanup/internalrefs/cleaner.go @@ -47,13 +47,13 @@ type ErrInvalidObjectMap error // NewCleaner builds a new instance of Cleaner, which is used to apply a // filter-repo or BFG object map to a repository. -func NewCleaner(ctx context.Context, cfg config.Cfg, repo *gitalypb.Repository, forEach ForEachFunc) (*Cleaner, error) { - table, err := buildLookupTable(ctx, repo) +func NewCleaner(ctx context.Context, cfg config.Cfg, gitCmdFactory git.CommandFactory, repo *gitalypb.Repository, forEach ForEachFunc) (*Cleaner, error) { + table, err := buildLookupTable(ctx, gitCmdFactory, repo) if err != nil { return nil, err } - updater, err := updateref.New(ctx, cfg, repo) + updater, err := updateref.New(ctx, cfg, gitCmdFactory, repo) if err != nil { return nil, err } @@ -133,8 +133,8 @@ func (c *Cleaner) processEntry(ctx context.Context, oldSHA, newSHA string) error // an object that has been rewritten by the filter-repo or BFG (and so require // action). It is consulted once per line in the object map. Git is optimized // for ref -> SHA lookups, but we want the opposite! -func buildLookupTable(ctx context.Context, repo *gitalypb.Repository) (map[string][]git.ReferenceName, error) { - cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ +func buildLookupTable(ctx context.Context, gitCmdFactory git.CommandFactory, repo *gitalypb.Repository) (map[string][]git.ReferenceName, error) { + cmd, err := gitCmdFactory.New(ctx, repo, nil, git.SubCmd{ Name: "for-each-ref", Flags: []git.Option{git.ValueFlag{Name: "--format", Value: "%(objectname) %(refname)"}}, Args: internalRefs, diff --git a/internal/gitaly/service/commit/commits_by_message.go b/internal/gitaly/service/commit/commits_by_message.go index ef04e9527..47735eeef 100644 --- a/internal/gitaly/service/commit/commits_by_message.go +++ b/internal/gitaly/service/commit/commits_by_message.go @@ -54,7 +54,7 @@ func (s *server) commitsByMessage(in *gitalypb.CommitsByMessageRequest, stream g if len(revision) == 0 { var err error - revision, err = defaultBranchName(ctx, in.Repository) + revision, err = defaultBranchName(ctx, s.gitCmdFactory, in.Repository) if err != nil { return err } diff --git a/internal/gitaly/service/commit/count_commits.go b/internal/gitaly/service/commit/count_commits.go index 7b7df9e6f..67f4ea2e6 100644 --- a/internal/gitaly/service/commit/count_commits.go +++ b/internal/gitaly/service/commit/count_commits.go @@ -45,7 +45,7 @@ func (s *server) CountCommits(ctx context.Context, in *gitalypb.CountCommitsRequ } globals := git.ConvertGlobalOptions(in.GetGlobalOptions()) - cmd, err := git.NewCommand(ctx, in.Repository, globals, subCmd) + cmd, err := s.gitCmdFactory.New(ctx, in.Repository, globals, subCmd) if err != nil { if _, ok := status.FromError(err); ok { return nil, err diff --git a/internal/gitaly/service/commit/count_diverging_commits.go b/internal/gitaly/service/commit/count_diverging_commits.go index 2e23210f0..0d7a708d1 100644 --- a/internal/gitaly/service/commit/count_diverging_commits.go +++ b/internal/gitaly/service/commit/count_diverging_commits.go @@ -22,7 +22,7 @@ func (s *server) CountDivergingCommits(ctx context.Context, req *gitalypb.CountD from, to := string(req.GetFrom()), string(req.GetTo()) maxCount := int(req.GetMaxCount()) - left, right, err := findLeftRightCount(ctx, req.GetRepository(), from, to, maxCount) + left, right, err := s.findLeftRightCount(ctx, req.GetRepository(), from, to, maxCount) if err != nil { return nil, helper.ErrInternal(err) } @@ -58,8 +58,8 @@ func buildRevListCountCmd(from, to string, maxCount int) git.SubCmd { return subCmd } -func findLeftRightCount(ctx context.Context, repo *gitalypb.Repository, from, to string, maxCount int) (int32, int32, error) { - cmd, err := git.NewCommand(ctx, repo, nil, buildRevListCountCmd(from, to, maxCount)) +func (s *server) findLeftRightCount(ctx context.Context, repo *gitalypb.Repository, from, to string, maxCount int) (int32, int32, error) { + cmd, err := s.gitCmdFactory.New(ctx, repo, nil, buildRevListCountCmd(from, to, maxCount)) if err != nil { return 0, 0, fmt.Errorf("git rev-list cmd: %v", err) } diff --git a/internal/gitaly/service/commit/find_all_commits.go b/internal/gitaly/service/commit/find_all_commits.go index 43dd4d803..3d4e3324d 100644 --- a/internal/gitaly/service/commit/find_all_commits.go +++ b/internal/gitaly/service/commit/find_all_commits.go @@ -34,7 +34,7 @@ func (s *server) FindAllCommits(in *gitalypb.FindAllCommitsRequest, stream gital var revisions []string if len(in.GetRevision()) == 0 { - branchNames, err := _findBranchNamesFunc(stream.Context(), in.Repository) + branchNames, err := _findBranchNamesFunc(stream.Context(), s.gitCmdFactory, in.Repository) if err != nil { return helper.ErrInvalidArgument(err) } diff --git a/internal/gitaly/service/commit/find_all_commits_test.go b/internal/gitaly/service/commit/find_all_commits_test.go index 2ce379b96..e92653c6e 100644 --- a/internal/gitaly/service/commit/find_all_commits_test.go +++ b/internal/gitaly/service/commit/find_all_commits_test.go @@ -7,6 +7,7 @@ import ( "github.com/golang/protobuf/ptypes/timestamp" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/gitaly/service/ref" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -18,7 +19,7 @@ func TestSuccessfulFindAllCommitsRequest(t *testing.T) { _findBranchNamesFunc = ref.FindBranchNames }() - _findBranchNamesFunc = func(ctx context.Context, repo *gitalypb.Repository) ([][]byte, error) { + _findBranchNamesFunc = func(ctx context.Context, gitCmdFactory git.CommandFactory, repo *gitalypb.Repository) ([][]byte, error) { return [][]byte{ []byte("few-commits"), []byte("two-commits"), diff --git a/internal/gitaly/service/commit/find_commit_test.go b/internal/gitaly/service/commit/find_commit_test.go index d176b73a1..7b3541245 100644 --- a/internal/gitaly/service/commit/find_commit_test.go +++ b/internal/gitaly/service/commit/find_commit_test.go @@ -326,8 +326,8 @@ func benchmarkFindCommit(withCache bool, b *testing.B) { defer cleanupFn() // get a list of revisions - - logCmd, err := git.NewCommand(ctx, testRepo, nil, + gitCmdFactory := git.NewExecCommandFactory(config.Config) + logCmd, err := gitCmdFactory.New(ctx, testRepo, nil, git.SubCmd{Name: "log", Flags: []git.Option{git.Flag{Name: "--format=format:%H"}}}) require.NoError(b, err) @@ -374,7 +374,8 @@ func TestFindCommitWithCache(t *testing.T) { // get a list of revisions - logCmd, err := git.NewCommand(ctx, testRepo, nil, + gitCmdFactory := git.NewExecCommandFactory(config.Config) + logCmd, err := gitCmdFactory.New(ctx, testRepo, nil, git.SubCmd{Name: "log", Flags: []git.Option{git.Flag{Name: "--format=format:%H"}}}) require.NoError(t, err) diff --git a/internal/gitaly/service/commit/find_commits.go b/internal/gitaly/service/commit/find_commits.go index ebcbed34b..50e9203dc 100644 --- a/internal/gitaly/service/commit/find_commits.go +++ b/internal/gitaly/service/commit/find_commits.go @@ -29,7 +29,7 @@ func (s *server) FindCommits(req *gitalypb.FindCommitsRequest, stream gitalypb.C // migrated. if revision := req.Revision; len(revision) == 0 && !req.GetAll() { var err error - req.Revision, err = defaultBranchName(ctx, req.Repository) + req.Revision, err = defaultBranchName(ctx, s.gitCmdFactory, req.Repository) if err != nil { return helper.ErrInternal(fmt.Errorf("defaultBranchName: %v", err)) } @@ -50,7 +50,7 @@ func (s *server) FindCommits(req *gitalypb.FindCommitsRequest, stream gitalypb.C func (s *server) findCommits(ctx context.Context, req *gitalypb.FindCommitsRequest, stream gitalypb.CommitService_FindCommitsServer) error { globals := git.ConvertGlobalOptions(req.GetGlobalOptions()) - logCmd, err := git.NewCommand(ctx, req.GetRepository(), globals, getLogCommandSubCmd(req)) + logCmd, err := s.gitCmdFactory.New(ctx, req.GetRepository(), globals, getLogCommandSubCmd(req)) if err != nil { return fmt.Errorf("error when creating git log command: %v", err) } diff --git a/internal/gitaly/service/commit/isancestor.go b/internal/gitaly/service/commit/isancestor.go index a6ecd28a1..0756bd0d6 100644 --- a/internal/gitaly/service/commit/isancestor.go +++ b/internal/gitaly/service/commit/isancestor.go @@ -19,18 +19,18 @@ func (s *server) CommitIsAncestor(ctx context.Context, in *gitalypb.CommitIsAnce return nil, status.Errorf(codes.InvalidArgument, "Bad Request (empty child sha)") } - ret, err := commitIsAncestorName(ctx, in.Repository, in.AncestorId, in.ChildId) + ret, err := s.commitIsAncestorName(ctx, in.Repository, in.AncestorId, in.ChildId) return &gitalypb.CommitIsAncestorResponse{Value: ret}, err } // Assumes that `path`, `ancestorID` and `childID` are populated :trollface: -func commitIsAncestorName(ctx context.Context, repo *gitalypb.Repository, ancestorID, childID string) (bool, error) { +func (s *server) commitIsAncestorName(ctx context.Context, repo *gitalypb.Repository, ancestorID, childID string) (bool, error) { ctxlogrus.Extract(ctx).WithFields(log.Fields{ "ancestorSha": ancestorID, "childSha": childID, }).Debug("commitIsAncestor") - cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{Name: "merge-base", + cmd, err := s.gitCmdFactory.New(ctx, repo, nil, git.SubCmd{Name: "merge-base", Flags: []git.Option{git.Flag{Name: "--is-ancestor"}}, Args: []string{ancestorID, childID}}) if err != nil { if _, ok := status.FromError(err); ok { diff --git a/internal/gitaly/service/commit/languages.go b/internal/gitaly/service/commit/languages.go index 4f867bc28..c64814617 100644 --- a/internal/gitaly/service/commit/languages.go +++ b/internal/gitaly/service/commit/languages.go @@ -30,7 +30,7 @@ func (s *server) CommitLanguages(ctx context.Context, req *gitalypb.CommitLangua revision := string(req.Revision) if revision == "" { - defaultBranch, err := ref.DefaultBranchName(ctx, req.Repository) + defaultBranch, err := ref.DefaultBranchName(ctx, s.gitCmdFactory, req.Repository) if err != nil { return nil, err } @@ -87,16 +87,16 @@ func (ls languageSorter) Swap(i, j int) { ls[i], ls[j] = ls[j], ls[i] } func (ls languageSorter) Less(i, j int) bool { return ls[i].Share > ls[j].Share } func (s *server) lookupRevision(ctx context.Context, repo *gitalypb.Repository, revision string) (string, error) { - rev, err := checkRevision(ctx, repo, revision) + rev, err := s.checkRevision(ctx, repo, revision) if err != nil { switch err { case errAmbigRef: - fullRev, err := disambiguateRevision(ctx, repo, revision) + fullRev, err := s.disambiguateRevision(ctx, repo, revision) if err != nil { return "", err } - rev, err = checkRevision(ctx, repo, fullRev) + rev, err = s.checkRevision(ctx, repo, fullRev) if err != nil { return "", err } @@ -108,10 +108,10 @@ func (s *server) lookupRevision(ctx context.Context, repo *gitalypb.Repository, return rev, nil } -func checkRevision(ctx context.Context, repo *gitalypb.Repository, revision string) (string, error) { +func (s *server) checkRevision(ctx context.Context, repo *gitalypb.Repository, revision string) (string, error) { var stdout, stderr bytes.Buffer - revParse, err := git.NewCommand(ctx, repo, nil, + revParse, err := s.gitCmdFactory.New(ctx, repo, nil, git.SubCmd{Name: "rev-parse", Args: []string{revision}}, git.WithStdout(&stdout), git.WithStderr(&stderr), @@ -133,8 +133,8 @@ func checkRevision(ctx context.Context, repo *gitalypb.Repository, revision stri return text.ChompBytes(stdout.Bytes()), nil } -func disambiguateRevision(ctx context.Context, repo *gitalypb.Repository, revision string) (string, error) { - cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ +func (s *server) disambiguateRevision(ctx context.Context, repo *gitalypb.Repository, revision string) (string, error) { + cmd, err := s.gitCmdFactory.New(ctx, repo, nil, git.SubCmd{ Name: "for-each-ref", Flags: []git.Option{git.Flag{Name: "--format=%(refname)"}}, Args: []string{"**/" + revision}, diff --git a/internal/gitaly/service/commit/list_files.go b/internal/gitaly/service/commit/list_files.go index 7a4d811ec..20b1d8d9f 100644 --- a/internal/gitaly/service/commit/list_files.go +++ b/internal/gitaly/service/commit/list_files.go @@ -33,7 +33,7 @@ func (s *server) ListFiles(in *gitalypb.ListFilesRequest, stream gitalypb.Commit revision := string(in.GetRevision()) if len(revision) == 0 { - defaultBranch, err := defaultBranchName(stream.Context(), repo) + defaultBranch, err := defaultBranchName(stream.Context(), s.gitCmdFactory, repo) if err != nil { return helper.DecorateError(codes.NotFound, fmt.Errorf("revision not found %q", revision)) } @@ -54,7 +54,7 @@ func (s *server) ListFiles(in *gitalypb.ListFilesRequest, stream gitalypb.Commit return stream.Send(&gitalypb.ListFilesResponse{}) } - if err := listFiles(repo, revision, stream); err != nil { + if err := s.listFiles(repo, revision, stream); err != nil { return helper.ErrInternal(err) } @@ -68,8 +68,8 @@ func validateListFilesRequest(in *gitalypb.ListFilesRequest) error { return nil } -func listFiles(repo *gitalypb.Repository, revision string, stream gitalypb.CommitService_ListFilesServer) error { - cmd, err := git.NewCommand(stream.Context(), repo, nil, git.SubCmd{Name: "ls-tree", +func (s *server) listFiles(repo *gitalypb.Repository, revision string, stream gitalypb.CommitService_ListFilesServer) error { + cmd, err := s.gitCmdFactory.New(stream.Context(), repo, nil, git.SubCmd{Name: "ls-tree", Flags: []git.Option{git.Flag{Name: "-z"}, git.Flag{Name: "-r"}, git.Flag{Name: "--full-tree"}, git.Flag{Name: "--full-name"}}, PostSepArgs: []string{revision}, }) diff --git a/internal/gitaly/service/commit/list_files_test.go b/internal/gitaly/service/commit/list_files_test.go index cfe3ce88c..59d0a94fa 100644 --- a/internal/gitaly/service/commit/list_files_test.go +++ b/internal/gitaly/service/commit/list_files_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/gitaly/service/ref" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -40,7 +41,7 @@ var ( ) func TestListFiles_success(t *testing.T) { - defaultBranchName = func(ctx context.Context, _ *gitalypb.Repository) ([]byte, error) { + defaultBranchName = func(context.Context, git.CommandFactory, *gitalypb.Repository) ([]byte, error) { return []byte("test-do-not-touch"), nil } defer func() { diff --git a/internal/gitaly/service/commit/list_last_commits_for_tree.go b/internal/gitaly/service/commit/list_last_commits_for_tree.go index 0cb6f480f..8af327966 100644 --- a/internal/gitaly/service/commit/list_last_commits_for_tree.go +++ b/internal/gitaly/service/commit/list_last_commits_for_tree.go @@ -38,7 +38,7 @@ func (s *server) ListLastCommitsForTree(in *gitalypb.ListLastCommitsForTreeReque } func (s *server) listLastCommitsForTree(in *gitalypb.ListLastCommitsForTreeRequest, stream gitalypb.CommitService_ListLastCommitsForTreeServer) error { - cmd, parser, err := newLSTreeParser(in, stream) + cmd, parser, err := s.newLSTreeParser(in, stream) if err != nil { return err } @@ -116,14 +116,14 @@ func getLSTreeEntries(parser *lstree.Parser) (lstree.Entries, error) { return entries, nil } -func newLSTreeParser(in *gitalypb.ListLastCommitsForTreeRequest, stream gitalypb.CommitService_ListLastCommitsForTreeServer) (*command.Command, *lstree.Parser, error) { +func (s *server) newLSTreeParser(in *gitalypb.ListLastCommitsForTreeRequest, stream gitalypb.CommitService_ListLastCommitsForTreeServer) (*command.Command, *lstree.Parser, error) { path := string(in.GetPath()) if path == "" || path == "/" { path = "." } globals := git.ConvertGlobalOptions(in.GetGlobalOptions()) - cmd, err := git.NewCommand(stream.Context(), in.GetRepository(), globals, git.SubCmd{ + cmd, err := s.gitCmdFactory.New(stream.Context(), in.GetRepository(), globals, git.SubCmd{ Name: "ls-tree", Flags: []git.Option{git.Flag{Name: "-z"}, git.Flag{Name: "--full-name"}}, Args: []string{in.GetRevision(), path}, diff --git a/internal/gitaly/service/commit/raw_blame.go b/internal/gitaly/service/commit/raw_blame.go index 60897fcca..d84abe51b 100644 --- a/internal/gitaly/service/commit/raw_blame.go +++ b/internal/gitaly/service/commit/raw_blame.go @@ -21,7 +21,7 @@ func (s *server) RawBlame(in *gitalypb.RawBlameRequest, stream gitalypb.CommitSe revision := string(in.GetRevision()) path := string(in.GetPath()) - cmd, err := git.NewCommand(ctx, in.Repository, nil, git.SubCmd{ + cmd, err := s.gitCmdFactory.New(ctx, in.Repository, nil, git.SubCmd{ Name: "blame", Flags: []git.Option{git.Flag{Name: "-p"}}, Args: []string{revision}, diff --git a/internal/gitaly/service/commit/server.go b/internal/gitaly/service/commit/server.go index dd981b6d8..62c29b6b6 100644 --- a/internal/gitaly/service/commit/server.go +++ b/internal/gitaly/service/commit/server.go @@ -9,8 +9,8 @@ import ( ) type server struct { - locator storage.Locator cfg config.Cfg + locator storage.Locator gitCmdFactory git.CommandFactory } diff --git a/internal/gitaly/service/commit/stats.go b/internal/gitaly/service/commit/stats.go index 7f59d51ee..5f733a76d 100644 --- a/internal/gitaly/service/commit/stats.go +++ b/internal/gitaly/service/commit/stats.go @@ -43,7 +43,7 @@ func (s *server) commitStats(ctx context.Context, in *gitalypb.CommitStatsReques args = append(args, commit.Id+"^", commit.Id) } - cmd, err := git.NewCommand(ctx, in.Repository, nil, git.SubCmd{ + cmd, err := s.gitCmdFactory.New(ctx, in.Repository, nil, git.SubCmd{ Name: "diff", Flags: []git.Option{git.Flag{Name: "--numstat"}}, Args: args, diff --git a/internal/gitaly/service/conflicts/resolve_conflicts.go b/internal/gitaly/service/conflicts/resolve_conflicts.go index 3d1a93145..800b402a4 100644 --- a/internal/gitaly/service/conflicts/resolve_conflicts.go +++ b/internal/gitaly/service/conflicts/resolve_conflicts.go @@ -301,7 +301,7 @@ func (s *server) repoWithBranchCommit(ctx context.Context, srcRepo, targetRepo * return err } - cmd, err := git.NewCommand(ctx, srcRepo, nil, + cmd, err := s.gitCmdFactory.New(ctx, srcRepo, nil, git.SubCmd{ Name: "fetch", Flags: []git.Option{git.Flag{Name: "--no-tags"}}, diff --git a/internal/gitaly/service/conflicts/server.go b/internal/gitaly/service/conflicts/server.go index 16f00ca24..e80e29c62 100644 --- a/internal/gitaly/service/conflicts/server.go +++ b/internal/gitaly/service/conflicts/server.go @@ -2,6 +2,7 @@ package conflicts import ( "gitlab.com/gitlab-org/gitaly/client" + "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/storage" @@ -9,18 +10,20 @@ import ( ) type server struct { - ruby *rubyserver.Server - cfg config.Cfg - locator storage.Locator - pool *client.Pool + ruby *rubyserver.Server + cfg config.Cfg + locator storage.Locator + gitCmdFactory git.CommandFactory + pool *client.Pool } // NewServer creates a new instance of a grpc ConflictsServer -func NewServer(rs *rubyserver.Server, cfg config.Cfg, locator storage.Locator) gitalypb.ConflictsServiceServer { +func NewServer(rs *rubyserver.Server, cfg config.Cfg, locator storage.Locator, gitCmdFactory git.CommandFactory) gitalypb.ConflictsServiceServer { return &server{ - ruby: rs, - cfg: cfg, - locator: locator, + ruby: rs, + cfg: cfg, + locator: locator, + gitCmdFactory: gitCmdFactory, pool: client.NewPoolWithOptions( client.WithDialer(client.HealthCheckDialer(client.DialContext)), client.WithDialOptions(client.FailOnNonTempDialError()...), diff --git a/internal/gitaly/service/conflicts/testhelper_test.go b/internal/gitaly/service/conflicts/testhelper_test.go index c64dff199..5e785db57 100644 --- a/internal/gitaly/service/conflicts/testhelper_test.go +++ b/internal/gitaly/service/conflicts/testhelper_test.go @@ -7,6 +7,7 @@ import ( "testing" log "github.com/sirupsen/logrus" + "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/git/hooks" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver" @@ -51,8 +52,9 @@ func testMain(m *testing.M) int { func runConflictsServer(t *testing.T) (string, func()) { srv := testhelper.NewServer(t, nil, nil) locator := config.NewLocator(config.Config) + gitCmdFactory := git.NewExecCommandFactory(config.Config) - gitalypb.RegisterConflictsServiceServer(srv.GrpcServer(), NewServer(RubyServer, config.Config, locator)) + gitalypb.RegisterConflictsServiceServer(srv.GrpcServer(), NewServer(RubyServer, config.Config, locator, gitCmdFactory)) reflection.Register(srv.GrpcServer()) srv.Start(t) diff --git a/internal/gitaly/service/operations/update_with_hooks.go b/internal/gitaly/service/operations/update_with_hooks.go index 2e2ce16e3..b77b14d53 100644 --- a/internal/gitaly/service/operations/update_with_hooks.go +++ b/internal/gitaly/service/operations/update_with_hooks.go @@ -88,7 +88,7 @@ func (s *Server) updateReferenceWithHooks(ctx context.Context, repo *gitalypb.Re return preReceiveError{message: err.Error()} } - updater, err := updateref.New(ctx, s.cfg, repo) + updater, err := updateref.New(ctx, s.cfg, s.gitCmdFactory, repo) if err != nil { return err } diff --git a/internal/gitaly/service/operations/update_with_hooks_test.go b/internal/gitaly/service/operations/update_with_hooks_test.go index 71992cdf1..38d3fbc5f 100644 --- a/internal/gitaly/service/operations/update_with_hooks_test.go +++ b/internal/gitaly/service/operations/update_with_hooks_test.go @@ -117,6 +117,7 @@ func TestUpdateReferenceWithHooks(t *testing.T) { // git-update-ref(1) spawned by `updateRefWithHooks()` txManager := transaction.NewManager(config.Config) hookManager := hook.NewManager(config.NewLocator(config.Config), txManager, hook.GitlabAPIStub, config.Config) + gitCmdFactory := git.NewExecCommandFactory(config.Config) gitalypb.RegisterHookServiceServer(server.GrpcServer(), hookservice.NewServer(config.Config, hookManager)) server.Start(t) @@ -265,7 +266,7 @@ func TestUpdateReferenceWithHooks(t *testing.T) { referenceTransaction: tc.referenceTransaction, } - hookServer := NewServer(config.Config, nil, hookManager, nil, nil, nil) + hookServer := NewServer(config.Config, nil, hookManager, nil, nil, gitCmdFactory) err := hookServer.updateReferenceWithHooks(ctx, repo, user, "refs/heads/master", git.ZeroOID.String(), oldRev) if tc.expectedErr == "" { diff --git a/internal/gitaly/service/ref/delete_refs.go b/internal/gitaly/service/ref/delete_refs.go index 2bbf6bfc1..49102ea0c 100644 --- a/internal/gitaly/service/ref/delete_refs.go +++ b/internal/gitaly/service/ref/delete_refs.go @@ -21,7 +21,7 @@ func (s *server) DeleteRefs(ctx context.Context, in *gitalypb.DeleteRefsRequest) return nil, status.Errorf(codes.InvalidArgument, "DeleteRefs: %v", err) } - updater, err := updateref.New(ctx, s.cfg, in.GetRepository()) + updater, err := updateref.New(ctx, s.cfg, s.gitCmdFactory, in.GetRepository()) if err != nil { if errors.Is(err, git.ErrInvalidArg) { return nil, helper.ErrInvalidArgument(err) diff --git a/internal/gitaly/service/ref/list_new_blobs.go b/internal/gitaly/service/ref/list_new_blobs.go index ea8dda4c0..44c546295 100644 --- a/internal/gitaly/service/ref/list_new_blobs.go +++ b/internal/gitaly/service/ref/list_new_blobs.go @@ -33,7 +33,7 @@ func (s *server) listNewBlobs(in *gitalypb.ListNewBlobsRequest, stream gitalypb. } // the added ^ is to negate the oid since there is a --not option that comes earlier in the arg list - revList, err := git.NewCommand(ctx, in.GetRepository(), nil, git.SubCmd{Name: "rev-list", Flags: cmdFlags, Args: []string{"^" + oid}}) + revList, err := s.gitCmdFactory.New(ctx, in.GetRepository(), nil, git.SubCmd{Name: "rev-list", Flags: cmdFlags, Args: []string{"^" + oid}}) if err != nil { return err } diff --git a/internal/gitaly/service/ref/list_new_commits.go b/internal/gitaly/service/ref/list_new_commits.go index d84e586f4..1b0333c84 100644 --- a/internal/gitaly/service/ref/list_new_commits.go +++ b/internal/gitaly/service/ref/list_new_commits.go @@ -26,7 +26,7 @@ func (s *server) ListNewCommits(in *gitalypb.ListNewCommitsRequest, stream gital func (s *server) listNewCommits(in *gitalypb.ListNewCommitsRequest, stream gitalypb.RefService_ListNewCommitsServer, oid string) error { ctx := stream.Context() - revList, err := git.NewCommand(ctx, in.GetRepository(), nil, git.SubCmd{ + revList, err := s.gitCmdFactory.New(ctx, in.GetRepository(), nil, git.SubCmd{ Name: "rev-list", Flags: []git.Option{git.Flag{Name: "--not"}, git.Flag{Name: "--all"}}, Args: []string{"^" + oid}, // the added ^ is to negate the oid since there is a --not option that comes earlier in the arg list diff --git a/internal/gitaly/service/ref/pack_refs.go b/internal/gitaly/service/ref/pack_refs.go index 9e8cbe9e6..c360c428d 100644 --- a/internal/gitaly/service/ref/pack_refs.go +++ b/internal/gitaly/service/ref/pack_refs.go @@ -11,12 +11,12 @@ import ( "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) -func (server) PackRefs(ctx context.Context, in *gitalypb.PackRefsRequest) (*gitalypb.PackRefsResponse, error) { +func (s *server) PackRefs(ctx context.Context, in *gitalypb.PackRefsRequest) (*gitalypb.PackRefsResponse, error) { if err := validatePackRefsRequest(in); err != nil { return nil, helper.ErrInvalidArgument(err) } - if err := packRefs(ctx, in.GetRepository(), in.GetAllRefs()); err != nil { + if err := s.packRefs(ctx, in.GetRepository(), in.GetAllRefs()); err != nil { return nil, helper.ErrInternal(err) } @@ -30,8 +30,8 @@ func validatePackRefsRequest(in *gitalypb.PackRefsRequest) error { return nil } -func packRefs(ctx context.Context, repository repository.GitRepo, all bool) error { - cmd, err := git.NewCommand(ctx, repository, nil, git.SubCmd{ +func (s *server) packRefs(ctx context.Context, repository repository.GitRepo, all bool) error { + cmd, err := s.gitCmdFactory.New(ctx, repository, nil, git.SubCmd{ Name: "pack-refs", Flags: []git.Option{git.Flag{Name: "--all"}}, }) diff --git a/internal/gitaly/service/ref/refexists.go b/internal/gitaly/service/ref/refexists.go index 437f1177d..4bcd54a12 100644 --- a/internal/gitaly/service/ref/refexists.go +++ b/internal/gitaly/service/ref/refexists.go @@ -12,14 +12,14 @@ import ( ) // RefExists returns true if the given reference exists. The ref must start with the string `ref/` -func (server) RefExists(ctx context.Context, in *gitalypb.RefExistsRequest) (*gitalypb.RefExistsResponse, error) { +func (s *server) RefExists(ctx context.Context, in *gitalypb.RefExistsRequest) (*gitalypb.RefExistsResponse, error) { ref := string(in.Ref) if !isValidRefName(ref) { return nil, helper.ErrInvalidArgument(fmt.Errorf("invalid refname")) } - exists, err := refExists(ctx, in.Repository, ref) + exists, err := s.refExists(ctx, in.Repository, ref) if err != nil { return nil, helper.ErrInternal(err) } @@ -27,8 +27,8 @@ func (server) RefExists(ctx context.Context, in *gitalypb.RefExistsRequest) (*gi return &gitalypb.RefExistsResponse{Value: exists}, nil } -func refExists(ctx context.Context, repo *gitalypb.Repository, ref string) (bool, error) { - cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ +func (s *server) refExists(ctx context.Context, repo *gitalypb.Repository, ref string) (bool, error) { + cmd, err := s.gitCmdFactory.New(ctx, repo, nil, git.SubCmd{ Name: "show-ref", Flags: []git.Option{git.Flag{Name: "--verify"}, git.Flag{Name: "--quiet"}}, Args: []string{ref}, diff --git a/internal/gitaly/service/ref/refname.go b/internal/gitaly/service/ref/refname.go index 199a07f23..6c191e50f 100644 --- a/internal/gitaly/service/ref/refname.go +++ b/internal/gitaly/service/ref/refname.go @@ -20,7 +20,7 @@ func (s *server) FindRefName(ctx context.Context, in *gitalypb.FindRefNameReques return nil, helper.ErrInvalidArgument(fmt.Errorf("empty commit sha")) } - ref, err := findRefName(ctx, in.Repository, in.CommitId, string(in.Prefix)) + ref, err := s.findRefName(ctx, in.Repository, in.CommitId, string(in.Prefix)) if err != nil { return nil, helper.ErrInternal(err) } @@ -29,7 +29,7 @@ func (s *server) FindRefName(ctx context.Context, in *gitalypb.FindRefNameReques } // We assume `repo` and `commitID` and `prefix` are non-empty -func findRefName(ctx context.Context, repo *gitalypb.Repository, commitID, prefix string) (string, error) { +func (s *server) findRefName(ctx context.Context, repo *gitalypb.Repository, commitID, prefix string) (string, error) { flags := []git.Option{ git.Flag{Name: "--format=%(refname)"}, git.Flag{Name: "--count=1"}, @@ -43,7 +43,7 @@ func findRefName(ctx context.Context, repo *gitalypb.Repository, commitID, prefi subCmd.Flags = flags subCmd.Args = []string{prefix} - cmd, err := git.NewCommand(ctx, repo, nil, subCmd) + cmd, err := s.gitCmdFactory.New(ctx, repo, nil, subCmd) if err != nil { return "", err } diff --git a/internal/gitaly/service/ref/refnames.go b/internal/gitaly/service/ref/refnames.go index 6e9f2f0a4..cda557116 100644 --- a/internal/gitaly/service/ref/refnames.go +++ b/internal/gitaly/service/ref/refnames.go @@ -15,7 +15,7 @@ import ( func (s *server) FindAllBranchNames(in *gitalypb.FindAllBranchNamesRequest, stream gitalypb.RefService_FindAllBranchNamesServer) error { chunker := chunk.New(&findAllBranchNamesSender{stream: stream}) - return listRefNames(stream.Context(), chunker, "refs/heads", in.Repository, nil) + return s.listRefNames(stream.Context(), chunker, "refs/heads", in.Repository, nil) } type findAllBranchNamesSender struct { @@ -36,7 +36,7 @@ func (ts *findAllBranchNamesSender) Send() error { func (s *server) FindAllTagNames(in *gitalypb.FindAllTagNamesRequest, stream gitalypb.RefService_FindAllTagNamesServer) error { chunker := chunk.New(&findAllTagNamesSender{stream: stream}) - return listRefNames(stream.Context(), chunker, "refs/tags", in.Repository, nil) + return s.listRefNames(stream.Context(), chunker, "refs/tags", in.Repository, nil) } type findAllTagNamesSender struct { @@ -53,7 +53,7 @@ func (ts *findAllTagNamesSender) Send() error { return ts.stream.Send(&gitalypb.FindAllTagNamesResponse{Names: ts.tagNames}) } -func listRefNames(ctx context.Context, chunker *chunk.Chunker, prefix string, repo *gitalypb.Repository, extraArgs []string) error { +func (s *server) listRefNames(ctx context.Context, chunker *chunk.Chunker, prefix string, repo *gitalypb.Repository, extraArgs []string) error { flags := []git.Option{ git.Flag{Name: "--format=%(refname)"}, } @@ -62,7 +62,7 @@ func listRefNames(ctx context.Context, chunker *chunk.Chunker, prefix string, re flags = append(flags, git.Flag{arg}) } - cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ + cmd, err := s.gitCmdFactory.New(ctx, repo, nil, git.SubCmd{ Name: "for-each-ref", Flags: flags, Args: []string{prefix}, diff --git a/internal/gitaly/service/ref/refnames_containing.go b/internal/gitaly/service/ref/refnames_containing.go index b30159e47..1c3678812 100644 --- a/internal/gitaly/service/ref/refnames_containing.go +++ b/internal/gitaly/service/ref/refnames_containing.go @@ -14,14 +14,14 @@ import ( // ListBranchNamesContainingCommit returns a maximum of in.GetLimit() Branch names // which contain the SHA1 passed as argument -func (*server) ListBranchNamesContainingCommit(in *gitalypb.ListBranchNamesContainingCommitRequest, stream gitalypb.RefService_ListBranchNamesContainingCommitServer) error { +func (s *server) ListBranchNamesContainingCommit(in *gitalypb.ListBranchNamesContainingCommitRequest, stream gitalypb.RefService_ListBranchNamesContainingCommitServer) error { if err := git.ValidateObjectID(in.GetCommitId()); err != nil { return helper.ErrInvalidArgument(err) } chunker := chunk.New(&branchNamesContainingCommitSender{stream: stream}) ctx := stream.Context() - if err := listRefNames(ctx, chunker, "refs/heads", in.Repository, containingArgs(in)); err != nil { + if err := s.listRefNames(ctx, chunker, "refs/heads", in.Repository, containingArgs(in)); err != nil { return helper.ErrInternal(err) } @@ -57,14 +57,14 @@ func (bs *branchNamesContainingCommitSender) Send() error { // ListTagNamesContainingCommit returns a maximum of in.GetLimit() Tag names // which contain the SHA1 passed as argument -func (*server) ListTagNamesContainingCommit(in *gitalypb.ListTagNamesContainingCommitRequest, stream gitalypb.RefService_ListTagNamesContainingCommitServer) error { +func (s *server) ListTagNamesContainingCommit(in *gitalypb.ListTagNamesContainingCommitRequest, stream gitalypb.RefService_ListTagNamesContainingCommitServer) error { if err := git.ValidateObjectID(in.GetCommitId()); err != nil { return helper.ErrInvalidArgument(err) } chunker := chunk.New(&tagNamesContainingCommitSender{stream: stream}) ctx := stream.Context() - if err := listRefNames(ctx, chunker, "refs/tags", in.Repository, containingArgs(in)); err != nil { + if err := s.listRefNames(ctx, chunker, "refs/tags", in.Repository, containingArgs(in)); err != nil { return helper.ErrInternal(err) } diff --git a/internal/gitaly/service/ref/refs.go b/internal/gitaly/service/ref/refs.go index 2d580dd03..3849895c0 100644 --- a/internal/gitaly/service/ref/refs.go +++ b/internal/gitaly/service/ref/refs.go @@ -39,7 +39,7 @@ type findRefsOpts struct { lines.SenderOpts } -func findRefs(ctx context.Context, writer lines.Sender, repo *gitalypb.Repository, patterns []string, opts *findRefsOpts) error { +func (s *server) findRefs(ctx context.Context, writer lines.Sender, repo *gitalypb.Repository, patterns []string, opts *findRefsOpts) error { var options []git.Option if len(opts.cmdArgs) == 0 { @@ -48,7 +48,7 @@ func findRefs(ctx context.Context, writer lines.Sender, repo *gitalypb.Repositor options = append(options, opts.cmdArgs...) } - cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ + cmd, err := s.gitCmdFactory.New(ctx, repo, nil, git.SubCmd{ Name: "for-each-ref", Flags: options, Args: patterns, @@ -88,7 +88,7 @@ func (t *tagSender) Send() error { } func (s *server) parseAndReturnTags(ctx context.Context, repo *gitalypb.Repository, stream gitalypb.RefService_FindAllTagsServer) error { - tagsCmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ + tagsCmd, err := s.gitCmdFactory.New(ctx, repo, nil, git.SubCmd{ Name: "for-each-ref", Flags: []git.Option{ git.ValueFlag{"--format", tagFormat}, @@ -154,10 +154,10 @@ func (s *server) validateFindAllTagsRequest(request *gitalypb.FindAllTagsRequest return nil } -func _findBranchNames(ctx context.Context, repo *gitalypb.Repository) ([][]byte, error) { +func _findBranchNames(ctx context.Context, gitCmdFactory git.CommandFactory, repo *gitalypb.Repository) ([][]byte, error) { var names [][]byte - cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ + cmd, err := gitCmdFactory.New(ctx, repo, nil, git.SubCmd{ Name: "for-each-ref", Flags: []git.Option{git.Flag{Name: "--format=%(refname)"}}, Args: []string{"refs/heads"}}, @@ -181,10 +181,10 @@ func _findBranchNames(ctx context.Context, repo *gitalypb.Repository) ([][]byte, return names, nil } -func _headReference(ctx context.Context, repo *gitalypb.Repository) ([]byte, error) { +func _headReference(ctx context.Context, gitCmdFactory git.CommandFactory, repo *gitalypb.Repository) ([]byte, error) { var headRef []byte - cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ + cmd, err := gitCmdFactory.New(ctx, repo, nil, git.SubCmd{ Name: "rev-parse", Flags: []git.Option{git.Flag{Name: "--symbolic-full-name"}}, Args: []string{"HEAD"}, @@ -214,8 +214,8 @@ func _headReference(ctx context.Context, repo *gitalypb.Repository) ([]byte, err } // SetDefaultBranchRef overwrites the default branch ref for the repository -func SetDefaultBranchRef(ctx context.Context, repo *gitalypb.Repository, ref string, cfg config.Cfg) error { - cmd, err := git.NewCommand(ctx, repo, nil, git.SubCmd{ +func SetDefaultBranchRef(ctx context.Context, gitCmdFactory git.CommandFactory, repo *gitalypb.Repository, ref string, cfg config.Cfg) error { + cmd, err := gitCmdFactory.New(ctx, repo, nil, git.SubCmd{ Name: "symbolic-ref", Args: []string{"HEAD", ref}, }, git.WithRefTxHook(ctx, repo, cfg)) @@ -226,8 +226,8 @@ func SetDefaultBranchRef(ctx context.Context, repo *gitalypb.Repository, ref str } // DefaultBranchName looks up the name of the default branch given a repoPath -func DefaultBranchName(ctx context.Context, repo *gitalypb.Repository) ([]byte, error) { - branches, err := FindBranchNames(ctx, repo) +func DefaultBranchName(ctx context.Context, gitCmdFactory git.CommandFactory, repo *gitalypb.Repository) ([]byte, error) { + branches, err := FindBranchNames(ctx, gitCmdFactory, repo) if err != nil { return nil, err @@ -244,7 +244,7 @@ func DefaultBranchName(ctx context.Context, repo *gitalypb.Repository) ([]byte, } hasMaster := false - headRef, err := headReference(ctx, repo) + headRef, err := headReference(ctx, gitCmdFactory, repo) if err != nil { return nil, err } @@ -268,7 +268,7 @@ func DefaultBranchName(ctx context.Context, repo *gitalypb.Repository) ([]byte, // FindDefaultBranchName returns the default branch name for the given repository func (s *server) FindDefaultBranchName(ctx context.Context, in *gitalypb.FindDefaultBranchNameRequest) (*gitalypb.FindDefaultBranchNameResponse, error) { - defaultBranchName, err := DefaultBranchName(ctx, in.Repository) + defaultBranchName, err := DefaultBranchName(ctx, s.gitCmdFactory, in.Repository) if err != nil { return nil, helper.ErrInternal(err) } @@ -313,7 +313,7 @@ func (s *server) findLocalBranches(in *gitalypb.FindLocalBranchesRequest, stream git.Flag{Name: "--sort=" + parseSortKey(in.GetSortBy())}, } - return findRefs(ctx, writer, in.Repository, []string{"refs/heads"}, opts) + return s.findRefs(ctx, writer, in.Repository, []string{"refs/heads"}, opts) } func (s *server) FindAllBranches(in *gitalypb.FindAllBranchesRequest, stream gitalypb.RefService_FindAllBranchesServer) error { @@ -333,7 +333,7 @@ func (s *server) findAllBranches(in *gitalypb.FindAllBranchesRequest, stream git patterns := []string{"refs/heads", "refs/remotes"} if in.MergedOnly { - defaultBranchName, err := DefaultBranchName(stream.Context(), in.Repository) + defaultBranchName, err := DefaultBranchName(stream.Context(), s.gitCmdFactory, in.Repository) if err != nil { return err } @@ -360,7 +360,7 @@ func (s *server) findAllBranches(in *gitalypb.FindAllBranchesRequest, stream git writer := newFindAllBranchesWriter(stream, c) - return findRefs(ctx, writer, in.Repository, patterns, opts) + return s.findRefs(ctx, writer, in.Repository, patterns, opts) } func (s *server) FindTag(ctx context.Context, in *gitalypb.FindTagRequest) (*gitalypb.FindTagResponse, error) { @@ -413,7 +413,7 @@ func parseTagLine(ctx context.Context, c catfile.Batch, tagLine string) (*gitaly } func (s *server) findTag(ctx context.Context, repository *gitalypb.Repository, tagName []byte) (*gitalypb.Tag, error) { - tagCmd, err := git.NewCommand(ctx, repository, nil, + tagCmd, err := s.gitCmdFactory.New(ctx, repository, nil, git.SubCmd{ Name: "tag", Flags: []git.Option{ diff --git a/internal/gitaly/service/ref/refs_test.go b/internal/gitaly/service/ref/refs_test.go index 7dccb28a5..d52db72ac 100644 --- a/internal/gitaly/service/ref/refs_test.go +++ b/internal/gitaly/service/ref/refs_test.go @@ -82,7 +82,7 @@ func TestFindAllBranchNamesVeryLargeResponse(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - updater, err := updateref.New(ctx, config.Config, testRepo) + updater, err := updateref.New(ctx, config.Config, git.NewExecCommandFactory(config.Config), testRepo) require.NoError(t, err) // We want to create enough refs to overflow the default bufio.Scanner @@ -272,7 +272,7 @@ func TestHeadReference(t *testing.T) { testRepo, _, cleanupFn := testhelper.NewTestRepo(t) defer cleanupFn() - headRef, err := headReference(ctx, testRepo) + headRef, err := headReference(ctx, git.NewExecCommandFactory(config.Config), testRepo) if err != nil { t.Fatal(err) } @@ -294,7 +294,7 @@ func TestHeadReferenceWithNonExistingHead(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - headRef, err := headReference(ctx, testRepo) + headRef, err := headReference(ctx, git.NewExecCommandFactory(config.Config), testRepo) if err != nil { t.Fatal(err) } @@ -329,10 +329,11 @@ func TestSetDefaultBranchRef(t *testing.T) { testRepo, _, cleanupFn := testhelper.NewTestRepo(t) defer cleanupFn() - err := SetDefaultBranchRef(ctx, testRepo, tc.ref, config.Config) + gitCmdFactory := git.NewExecCommandFactory(config.Config) + err := SetDefaultBranchRef(ctx, gitCmdFactory, testRepo, tc.ref, config.Config) require.NoError(t, err) - newRef, err := DefaultBranchName(ctx, testRepo) + newRef, err := DefaultBranchName(ctx, gitCmdFactory, testRepo) require.NoError(t, err) require.Equal(t, tc.expectedRef, string(newRef)) @@ -352,47 +353,51 @@ func TestDefaultBranchName(t *testing.T) { testCases := []struct { desc string - findBranchNames func(context.Context, *gitalypb.Repository) ([][]byte, error) - headReference func(context.Context, *gitalypb.Repository) ([]byte, error) + findBranchNames func(context.Context, git.CommandFactory, *gitalypb.Repository) ([][]byte, error) + headReference func(context.Context, git.CommandFactory, *gitalypb.Repository) ([]byte, error) expected []byte }{ { desc: "Get first branch when only one branch exists", expected: []byte("refs/heads/foo"), - findBranchNames: func(context.Context, *gitalypb.Repository) ([][]byte, error) { + findBranchNames: func(context.Context, git.CommandFactory, *gitalypb.Repository) ([][]byte, error) { return [][]byte{[]byte("refs/heads/foo")}, nil }, - headReference: func(context.Context, *gitalypb.Repository) ([]byte, error) { return nil, nil }, + headReference: func(context.Context, git.CommandFactory, *gitalypb.Repository) ([]byte, error) { return nil, nil }, }, { - desc: "Get empy ref if no branches exists", - expected: nil, - findBranchNames: func(context.Context, *gitalypb.Repository) ([][]byte, error) { return [][]byte{}, nil }, - headReference: func(context.Context, *gitalypb.Repository) ([]byte, error) { return nil, nil }, + desc: "Get empy ref if no branches exists", + expected: nil, + findBranchNames: func(context.Context, git.CommandFactory, *gitalypb.Repository) ([][]byte, error) { + return [][]byte{}, nil + }, + headReference: func(context.Context, git.CommandFactory, *gitalypb.Repository) ([]byte, error) { return nil, nil }, }, { desc: "Get the name of the head reference when more than one branch exists", expected: []byte("refs/heads/bar"), - findBranchNames: func(context.Context, *gitalypb.Repository) ([][]byte, error) { + findBranchNames: func(context.Context, git.CommandFactory, *gitalypb.Repository) ([][]byte, error) { return [][]byte{[]byte("refs/heads/foo"), []byte("refs/heads/bar")}, nil }, - headReference: func(context.Context, *gitalypb.Repository) ([]byte, error) { return []byte("refs/heads/bar"), nil }, + headReference: func(context.Context, git.CommandFactory, *gitalypb.Repository) ([]byte, error) { + return []byte("refs/heads/bar"), nil + }, }, { desc: "Get `ref/heads/master` when several branches exist", expected: []byte("refs/heads/master"), - findBranchNames: func(context.Context, *gitalypb.Repository) ([][]byte, error) { + findBranchNames: func(context.Context, git.CommandFactory, *gitalypb.Repository) ([][]byte, error) { return [][]byte{[]byte("refs/heads/foo"), []byte("refs/heads/master"), []byte("refs/heads/bar")}, nil }, - headReference: func(context.Context, *gitalypb.Repository) ([]byte, error) { return nil, nil }, + headReference: func(context.Context, git.CommandFactory, *gitalypb.Repository) ([]byte, error) { return nil, nil }, }, { desc: "Get the name of the first branch when several branches exists and no other conditions are met", expected: []byte("refs/heads/foo"), - findBranchNames: func(context.Context, *gitalypb.Repository) ([][]byte, error) { + findBranchNames: func(context.Context, git.CommandFactory, *gitalypb.Repository) ([][]byte, error) { return [][]byte{[]byte("refs/heads/foo"), []byte("refs/heads/bar"), []byte("refs/heads/baz")}, nil }, - headReference: func(context.Context, *gitalypb.Repository) ([]byte, error) { return nil, nil }, + headReference: func(context.Context, git.CommandFactory, *gitalypb.Repository) ([]byte, error) { return nil, nil }, }, } @@ -402,7 +407,7 @@ func TestDefaultBranchName(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - defaultBranch, err := DefaultBranchName(ctx, testRepo) + defaultBranch, err := DefaultBranchName(ctx, git.NewExecCommandFactory(config.Config), testRepo) if err != nil { t.Fatal(err) } diff --git a/internal/gitaly/service/ref/remote_branches.go b/internal/gitaly/service/ref/remote_branches.go index 01776f221..f753c4c9a 100644 --- a/internal/gitaly/service/ref/remote_branches.go +++ b/internal/gitaly/service/ref/remote_branches.go @@ -39,7 +39,7 @@ func (s *server) findAllRemoteBranches(req *gitalypb.FindAllRemoteBranchesReques opts.cmdArgs = args writer := newFindAllRemoteBranchesWriter(stream, c) - return findRefs(ctx, writer, req.GetRepository(), patterns, opts) + return s.findRefs(ctx, writer, req.GetRepository(), patterns, opts) } func validateFindAllRemoteBranchesRequest(req *gitalypb.FindAllRemoteBranchesRequest) error { diff --git a/internal/gitaly/service/ref/testhelper_test.go b/internal/gitaly/service/ref/testhelper_test.go index b402dffe4..5055e7b21 100644 --- a/internal/gitaly/service/ref/testhelper_test.go +++ b/internal/gitaly/service/ref/testhelper_test.go @@ -44,13 +44,15 @@ func testMain(m *testing.M) int { } func runRefServiceServer(t *testing.T) (func(), string) { - locator := config.NewLocator(config.Config) - txManager := transaction.NewManager(config.Config) - hookManager := hook.NewManager(locator, txManager, hook.GitlabAPIStub, config.Config) - - srv := testhelper.NewServer(t, nil, nil, testhelper.WithInternalSocket(config.Config)) - gitalypb.RegisterRefServiceServer(srv.GrpcServer(), NewServer(config.Config, locator, git.NewExecCommandFactory(config.Config))) - gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hookservice.NewServer(config.Config, hookManager)) + cfg := config.Config + locator := config.NewLocator(cfg) + txManager := transaction.NewManager(cfg) + hookManager := hook.NewManager(locator, txManager, hook.GitlabAPIStub, cfg) + gitCmdFactory := git.NewExecCommandFactory(cfg) + + srv := testhelper.NewServer(t, nil, nil, testhelper.WithInternalSocket(cfg)) + gitalypb.RegisterRefServiceServer(srv.GrpcServer(), NewServer(cfg, locator, gitCmdFactory)) + gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hookservice.NewServer(cfg, hookManager)) srv.Start(t) return srv.Stop, "unix://" + srv.Socket() diff --git a/internal/gitaly/service/register.go b/internal/gitaly/service/register.go index 816cb48f4..120512785 100644 --- a/internal/gitaly/service/register.go +++ b/internal/gitaly/service/register.go @@ -84,10 +84,11 @@ func RegisterAll( gitalypb.RegisterSmartHTTPServiceServer(grpcServer, smarthttp.NewServer( cfg, locator, + gitCmdFactory, smarthttp.WithPackfileNegotiationMetrics(smarthttpPackfileNegotiationMetrics), )) gitalypb.RegisterWikiServiceServer(grpcServer, wiki.NewServer(rubyServer, locator)) - gitalypb.RegisterConflictsServiceServer(grpcServer, conflicts.NewServer(rubyServer, cfg, locator)) + gitalypb.RegisterConflictsServiceServer(grpcServer, conflicts.NewServer(rubyServer, cfg, locator, gitCmdFactory)) gitalypb.RegisterRemoteServiceServer(grpcServer, remote.NewServer(cfg, rubyServer, locator, gitCmdFactory)) gitalypb.RegisterServerServiceServer(grpcServer, server.NewServer(cfg.Storages)) gitalypb.RegisterObjectPoolServiceServer(grpcServer, objectpool.NewServer(cfg, locator, gitCmdFactory)) diff --git a/internal/gitaly/service/remote/fetch_internal_remote.go b/internal/gitaly/service/remote/fetch_internal_remote.go index 84bfc20e8..2023b8c9f 100644 --- a/internal/gitaly/service/remote/fetch_internal_remote.go +++ b/internal/gitaly/service/remote/fetch_internal_remote.go @@ -57,13 +57,13 @@ func (s *server) FetchInternalRemote(ctx context.Context, req *gitalypb.FetchInt return nil, status.Errorf(codes.Internal, "FetchInternalRemote: remote default branch: %v", err) } - defaultBranch, err := ref.DefaultBranchName(ctx, req.Repository) + defaultBranch, err := ref.DefaultBranchName(ctx, s.gitCmdFactory, req.Repository) if err != nil { return nil, status.Errorf(codes.Internal, "FetchInternalRemote: default branch: %v", err) } if !bytes.Equal(defaultBranch, remoteDefaultBranch) { - if err := ref.SetDefaultBranchRef(ctx, req.Repository, string(remoteDefaultBranch), config.Config); err != nil { + if err := ref.SetDefaultBranchRef(ctx, s.gitCmdFactory, req.Repository, string(remoteDefaultBranch), config.Config); err != nil { return nil, status.Errorf(codes.Internal, "FetchInternalRemote: set default branch: %v", err) } } diff --git a/internal/gitaly/service/repository/optimize_test.go b/internal/gitaly/service/repository/optimize_test.go index 5e2ebed70..f8ea4a61c 100644 --- a/internal/gitaly/service/repository/optimize_test.go +++ b/internal/gitaly/service/repository/optimize_test.go @@ -101,7 +101,7 @@ func TestOptimizeRepository(t *testing.T) { blobs := 10 blobIDs := testhelper.WriteBlobs(t, testRepoPath, blobs) - updater, err := updateref.New(ctx, config.Config, testRepo) + updater, err := updateref.New(ctx, config.Config, git.NewExecCommandFactory(config.Config), testRepo) require.NoError(t, err) for _, blobID := range blobIDs { diff --git a/internal/gitaly/service/repository/write_ref.go b/internal/gitaly/service/repository/write_ref.go index f35381ccf..a41f6571c 100644 --- a/internal/gitaly/service/repository/write_ref.go +++ b/internal/gitaly/service/repository/write_ref.go @@ -27,7 +27,7 @@ func (s *server) writeRef(ctx context.Context, req *gitalypb.WriteRefRequest) er if string(req.Ref) == "HEAD" { return s.updateSymbolicRef(ctx, req) } - return updateRef(ctx, s.cfg, req) + return updateRef(ctx, s.cfg, s.gitCmdFactory, req) } func (s *server) updateSymbolicRef(ctx context.Context, req *gitalypb.WriteRefRequest) error { @@ -47,8 +47,8 @@ func (s *server) updateSymbolicRef(ctx context.Context, req *gitalypb.WriteRefRe return nil } -func updateRef(ctx context.Context, cfg config.Cfg, req *gitalypb.WriteRefRequest) error { - u, err := updateref.New(ctx, cfg, req.GetRepository()) +func updateRef(ctx context.Context, cfg config.Cfg, gitCmdFactory git.CommandFactory, req *gitalypb.WriteRefRequest) error { + u, err := updateref.New(ctx, cfg, gitCmdFactory, req.GetRepository()) if err != nil { return fmt.Errorf("error when running creating new updater: %v", err) } diff --git a/internal/gitaly/service/smarthttp/inforefs.go b/internal/gitaly/service/smarthttp/inforefs.go index 7dc18e6e3..800bf1fd0 100644 --- a/internal/gitaly/service/smarthttp/inforefs.go +++ b/internal/gitaly/service/smarthttp/inforefs.go @@ -58,7 +58,7 @@ func (s *server) handleInfoRefs(ctx context.Context, service string, req *gitaly globalOpts[i] = git.ValueFlag{"-c", o} } - cmd, err := git.NewCommandWithoutRepo(ctx, globalOpts, git.SubCmd{ + cmd, err := s.gitCmdFactory.NewWithoutRepo(ctx, globalOpts, git.SubCmd{ Name: service, Flags: []git.Option{git.Flag{Name: "--stateless-rpc"}, git.Flag{Name: "--advertise-refs"}}, Args: []string{repoPath}, diff --git a/internal/gitaly/service/smarthttp/receive_pack.go b/internal/gitaly/service/smarthttp/receive_pack.go index 458842868..4ddd31b59 100644 --- a/internal/gitaly/service/smarthttp/receive_pack.go +++ b/internal/gitaly/service/smarthttp/receive_pack.go @@ -47,7 +47,7 @@ func (s *server) PostReceivePack(stream gitalypb.SmartHTTPService_PostReceivePac globalOpts[i] = git.ValueFlag{"-c", o} } - cmd, err := git.NewCommandWithoutRepo(ctx, globalOpts, + cmd, err := s.gitCmdFactory.NewWithoutRepo(ctx, globalOpts, git.SubCmd{ Name: "receive-pack", Flags: []git.Option{git.Flag{Name: "--stateless-rpc"}}, diff --git a/internal/gitaly/service/smarthttp/receive_pack_test.go b/internal/gitaly/service/smarthttp/receive_pack_test.go index 587437ead..3b3e66b81 100644 --- a/internal/gitaly/service/smarthttp/receive_pack_test.go +++ b/internal/gitaly/service/smarthttp/receive_pack_test.go @@ -455,7 +455,7 @@ func runSmartHTTPHookServiceServer(t *testing.T) (*grpc.Server, string) { txManager := transaction.NewManager(config.Config) hookManager := gitalyhook.NewManager(locator, txManager, gitalyhook.GitlabAPIStub, config.Config) - gitalypb.RegisterSmartHTTPServiceServer(server, NewServer(config.Config, locator)) + gitalypb.RegisterSmartHTTPServiceServer(server, NewServer(config.Config, locator, git.NewExecCommandFactory(config.Config))) gitalypb.RegisterHookServiceServer(server, hook.NewServer(config.Config, hookManager)) reflection.Register(server) @@ -513,7 +513,7 @@ func testPostReceiveWithTransactionsViaPraefect(t *testing.T, ctx context.Contex gitalyServer := testhelper.NewServerWithAuth(t, nil, nil, config.Config.Auth.Token) - gitalypb.RegisterSmartHTTPServiceServer(gitalyServer.GrpcServer(), NewServer(config.Config, locator)) + gitalypb.RegisterSmartHTTPServiceServer(gitalyServer.GrpcServer(), NewServer(config.Config, locator, git.NewExecCommandFactory(config.Config))) gitalypb.RegisterHookServiceServer(gitalyServer.GrpcServer(), hook.NewServer(config.Config, hookManager)) reflection.Register(gitalyServer.GrpcServer()) gitalyServer.Start(t) @@ -561,7 +561,7 @@ func TestPostReceiveWithReferenceTransactionHook(t *testing.T) { hookManager := gitalyhook.NewManager(locator, txManager, gitalyhook.GitlabAPIStub, config.Config) gitalyServer := testhelper.NewTestGrpcServer(t, nil, nil) - gitalypb.RegisterSmartHTTPServiceServer(gitalyServer, NewServer(config.Config, locator)) + gitalypb.RegisterSmartHTTPServiceServer(gitalyServer, NewServer(config.Config, locator, git.NewExecCommandFactory(config.Config))) gitalypb.RegisterHookServiceServer(gitalyServer, hook.NewServer(config.Config, hookManager)) gitalypb.RegisterRefTransactionServer(gitalyServer, refTransactionServer) healthpb.RegisterHealthServer(gitalyServer, health.NewServer()) diff --git a/internal/gitaly/service/smarthttp/server.go b/internal/gitaly/service/smarthttp/server.go index 0fca36890..443dda253 100644 --- a/internal/gitaly/service/smarthttp/server.go +++ b/internal/gitaly/service/smarthttp/server.go @@ -3,6 +3,7 @@ package smarthttp import ( "github.com/prometheus/client_golang/prometheus" "gitlab.com/gitlab-org/gitaly/internal/cache" + "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/storage" "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" @@ -11,15 +12,17 @@ import ( type server struct { cfg config.Cfg locator storage.Locator + gitCmdFactory git.CommandFactory packfileNegotiationMetrics *prometheus.CounterVec infoRefCache infoRefCache } // NewServer creates a new instance of a grpc SmartHTTPServer -func NewServer(cfg config.Cfg, locator storage.Locator, serverOpts ...ServerOpt) gitalypb.SmartHTTPServiceServer { +func NewServer(cfg config.Cfg, locator storage.Locator, gitCmdFactory git.CommandFactory, serverOpts ...ServerOpt) gitalypb.SmartHTTPServiceServer { s := &server{ - cfg: cfg, - locator: locator, + cfg: cfg, + locator: locator, + gitCmdFactory: gitCmdFactory, packfileNegotiationMetrics: prometheus.NewCounterVec( prometheus.CounterOpts{}, []string{"git_negotiation_feature"}, diff --git a/internal/gitaly/service/smarthttp/testhelper_test.go b/internal/gitaly/service/smarthttp/testhelper_test.go index 743461e64..6687e792c 100644 --- a/internal/gitaly/service/smarthttp/testhelper_test.go +++ b/internal/gitaly/service/smarthttp/testhelper_test.go @@ -8,6 +8,7 @@ import ( log "github.com/sirupsen/logrus" gitalyauth "gitlab.com/gitlab-org/gitaly/auth" diskcache "gitlab.com/gitlab-org/gitaly/internal/cache" + "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/gitaly/hook" hookservice "gitlab.com/gitlab-org/gitaly/internal/gitaly/service/hook" @@ -61,7 +62,7 @@ func runSmartHTTPServer(t *testing.T, serverOpts ...ServerOpt) (string, func()) }, testhelper.WithInternalSocket(config.Config)) - gitalypb.RegisterSmartHTTPServiceServer(srv.GrpcServer(), NewServer(config.Config, locator, serverOpts...)) + gitalypb.RegisterSmartHTTPServiceServer(srv.GrpcServer(), NewServer(config.Config, locator, git.NewExecCommandFactory(config.Config), serverOpts...)) gitalypb.RegisterHookServiceServer(srv.GrpcServer(), hookservice.NewServer(config.Config, hookManager)) srv.Start(t) diff --git a/internal/gitaly/service/smarthttp/upload_pack.go b/internal/gitaly/service/smarthttp/upload_pack.go index 31c6d964f..29ba2f964 100644 --- a/internal/gitaly/service/smarthttp/upload_pack.go +++ b/internal/gitaly/service/smarthttp/upload_pack.go @@ -88,7 +88,7 @@ func (s *server) PostUploadPack(stream gitalypb.SmartHTTPService_PostUploadPackS commandOpts = append(commandOpts, git.WithPackObjectsHookEnv(ctx, req.Repository, s.cfg)) } - cmd, err := git.NewCommandWithoutRepo(ctx, globalOpts, git.SubCmd{ + cmd, err := s.gitCmdFactory.NewWithoutRepo(ctx, globalOpts, git.SubCmd{ Name: "upload-pack", Flags: []git.Option{git.Flag{Name: "--stateless-rpc"}}, Args: []string{repoPath}, |