diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-06-14 11:53:21 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-06-14 12:32:32 +0300 |
commit | e1d2df8adfcc548fac7d5a01677429c0d246d7e9 (patch) | |
tree | 9af19268e85abdfd8b54b1600d556a5c02a8701d | |
parent | f365b27d869b4e96850a10bdd40b775ab37045b6 (diff) |
ref: Refactor `SetDefaultBranchRef()` to receive repo executor
Instead of having to pass around the command factory, we nowadays often
use the `git.RepositoryExecutor` interface which gets implemented by our
localrepo structure. Let's refactor `SetDefaultBranchRef()` to use this
interface.
-rw-r--r-- | internal/gitaly/service/ref/refs.go | 9 | ||||
-rw-r--r-- | internal/gitaly/service/ref/refs_test.go | 4 | ||||
-rw-r--r-- | internal/gitaly/service/remote/fetch_internal_remote.go | 2 |
3 files changed, 6 insertions, 9 deletions
diff --git a/internal/gitaly/service/ref/refs.go b/internal/gitaly/service/ref/refs.go index 37ec2ea25..107c469bb 100644 --- a/internal/gitaly/service/ref/refs.go +++ b/internal/gitaly/service/ref/refs.go @@ -213,15 +213,14 @@ func _headReference(ctx context.Context, repo git.RepositoryExecutor) ([]byte, e } // SetDefaultBranchRef overwrites the default branch ref for the repository -func SetDefaultBranchRef(ctx context.Context, gitCmdFactory git.CommandFactory, repo *gitalypb.Repository, ref string, cfg config.Cfg) error { - cmd, err := gitCmdFactory.New(ctx, repo, git.SubCmd{ +func SetDefaultBranchRef(ctx context.Context, repo git.RepositoryExecutor, ref string, cfg config.Cfg) error { + if err := repo.ExecAndWait(ctx, git.SubCmd{ Name: "symbolic-ref", Args: []string{"HEAD", ref}, - }, git.WithRefTxHook(ctx, repo, cfg)) - if err != nil { + }, git.WithRefTxHook(ctx, repo, cfg)); err != nil { return err } - return cmd.Wait() + return nil } // DefaultBranchName looks up the name of the default branch given a repoPath diff --git a/internal/gitaly/service/ref/refs_test.go b/internal/gitaly/service/ref/refs_test.go index a1ac70454..f07a61e41 100644 --- a/internal/gitaly/service/ref/refs_test.go +++ b/internal/gitaly/service/ref/refs_test.go @@ -278,9 +278,7 @@ func TestSetDefaultBranchRef(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - gitCmdFactory := git.NewExecCommandFactory(cfg) - err := SetDefaultBranchRef(ctx, gitCmdFactory, repoProto, tc.ref, cfg) - require.NoError(t, err) + require.NoError(t, SetDefaultBranchRef(ctx, repo, tc.ref, cfg)) newRef, err := DefaultBranchName(ctx, repo) require.NoError(t, err) diff --git a/internal/gitaly/service/remote/fetch_internal_remote.go b/internal/gitaly/service/remote/fetch_internal_remote.go index a44ccd06d..6fe79186e 100644 --- a/internal/gitaly/service/remote/fetch_internal_remote.go +++ b/internal/gitaly/service/remote/fetch_internal_remote.go @@ -83,7 +83,7 @@ func (s *server) FetchInternalRemote(ctx context.Context, req *gitalypb.FetchInt } if !bytes.Equal(defaultBranch, remoteDefaultBranch) { - if err := ref.SetDefaultBranchRef(ctx, s.gitCmdFactory, req.GetRepository(), string(remoteDefaultBranch), s.cfg); err != nil { + if err := ref.SetDefaultBranchRef(ctx, repo, string(remoteDefaultBranch), s.cfg); err != nil { return nil, status.Errorf(codes.Internal, "FetchInternalRemote: set default branch: %v", err) } } |