diff options
author | Pavlo Strokov <pstrokov@gitlab.com> | 2020-11-19 11:08:30 +0300 |
---|---|---|
committer | Pavlo Strokov <pstrokov@gitlab.com> | 2020-11-19 11:08:30 +0300 |
commit | 9162238ae9f5f1b4ca452965fbdbe1dc4f80fef8 (patch) | |
tree | 8e85b31a70c627912577ba1cf66f589e13183e70 | |
parent | a2d7d5ad16d47d64761786d760a02f79e666bbce (diff) | |
parent | fd21cba723276997344e7aace9cb62726c30cb03 (diff) |
Merge branch 'smh-subpackage-repo-implementations' into 'master'
Move RemoteRepository in to a subpackage
See merge request gitlab-org/gitaly!2803
-rw-r--r-- | internal/git/remote.go | 50 | ||||
-rw-r--r-- | internal/git/remoterepo/helper_test.go | 19 | ||||
-rw-r--r-- | internal/git/remoterepo/repository.go | 58 | ||||
-rw-r--r-- | internal/git/remoterepo/repository_test.go | 37 | ||||
-rw-r--r-- | internal/git/repository_suite.go | 77 | ||||
-rw-r--r-- | internal/git/repository_test.go | 198 | ||||
-rw-r--r-- | internal/gitaly/service/conflicts/resolve_conflicts.go | 3 | ||||
-rw-r--r-- | internal/gitaly/service/operations/commit_files.go | 3 |
8 files changed, 258 insertions, 187 deletions
diff --git a/internal/git/remote.go b/internal/git/remote.go index 48a035d2a..b6b29dcfb 100644 --- a/internal/git/remote.go +++ b/internal/git/remote.go @@ -3,64 +3,14 @@ package git import ( "bytes" "context" - "fmt" "strings" - "gitlab.com/gitlab-org/gitaly/client" "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/git/repository" "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/helper" - "gitlab.com/gitlab-org/gitaly/internal/storage" - "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) -// RemoteRepository represents a Git repository on a different Gitaly storage -type RemoteRepository struct { - repo *gitalypb.Repository - server storage.ServerInfo - pool *client.Pool -} - -// NewRepository creates a new remote Repository from its protobuf representation. -func NewRemoteRepository(ctx context.Context, repo *gitalypb.Repository, pool *client.Pool) (Repository, error) { - server, err := helper.ExtractGitalyServer(ctx, repo.GetStorageName()) - if err != nil { - return nil, fmt.Errorf("remote repository: %w", err) - } - - return RemoteRepository{ - repo: repo, - server: server, - pool: pool, - }, nil -} - -// ResolveRefish will dial to the remote repository and attempt to resolve the -// refish string via the gRPC interface -func (rr RemoteRepository) ResolveRefish(ctx context.Context, ref string) (string, error) { - cc, err := rr.pool.Dial(ctx, rr.server.Address, rr.server.Token) - if err != nil { - return "", err - } - - cli := gitalypb.NewCommitServiceClient(cc) - resp, err := cli.FindCommit(ctx, &gitalypb.FindCommitRequest{ - Repository: rr.repo, - Revision: []byte(ref), - }) - if err != nil { - return "", err - } - - oid := resp.GetCommit().GetId() - if oid == "" { - return "", ErrReferenceNotFound - } - - return oid, nil -} - // Remote represents 'remote' sub-command. // https://git-scm.com/docs/git-remote type Remote interface { diff --git a/internal/git/remoterepo/helper_test.go b/internal/git/remoterepo/helper_test.go new file mode 100644 index 000000000..c61785c01 --- /dev/null +++ b/internal/git/remoterepo/helper_test.go @@ -0,0 +1,19 @@ +package remoterepo + +import ( + "os" + "testing" + + "gitlab.com/gitlab-org/gitaly/internal/testhelper" +) + +func TestMain(m *testing.M) { + os.Exit(testMain(m)) +} + +func testMain(m *testing.M) int { + defer testhelper.MustHaveNoChildProcess() + cleanup := testhelper.Configure() + defer cleanup() + return m.Run() +} diff --git a/internal/git/remoterepo/repository.go b/internal/git/remoterepo/repository.go new file mode 100644 index 000000000..b4e959137 --- /dev/null +++ b/internal/git/remoterepo/repository.go @@ -0,0 +1,58 @@ +package remoterepo + +import ( + "context" + "fmt" + + "gitlab.com/gitlab-org/gitaly/client" + "gitlab.com/gitlab-org/gitaly/internal/git" + "gitlab.com/gitlab-org/gitaly/internal/helper" + "gitlab.com/gitlab-org/gitaly/internal/storage" + "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" +) + +// Repository represents a Git repository on a different Gitaly storage +type Repository struct { + repo *gitalypb.Repository + server storage.ServerInfo + pool *client.Pool +} + +// New creates a new remote Repository from its protobuf representation. +func New(ctx context.Context, repo *gitalypb.Repository, pool *client.Pool) (Repository, error) { + server, err := helper.ExtractGitalyServer(ctx, repo.GetStorageName()) + if err != nil { + return Repository{}, fmt.Errorf("remote repository: %w", err) + } + + return Repository{ + repo: repo, + server: server, + pool: pool, + }, nil +} + +// ResolveRefish will dial to the remote repository and attempt to resolve the +// refish string via the gRPC interface +func (rr Repository) ResolveRefish(ctx context.Context, ref string) (string, error) { + cc, err := rr.pool.Dial(ctx, rr.server.Address, rr.server.Token) + if err != nil { + return "", err + } + + cli := gitalypb.NewCommitServiceClient(cc) + resp, err := cli.FindCommit(ctx, &gitalypb.FindCommitRequest{ + Repository: rr.repo, + Revision: []byte(ref), + }) + if err != nil { + return "", err + } + + oid := resp.GetCommit().GetId() + if oid == "" { + return "", git.ErrReferenceNotFound + } + + return oid, nil +} diff --git a/internal/git/remoterepo/repository_test.go b/internal/git/remoterepo/repository_test.go new file mode 100644 index 000000000..b88a55413 --- /dev/null +++ b/internal/git/remoterepo/repository_test.go @@ -0,0 +1,37 @@ +package remoterepo + +import ( + "testing" + + "github.com/stretchr/testify/require" + "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/helper" + "gitlab.com/gitlab-org/gitaly/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/internal/testhelper/testserver" + "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" +) + +func TestRepository(t *testing.T) { + _, serverSocketPath, cleanup := testserver.RunInternalGitalyServer(t, config.Config.Storages, config.Config.Auth.Token) + defer cleanup() + + ctx, cancel := testhelper.Context() + defer cancel() + + ctx, err := helper.InjectGitalyServers(ctx, "default", serverSocketPath, config.Config.Auth.Token) + require.NoError(t, err) + + git.TestRepository(t, func(t testing.TB, pbRepo *gitalypb.Repository) git.Repository { + t.Helper() + + r, err := New( + helper.OutgoingToIncoming(ctx), + testhelper.TestRepository(), + client.NewPool(), + ) + require.NoError(t, err) + return r + }) +} diff --git a/internal/git/repository_suite.go b/internal/git/repository_suite.go new file mode 100644 index 000000000..616530fb6 --- /dev/null +++ b/internal/git/repository_suite.go @@ -0,0 +1,77 @@ +package git + +import ( + "testing" + + "github.com/stretchr/testify/require" + "gitlab.com/gitlab-org/gitaly/internal/testhelper" + "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" +) + +// TestRepository tests an implementation of Repository. +func TestRepository(t *testing.T, getRepository func(testing.TB, *gitalypb.Repository) Repository) { + for _, tc := range []struct { + desc string + test func(*testing.T, Repository) + }{ + { + desc: "ResolveRefish", + test: testRepositoryResolveRefish, + }, + } { + t.Run(tc.desc, func(t *testing.T) { + tc.test(t, getRepository(t, testhelper.TestRepository())) + }) + } +} + +func testRepositoryResolveRefish(t *testing.T, repo Repository) { + ctx, cancel := testhelper.Context() + defer cancel() + + for _, tc := range []struct { + desc string + refish string + expected string + }{ + { + desc: "unqualified master branch", + refish: "master", + expected: "1e292f8fedd741b75372e19097c76d327140c312", + }, + { + desc: "fully qualified master branch", + refish: "refs/heads/master", + expected: "1e292f8fedd741b75372e19097c76d327140c312", + }, + { + desc: "typed commit", + refish: "refs/heads/master^{commit}", + expected: "1e292f8fedd741b75372e19097c76d327140c312", + }, + { + desc: "extended SHA notation", + refish: "refs/heads/master^2", + expected: "c1c67abbaf91f624347bb3ae96eabe3a1b742478", + }, + { + desc: "nonexistent branch", + refish: "refs/heads/foobar", + }, + { + desc: "SHA notation gone wrong", + refish: "refs/heads/master^3", + }, + } { + t.Run(tc.desc, func(t *testing.T) { + oid, err := repo.ResolveRefish(ctx, tc.refish) + if tc.expected == "" { + require.Equal(t, err, ErrReferenceNotFound) + return + } + + require.NoError(t, err) + require.Equal(t, tc.expected, oid) + }) + } +} diff --git a/internal/git/repository_test.go b/internal/git/repository_test.go index b893b6cef..79af68e96 100644 --- a/internal/git/repository_test.go +++ b/internal/git/repository_test.go @@ -1,4 +1,4 @@ -package git_test +package git import ( "bytes" @@ -14,13 +14,9 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitaly/client" "gitlab.com/gitlab-org/gitaly/internal/command" - "gitlab.com/gitlab-org/gitaly/internal/git" - "gitlab.com/gitlab-org/gitaly/internal/gitaly/config" - "gitlab.com/gitlab-org/gitaly/internal/helper" "gitlab.com/gitlab-org/gitaly/internal/testhelper" - "gitlab.com/gitlab-org/gitaly/internal/testhelper/testserver" + "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb" ) const ( @@ -28,86 +24,18 @@ const ( NonexistentID = "ba4f184e126b751d1bffad5897f263108befc780" ) -func TestRepository_ResolveRefish(t *testing.T) { - ctx, cancel := testhelper.Context() - defer cancel() - - testcases := []struct { - desc string - refish string - expected string - }{ - { - desc: "unqualified master branch", - refish: "master", - expected: MasterID, - }, - { - desc: "fully qualified master branch", - refish: "refs/heads/master", - expected: MasterID, - }, - { - desc: "typed commit", - refish: "refs/heads/master^{commit}", - expected: MasterID, - }, - { - desc: "extended SHA notation", - refish: "refs/heads/master^2", - expected: "c1c67abbaf91f624347bb3ae96eabe3a1b742478", - }, - { - desc: "nonexistent branch", - refish: "refs/heads/foobar", - }, - { - desc: "SHA notation gone wrong", - refish: "refs/heads/master^3", - }, - } - - _, serverSocketPath, cleanup := testserver.RunInternalGitalyServer(t, config.Config.Storages, config.Config.Auth.Token) - defer cleanup() - - for _, repo := range []git.Repository{ - git.NewRepository(testhelper.TestRepository()), - func() git.Repository { - ctx, err := helper.InjectGitalyServers(ctx, "default", serverSocketPath, config.Config.Auth.Token) - require.NoError(t, err) - - r, err := git.NewRemoteRepository( - helper.OutgoingToIncoming(ctx), - testhelper.TestRepository(), - client.NewPool(), - ) - require.NoError(t, err) - return r - }(), - } { - t.Run(fmt.Sprintf("%T", repo), func(t *testing.T) { - for _, tc := range testcases { - t.Run(tc.desc, func(t *testing.T) { - oid, err := repo.ResolveRefish(ctx, tc.refish) - - if tc.expected == "" { - require.Equal(t, err, git.ErrReferenceNotFound) - return - } - - require.NoError(t, err) - require.Equal(t, tc.expected, oid) - }) - } - }) - } +func TestLocalRepository(t *testing.T) { + TestRepository(t, func(t testing.TB, pbRepo *gitalypb.Repository) Repository { + t.Helper() + return NewRepository(pbRepo) + }) } func TestLocalRepository_ContainsRef(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - repo := git.NewRepository(testhelper.TestRepository()) + repo := NewRepository(testhelper.TestRepository()) testcases := []struct { desc string @@ -144,32 +72,32 @@ func TestLocalRepository_GetReference(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - repo := git.NewRepository(testhelper.TestRepository()) + repo := NewRepository(testhelper.TestRepository()) testcases := []struct { desc string ref string - expected git.Reference + expected Reference }{ { desc: "fully qualified master branch", ref: "refs/heads/master", - expected: git.NewReference("refs/heads/master", MasterID), + expected: NewReference("refs/heads/master", MasterID), }, { desc: "unqualified master branch fails", ref: "master", - expected: git.Reference{}, + expected: Reference{}, }, { desc: "nonexistent branch", ref: "refs/heads/nonexistent", - expected: git.Reference{}, + expected: Reference{}, }, { desc: "nonexistent branch", ref: "nonexistent", - expected: git.Reference{}, + expected: Reference{}, }, } @@ -177,7 +105,7 @@ func TestLocalRepository_GetReference(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { ref, err := repo.GetReference(ctx, tc.ref) if tc.expected.Name == "" { - require.True(t, errors.Is(err, git.ErrReferenceNotFound)) + require.True(t, errors.Is(err, ErrReferenceNotFound)) } else { require.NoError(t, err) require.Equal(t, tc.expected, ref) @@ -190,32 +118,32 @@ func TestLocalRepository_GetBranch(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - repo := git.NewRepository(testhelper.TestRepository()) + repo := NewRepository(testhelper.TestRepository()) testcases := []struct { desc string ref string - expected git.Reference + expected Reference }{ { desc: "fully qualified master branch", ref: "refs/heads/master", - expected: git.NewReference("refs/heads/master", MasterID), + expected: NewReference("refs/heads/master", MasterID), }, { desc: "half-qualified master branch", ref: "heads/master", - expected: git.NewReference("refs/heads/master", MasterID), + expected: NewReference("refs/heads/master", MasterID), }, { desc: "fully qualified master branch", ref: "master", - expected: git.NewReference("refs/heads/master", MasterID), + expected: NewReference("refs/heads/master", MasterID), }, { desc: "nonexistent branch", ref: "nonexistent", - expected: git.Reference{}, + expected: Reference{}, }, } @@ -223,7 +151,7 @@ func TestLocalRepository_GetBranch(t *testing.T) { t.Run(tc.desc, func(t *testing.T) { ref, err := repo.GetBranch(ctx, tc.ref) if tc.expected.Name == "" { - require.True(t, errors.Is(err, git.ErrReferenceNotFound)) + require.True(t, errors.Is(err, ErrReferenceNotFound)) } else { require.NoError(t, err) require.Equal(t, tc.expected, ref) @@ -236,40 +164,40 @@ func TestLocalRepository_GetReferences(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - repo := git.NewRepository(testhelper.TestRepository()) + repo := NewRepository(testhelper.TestRepository()) testcases := []struct { desc string pattern string - match func(t *testing.T, refs []git.Reference) + match func(t *testing.T, refs []Reference) }{ { desc: "master branch", pattern: "refs/heads/master", - match: func(t *testing.T, refs []git.Reference) { - require.Equal(t, []git.Reference{ - git.NewReference("refs/heads/master", MasterID), + match: func(t *testing.T, refs []Reference) { + require.Equal(t, []Reference{ + NewReference("refs/heads/master", MasterID), }, refs) }, }, { desc: "all references", pattern: "", - match: func(t *testing.T, refs []git.Reference) { + match: func(t *testing.T, refs []Reference) { require.Len(t, refs, 94) }, }, { desc: "branches", pattern: "refs/heads/", - match: func(t *testing.T, refs []git.Reference) { + match: func(t *testing.T, refs []Reference) { require.Len(t, refs, 91) }, }, { desc: "branches", pattern: "refs/heads/nonexistent", - match: func(t *testing.T, refs []git.Reference) { + match: func(t *testing.T, refs []Reference) { require.Empty(t, refs) }, }, @@ -302,7 +230,7 @@ crlf binary lf text `), os.ModePerm)) - repo := git.NewRepository(pbRepo) + repo := NewRepository(pbRepo) for _, tc := range []struct { desc string @@ -363,7 +291,7 @@ func TestLocalRepository_ReadObject(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - repo := git.NewRepository(testhelper.TestRepository()) + repo := NewRepository(testhelper.TestRepository()) for _, tc := range []struct { desc string @@ -373,8 +301,8 @@ func TestLocalRepository_ReadObject(t *testing.T) { }{ { desc: "invalid object", - oid: git.NullSHA, - error: git.InvalidObjectError(git.NullSHA), + oid: NullSHA, + error: InvalidObjectError(NullSHA), }, { desc: "valid object", @@ -395,7 +323,7 @@ func TestLocalRepository_GetBranches(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - repo := git.NewRepository(testhelper.TestRepository()) + repo := NewRepository(testhelper.TestRepository()) refs, err := repo.GetBranches(ctx) require.NoError(t, err) @@ -409,7 +337,7 @@ func TestLocalRepository_UpdateRef(t *testing.T) { testRepo, _, cleanup := testhelper.NewTestRepo(t) defer cleanup() - otherRef, err := git.NewRepository(testRepo).GetReference(ctx, "refs/heads/gitaly-test-ref") + otherRef, err := NewRepository(testRepo).GetReference(ctx, "refs/heads/gitaly-test-ref") require.NoError(t, err) testcases := []struct { @@ -417,14 +345,14 @@ func TestLocalRepository_UpdateRef(t *testing.T) { ref string newrev string oldrev string - verify func(t *testing.T, repo *git.LocalRepository, err error) + verify func(t *testing.T, repo *LocalRepository, err error) }{ { desc: "successfully update master", ref: "refs/heads/master", newrev: otherRef.Target, oldrev: MasterID, - verify: func(t *testing.T, repo *git.LocalRepository, err error) { + verify: func(t *testing.T, repo *LocalRepository, err error) { require.NoError(t, err) ref, err := repo.GetReference(ctx, "refs/heads/master") require.NoError(t, err) @@ -436,7 +364,7 @@ func TestLocalRepository_UpdateRef(t *testing.T) { ref: "refs/heads/master", newrev: otherRef.Target, oldrev: NonexistentID, - verify: func(t *testing.T, repo *git.LocalRepository, err error) { + verify: func(t *testing.T, repo *LocalRepository, err error) { require.Error(t, err) ref, err := repo.GetReference(ctx, "refs/heads/master") require.NoError(t, err) @@ -448,7 +376,7 @@ func TestLocalRepository_UpdateRef(t *testing.T) { ref: "refs/heads/master", newrev: NonexistentID, oldrev: MasterID, - verify: func(t *testing.T, repo *git.LocalRepository, err error) { + verify: func(t *testing.T, repo *LocalRepository, err error) { require.Error(t, err) ref, err := repo.GetReference(ctx, "refs/heads/master") require.NoError(t, err) @@ -460,7 +388,7 @@ func TestLocalRepository_UpdateRef(t *testing.T) { ref: "refs/heads/master", newrev: otherRef.Target, oldrev: "", - verify: func(t *testing.T, repo *git.LocalRepository, err error) { + verify: func(t *testing.T, repo *LocalRepository, err error) { require.NoError(t, err) ref, err := repo.GetReference(ctx, "refs/heads/master") require.NoError(t, err) @@ -472,7 +400,7 @@ func TestLocalRepository_UpdateRef(t *testing.T) { ref: "master", newrev: otherRef.Target, oldrev: MasterID, - verify: func(t *testing.T, repo *git.LocalRepository, err error) { + verify: func(t *testing.T, repo *LocalRepository, err error) { require.Error(t, err) ref, err := repo.GetReference(ctx, "refs/heads/master") require.NoError(t, err) @@ -484,7 +412,7 @@ func TestLocalRepository_UpdateRef(t *testing.T) { ref: "refs/heads/master", newrev: strings.Repeat("0", 40), oldrev: MasterID, - verify: func(t *testing.T, repo *git.LocalRepository, err error) { + verify: func(t *testing.T, repo *LocalRepository, err error) { require.NoError(t, err) _, err = repo.GetReference(ctx, "refs/heads/master") require.Error(t, err) @@ -495,7 +423,7 @@ func TestLocalRepository_UpdateRef(t *testing.T) { ref: "refs/heads/new", newrev: MasterID, oldrev: strings.Repeat("0", 40), - verify: func(t *testing.T, repo *git.LocalRepository, err error) { + verify: func(t *testing.T, repo *LocalRepository, err error) { require.NoError(t, err) ref, err := repo.GetReference(ctx, "refs/heads/new") require.NoError(t, err) @@ -510,7 +438,7 @@ func TestLocalRepository_UpdateRef(t *testing.T) { testRepo, _, cleanup := testhelper.NewTestRepo(t) defer cleanup() - repo := git.NewRepository(testRepo) + repo := NewRepository(testRepo) err := repo.UpdateRef(ctx, tc.ref, tc.newrev, tc.oldrev) tc.verify(t, repo, err) @@ -522,7 +450,7 @@ func TestLocalRepository_FetchRemote(t *testing.T) { ctx, cancel := testhelper.Context() defer cancel() - initBareWithRemote := func(t *testing.T, remote string) (*git.LocalRepository, string, testhelper.Cleanup) { + initBareWithRemote := func(t *testing.T, remote string) (*LocalRepository, string, testhelper.Cleanup) { t.Helper() testRepo, testRepoPath, cleanup := testhelper.InitBareRepo(t) @@ -535,14 +463,14 @@ func TestLocalRepository_FetchRemote(t *testing.T) { t.FailNow() } - return git.NewRepository(testRepo), testRepoPath, cleanup + return NewRepository(testRepo), testRepoPath, cleanup } t.Run("invalid name", func(t *testing.T) { - repo := git.NewRepository(nil) + repo := NewRepository(nil) - err := repo.FetchRemote(ctx, " ", git.FetchOpts{}) - require.True(t, errors.Is(err, git.ErrInvalidArg)) + err := repo.FetchRemote(ctx, " ", FetchOpts{}) + require.True(t, errors.Is(err, ErrInvalidArg)) require.Contains(t, err.Error(), `"remoteName" is blank or empty`) }) @@ -550,9 +478,9 @@ func TestLocalRepository_FetchRemote(t *testing.T) { testRepo, _, cleanup := testhelper.InitBareRepo(t) defer cleanup() - repo := git.NewRepository(testRepo) + repo := NewRepository(testRepo) var stderr bytes.Buffer - err := repo.FetchRemote(ctx, "stub", git.FetchOpts{Stderr: &stderr}) + err := repo.FetchRemote(ctx, "stub", FetchOpts{Stderr: &stderr}) require.Error(t, err) require.Contains(t, stderr.String(), "'stub' does not appear to be a git repository") }) @@ -562,7 +490,7 @@ func TestLocalRepository_FetchRemote(t *testing.T) { defer cleanup() var stderr bytes.Buffer - require.NoError(t, repo.FetchRemote(ctx, "origin", git.FetchOpts{Stderr: &stderr})) + require.NoError(t, repo.FetchRemote(ctx, "origin", FetchOpts{Stderr: &stderr})) require.Empty(t, stderr.String(), "it should not produce output as it is called with --quite flag by default") @@ -585,11 +513,11 @@ func TestLocalRepository_FetchRemote(t *testing.T) { testRepo, testRepoPath, testCleanup := testhelper.NewTestRepo(t) defer testCleanup() - repo := git.NewRepository(testRepo) + repo := NewRepository(testRepo) testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "remote", "add", "source", sourceRepoPath) var stderr bytes.Buffer - require.NoError(t, repo.FetchRemote(ctx, "source", git.FetchOpts{Stderr: &stderr, Env: []string{"GIT_TRACE=1"}})) + require.NoError(t, repo.FetchRemote(ctx, "source", FetchOpts{Stderr: &stderr, Env: []string{"GIT_TRACE=1"}})) require.Contains(t, stderr.String(), "trace: built-in: git fetch --quiet source --end-of-options") }) @@ -600,10 +528,10 @@ func TestLocalRepository_FetchRemote(t *testing.T) { testRepo, testRepoPath, testCleanup := testhelper.NewTestRepo(t) defer testCleanup() - repo := git.NewRepository(testRepo) + repo := NewRepository(testRepo) testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "remote", "add", "source", sourceRepoPath) - require.NoError(t, repo.FetchRemote(ctx, "source", git.FetchOpts{})) + require.NoError(t, repo.FetchRemote(ctx, "source", FetchOpts{})) testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", "--track", "testing-fetch-prune", "refs/remotes/source/markdown") testhelper.MustRunCommand(t, nil, "git", "-C", sourceRepoPath, "branch", "-D", "markdown") @@ -611,8 +539,8 @@ func TestLocalRepository_FetchRemote(t *testing.T) { require.NoError(t, repo.FetchRemote( ctx, "source", - git.FetchOpts{ - Global: []git.Option{git.ValueFlag{Name: "-c", Value: "fetch.prune=true"}}, + FetchOpts{ + Global: []Option{ValueFlag{Name: "-c", Value: "fetch.prune=true"}}, }), ) @@ -628,15 +556,15 @@ func TestLocalRepository_FetchRemote(t *testing.T) { testRepo, testRepoPath, testCleanup := testhelper.NewTestRepo(t) defer testCleanup() - repo := git.NewRepository(testRepo) + repo := NewRepository(testRepo) testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "remote", "add", "source", sourceRepoPath) - require.NoError(t, repo.FetchRemote(ctx, "source", git.FetchOpts{})) + require.NoError(t, repo.FetchRemote(ctx, "source", FetchOpts{})) testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", "--track", "testing-fetch-prune", "refs/remotes/source/markdown") testhelper.MustRunCommand(t, nil, "git", "-C", sourceRepoPath, "branch", "-D", "markdown") - require.NoError(t, repo.FetchRemote(ctx, "source", git.FetchOpts{Prune: true})) + require.NoError(t, repo.FetchRemote(ctx, "source", FetchOpts{Prune: true})) contains, err := repo.ContainsRef(ctx, "refs/remotes/source/markdown") require.NoError(t, err) @@ -650,7 +578,7 @@ func TestLocalRepository_FetchRemote(t *testing.T) { tagsBefore := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "tag", "--list") require.Empty(t, tagsBefore) - require.NoError(t, repo.FetchRemote(ctx, "origin", git.FetchOpts{Tags: git.FetchOptsTagsNone, Force: true})) + require.NoError(t, repo.FetchRemote(ctx, "origin", FetchOpts{Tags: FetchOptsTagsNone, Force: true})) tagsAfter := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "tag", "--list") require.Empty(t, tagsAfter) diff --git a/internal/gitaly/service/conflicts/resolve_conflicts.go b/internal/gitaly/service/conflicts/resolve_conflicts.go index e7f31cea7..390ae99db 100644 --- a/internal/gitaly/service/conflicts/resolve_conflicts.go +++ b/internal/gitaly/service/conflicts/resolve_conflicts.go @@ -13,6 +13,7 @@ import ( "github.com/grpc-ecosystem/go-grpc-middleware/logging/logrus/ctxlogrus" "gitlab.com/gitlab-org/gitaly/internal/git" "gitlab.com/gitlab-org/gitaly/internal/git/conflict" + "gitlab.com/gitlab-org/gitaly/internal/git/remoterepo" "gitlab.com/gitlab-org/gitaly/internal/git2go" "gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/gitalyssh" @@ -258,7 +259,7 @@ func (s *server) repoWithBranchCommit(ctx context.Context, srcRepo, targetRepo * return err } - target, err := git.NewRemoteRepository(ctx, targetRepo, s.pool) + target, err := remoterepo.New(ctx, targetRepo, s.pool) if err != nil { return err } diff --git a/internal/gitaly/service/operations/commit_files.go b/internal/gitaly/service/operations/commit_files.go index a6fd76ee1..59ce44677 100644 --- a/internal/gitaly/service/operations/commit_files.go +++ b/internal/gitaly/service/operations/commit_files.go @@ -13,6 +13,7 @@ import ( "github.com/sirupsen/logrus" "gitlab.com/gitlab-org/gitaly/internal/command" "gitlab.com/gitlab-org/gitaly/internal/git" + "gitlab.com/gitlab-org/gitaly/internal/git/remoterepo" "gitlab.com/gitlab-org/gitaly/internal/git2go" "gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver" "gitlab.com/gitlab-org/gitaly/internal/gitalyssh" @@ -353,7 +354,7 @@ func (s *server) resolveParentCommit(ctx context.Context, local git.Repository, repo := local if remote != nil { var err error - repo, err = git.NewRemoteRepository(ctx, remote, s.conns) + repo, err = remoterepo.New(ctx, remote, s.conns) if err != nil { return "", fmt.Errorf("remote repository: %w", err) } |