Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2021-02-08 10:15:38 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2021-02-11 15:32:47 +0300
commit64291a542f6125d6a23aad29ef4086f17a14e97c (patch)
treec314aa694feb91cc73e2c1d61446e45e63719109
parent043bf1303939a697d4488725400a61da4e30b211 (diff)
tests: Convert code to use `localrepo.ReadCommit()`
This commit converts all users of `log.GetCommit()` and `log.GetCommitWithTrailers()` to instead use the new `localrepo.ReadCommit()` function.
-rw-r--r--cmd/gitaly-git2go/submodule_test.go5
-rw-r--r--internal/git/updateref/updateref_test.go73
-rw-r--r--internal/gitaly/service/cleanup/apply_bfg_object_map_stream_test.go6
-rw-r--r--internal/gitaly/service/commit/find_commit_test.go11
-rw-r--r--internal/gitaly/service/conflicts/resolve_conflicts_test.go14
-rw-r--r--internal/gitaly/service/objectpool/link_test.go15
-rw-r--r--internal/gitaly/service/operations/apply_patch_test.go20
-rw-r--r--internal/gitaly/service/operations/branches_test.go26
-rw-r--r--internal/gitaly/service/operations/cherry_pick_test.go90
-rw-r--r--internal/gitaly/service/operations/commit_files_test.go57
-rw-r--r--internal/gitaly/service/operations/merge_test.go78
-rw-r--r--internal/gitaly/service/operations/rebase_test.go94
-rw-r--r--internal/gitaly/service/operations/revert_test.go105
-rw-r--r--internal/gitaly/service/operations/squash_test.go70
-rw-r--r--internal/gitaly/service/operations/submodules_test.go10
-rw-r--r--internal/gitaly/service/operations/tags_test.go62
-rw-r--r--internal/gitaly/service/operations/update_branches_test.go33
-rw-r--r--internal/gitaly/service/ref/branches_test.go3
-rw-r--r--internal/gitaly/service/ref/refs_test.go68
-rw-r--r--internal/gitaly/service/ref/remote_branches_test.go16
-rw-r--r--internal/gitaly/service/repository/create_from_bundle_test.go12
-rw-r--r--internal/gitaly/service/repository/fetch_test.go18
-rw-r--r--internal/gitaly/service/wiki/delete_page_test.go13
-rw-r--r--internal/gitaly/service/wiki/testhelper_test.go12
-rw-r--r--internal/gitaly/service/wiki/update_page_test.go13
-rw-r--r--internal/gitaly/service/wiki/write_page_test.go11
26 files changed, 492 insertions, 443 deletions
diff --git a/cmd/gitaly-git2go/submodule_test.go b/cmd/gitaly-git2go/submodule_test.go
index 588f92a55..26357598f 100644
--- a/cmd/gitaly-git2go/submodule_test.go
+++ b/cmd/gitaly-git2go/submodule_test.go
@@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git"
- "gitlab.com/gitlab-org/gitaly/internal/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/git/lstree"
"gitlab.com/gitlab-org/gitaly/internal/git2go"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
@@ -88,6 +88,7 @@ func TestSubmodule(t *testing.T) {
t.Run(tc.desc, func(t *testing.T) {
testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(testRepo, config.Config)
tc.command.Repository = testRepoPath
@@ -102,7 +103,7 @@ func TestSubmodule(t *testing.T) {
}
require.NoError(t, err)
- commit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(response.CommitID))
+ commit, err := repo.ReadCommit(ctx, git.Revision(response.CommitID))
require.NoError(t, err)
require.Equal(t, commit.Author.Email, testhelper.TestUser.Email)
require.Equal(t, commit.Committer.Email, testhelper.TestUser.Email)
diff --git a/internal/git/updateref/updateref_test.go b/internal/git/updateref/updateref_test.go
index 24f3f2c52..cec69a005 100644
--- a/internal/git/updateref/updateref_test.go
+++ b/internal/git/updateref/updateref_test.go
@@ -10,10 +10,8 @@ import (
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/hooks"
"gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
- "gitlab.com/gitlab-org/gitaly/internal/git/log"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
- "gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
)
func TestMain(m *testing.M) {
@@ -28,26 +26,27 @@ func testMain(m *testing.M) int {
return m.Run()
}
-func setup(t *testing.T) (context.Context, *gitalypb.Repository, string, func()) {
+func setup(t *testing.T) (context.Context, *localrepo.Repo, string, func()) {
ctx, cancel := testhelper.Context()
- testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanup := testhelper.NewTestRepo(t)
teardown := func() {
cancel()
cleanup()
}
- return ctx, testRepo, testRepoPath, teardown
+ repo := localrepo.New(repoProto, config.Config)
+
+ return ctx, repo, repoPath, teardown
}
func TestCreate(t *testing.T) {
- ctx, testRepo, _, teardown := setup(t)
+ ctx, repo, _, teardown := setup(t)
defer teardown()
- gitCmdFactory := git.NewExecCommandFactory(config.Config)
- headCommit, err := log.GetCommit(ctx, gitCmdFactory, testRepo, "HEAD")
+ headCommit, err := repo.ReadCommit(ctx, "HEAD")
require.NoError(t, err)
- updater, err := New(ctx, config.Config, git.NewExecCommandFactory(config.Config), testRepo)
+ updater, err := New(ctx, config.Config, git.NewExecCommandFactory(config.Config), repo)
require.NoError(t, err)
ref := git.ReferenceName("refs/heads/_create")
@@ -57,27 +56,26 @@ func TestCreate(t *testing.T) {
require.NoError(t, updater.Wait())
// check the ref was created
- commit, logErr := log.GetCommit(ctx, gitCmdFactory, testRepo, ref.Revision())
+ commit, logErr := repo.ReadCommit(ctx, ref.Revision())
require.NoError(t, logErr)
require.Equal(t, commit.Id, sha, "reference was created with the wrong SHA")
}
func TestUpdate(t *testing.T) {
- ctx, testRepo, _, teardown := setup(t)
+ ctx, repo, _, teardown := setup(t)
defer teardown()
- gitCmdFactory := git.NewExecCommandFactory(config.Config)
- headCommit, err := log.GetCommit(ctx, gitCmdFactory, testRepo, "HEAD")
+ headCommit, err := repo.ReadCommit(ctx, "HEAD")
require.NoError(t, err)
- updater, err := New(ctx, config.Config, git.NewExecCommandFactory(config.Config), testRepo)
+ updater, err := New(ctx, config.Config, git.NewExecCommandFactory(config.Config), repo)
require.NoError(t, err)
ref := git.ReferenceName("refs/heads/feature")
sha := headCommit.Id
// Sanity check: ensure the ref exists before we start
- commit, logErr := log.GetCommit(ctx, gitCmdFactory, testRepo, ref.Revision())
+ commit, logErr := repo.ReadCommit(ctx, ref.Revision())
require.NoError(t, logErr)
require.NotEqual(t, commit.Id, sha, "%s points to HEAD: %s in the test repository", ref.String(), sha)
@@ -85,26 +83,26 @@ func TestUpdate(t *testing.T) {
require.NoError(t, updater.Wait())
// check the ref was updated
- commit, logErr = log.GetCommit(ctx, gitCmdFactory, testRepo, ref.Revision())
+ commit, logErr = repo.ReadCommit(ctx, ref.Revision())
require.NoError(t, logErr)
require.Equal(t, commit.Id, sha, "reference was not updated")
// since ref has been updated to HEAD, we know that it does not point to HEAD^. So, HEAD^ is an invalid "old value" for updating ref
- parentCommit, err := log.GetCommit(ctx, gitCmdFactory, testRepo, "HEAD^")
+ parentCommit, err := repo.ReadCommit(ctx, "HEAD^")
require.NoError(t, err)
require.Error(t, updater.Update(ref, parentCommit.Id, parentCommit.Id))
// check the ref was not updated
- commit, logErr = log.GetCommit(ctx, gitCmdFactory, testRepo, ref.Revision())
+ commit, logErr = repo.ReadCommit(ctx, ref.Revision())
require.NoError(t, logErr)
require.NotEqual(t, commit.Id, parentCommit.Id, "reference was updated when it shouldn't have been")
}
func TestDelete(t *testing.T) {
- ctx, testRepo, _, teardown := setup(t)
+ ctx, repo, _, teardown := setup(t)
defer teardown()
- updater, err := New(ctx, config.Config, git.NewExecCommandFactory(config.Config), testRepo)
+ updater, err := New(ctx, config.Config, git.NewExecCommandFactory(config.Config), repo)
require.NoError(t, err)
ref := git.ReferenceName("refs/heads/feature")
@@ -113,18 +111,18 @@ func TestDelete(t *testing.T) {
require.NoError(t, updater.Wait())
// check the ref was removed
- _, err = log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, ref.Revision())
- require.True(t, log.IsNotFound(err), "expected 'not found' error got %v", err)
+ _, err = repo.ReadCommit(ctx, ref.Revision())
+ require.Equal(t, localrepo.ErrObjectNotFound, err, "expected 'not found' error got %v", err)
}
func TestBulkOperation(t *testing.T) {
- ctx, testRepo, _, teardown := setup(t)
+ ctx, repo, _, teardown := setup(t)
defer teardown()
- headCommit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, "HEAD")
+ headCommit, err := repo.ReadCommit(ctx, "HEAD")
require.NoError(t, err)
- updater, err := New(ctx, config.Config, git.NewExecCommandFactory(config.Config), testRepo)
+ updater, err := New(ctx, config.Config, git.NewExecCommandFactory(config.Config), repo)
require.NoError(t, err)
for i := 0; i < 1000; i++ {
@@ -134,21 +132,20 @@ func TestBulkOperation(t *testing.T) {
require.NoError(t, updater.Wait())
- refs, err := localrepo.New(testRepo, config.Config).GetReferences(ctx, "refs/")
+ refs, err := repo.GetReferences(ctx, "refs/")
require.NoError(t, err)
require.Greater(t, len(refs), 1000, "At least 1000 refs should be present")
}
func TestContextCancelAbortsRefChanges(t *testing.T) {
- ctx, testRepo, _, teardown := setup(t)
+ ctx, repo, _, teardown := setup(t)
defer teardown()
- gitCmdFactory := git.NewExecCommandFactory(config.Config)
- headCommit, err := log.GetCommit(ctx, gitCmdFactory, testRepo, "HEAD")
+ headCommit, err := repo.ReadCommit(ctx, "HEAD")
require.NoError(t, err)
childCtx, childCancel := context.WithCancel(ctx)
- updater, err := New(childCtx, config.Config, git.NewExecCommandFactory(config.Config), testRepo)
+ updater, err := New(childCtx, config.Config, git.NewExecCommandFactory(config.Config), repo)
require.NoError(t, err)
ref := git.ReferenceName("refs/heads/_shouldnotexist")
@@ -160,24 +157,24 @@ func TestContextCancelAbortsRefChanges(t *testing.T) {
require.Error(t, updater.Wait())
// check the ref doesn't exist
- _, err = log.GetCommit(ctx, gitCmdFactory, testRepo, ref.Revision())
- require.True(t, log.IsNotFound(err), "expected 'not found' error got %v", err)
+ _, err = repo.ReadCommit(ctx, ref.Revision())
+ require.Equal(t, localrepo.ErrObjectNotFound, err, "expected 'not found' error got %v", err)
}
func TestUpdater_closingStdinAbortsChanges(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- testRepo, _, cleanup := testhelper.NewTestRepo(t)
+ repoProto, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
- gitCmdFactory := git.NewExecCommandFactory(config.Config)
- headCommit, err := log.GetCommit(ctx, gitCmdFactory, testRepo, "HEAD")
+ headCommit, err := repo.ReadCommit(ctx, "HEAD")
require.NoError(t, err)
ref := git.ReferenceName("refs/heads/shouldnotexist")
- updater, err := New(ctx, config.Config, git.NewExecCommandFactory(config.Config), testRepo)
+ updater, err := New(ctx, config.Config, git.NewExecCommandFactory(config.Config), repo)
require.NoError(t, err)
require.NoError(t, updater.Create(ref, headCommit.Id))
@@ -190,6 +187,6 @@ func TestUpdater_closingStdinAbortsChanges(t *testing.T) {
// ... but as we now use explicit transactional behaviour, this is no
// longer the case.
- _, err = log.GetCommit(ctx, gitCmdFactory, testRepo, ref.Revision())
- require.True(t, log.IsNotFound(err), "expected 'not found' error got %v", err)
+ _, err = repo.ReadCommit(ctx, ref.Revision())
+ require.Equal(t, localrepo.ErrObjectNotFound, err, "expected 'not found' error got %v", err)
}
diff --git a/internal/gitaly/service/cleanup/apply_bfg_object_map_stream_test.go b/internal/gitaly/service/cleanup/apply_bfg_object_map_stream_test.go
index b7f302b75..7528834ca 100644
--- a/internal/gitaly/service/cleanup/apply_bfg_object_map_stream_test.go
+++ b/internal/gitaly/service/cleanup/apply_bfg_object_map_stream_test.go
@@ -11,7 +11,6 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
- "gitlab.com/gitlab-org/gitaly/internal/git/log"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -27,11 +26,12 @@ func TestApplyBfgObjectMapStreamSuccess(t *testing.T) {
testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(testRepo, config.Config)
ctx, cancel := testhelper.Context()
defer cancel()
- headCommit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, "HEAD")
+ headCommit, err := repo.ReadCommit(ctx, "HEAD")
require.NoError(t, err)
// A known blob: the CHANGELOG in the test repository
@@ -70,7 +70,7 @@ func TestApplyBfgObjectMapStreamSuccess(t *testing.T) {
require.NoError(t, err)
// Ensure that the internal refs are gone, but the others still exist
- refs, err := localrepo.New(testRepo, config.Config).GetReferences(ctx, "refs/")
+ refs, err := repo.GetReferences(ctx, "refs/")
require.NoError(t, err)
refNames := make([]string, len(refs))
diff --git a/internal/gitaly/service/commit/find_commit_test.go b/internal/gitaly/service/commit/find_commit_test.go
index 7b3541245..fa8f12c12 100644
--- a/internal/gitaly/service/commit/find_commit_test.go
+++ b/internal/gitaly/service/commit/find_commit_test.go
@@ -10,7 +10,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/catfile"
- "gitlab.com/gitlab-org/gitaly/internal/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/helper"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
@@ -30,18 +30,19 @@ func TestSuccessfulFindCommitRequest(t *testing.T) {
client, conn := newCommitServiceClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
ctx, cancel := testhelper.Context()
defer cancel()
bigMessage := "An empty commit with REALLY BIG message\n\n" + strings.Repeat("MOAR!\n", 20*1024)
- bigCommitID := testhelper.CreateCommit(t, testRepoPath, "local-big-commits", &testhelper.CreateCommitOpts{
+ bigCommitID := testhelper.CreateCommit(t, repoPath, "local-big-commits", &testhelper.CreateCommitOpts{
Message: bigMessage,
ParentID: "60ecb67744cb56576c30214ff52294f8ce2def98",
})
- bigCommit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(bigCommitID))
+ bigCommit, err := repo.ReadCommit(ctx, git.Revision(bigCommitID))
require.NoError(t, err)
testCases := []struct {
@@ -248,7 +249,7 @@ func TestSuccessfulFindCommitRequest(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.description, func(t *testing.T) {
request := &gitalypb.FindCommitRequest{
- Repository: testRepo,
+ Repository: repoProto,
Revision: []byte(testCase.revision),
Trailers: testCase.trailers,
}
diff --git a/internal/gitaly/service/conflicts/resolve_conflicts_test.go b/internal/gitaly/service/conflicts/resolve_conflicts_test.go
index 84cdf0183..cdb9014a5 100644
--- a/internal/gitaly/service/conflicts/resolve_conflicts_test.go
+++ b/internal/gitaly/service/conflicts/resolve_conflicts_test.go
@@ -8,7 +8,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/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/service/conflicts"
"gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag"
@@ -64,6 +64,7 @@ func testSuccessfulResolveConflictsRequest(t *testing.T, ctx context.Context) {
testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(testRepo, config.Config)
ctxOuter, cancel := testhelper.Context()
defer cancel()
@@ -111,7 +112,7 @@ func testSuccessfulResolveConflictsRequest(t *testing.T, ctx context.Context) {
require.NoError(t, err)
require.Empty(t, r.GetResolutionError())
- headCommit, err := log.GetCommit(ctxOuter, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(sourceBranch))
+ headCommit, err := repo.ReadCommit(ctxOuter, git.Revision(sourceBranch))
require.NoError(t, err)
require.Contains(t, headCommit.ParentIds, "1450cd639e0bc6721eb02800169e464f212cde06")
require.Contains(t, headCommit.ParentIds, "824be604a34828eb682305f0d963056cfac87b2d")
@@ -135,8 +136,9 @@ func testResolveConflictsStableID(t *testing.T, ctx context.Context) {
client, conn := conflicts.NewConflictsClient(t, serverSocketPath)
defer conn.Close()
- repo, _, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
ctx = testhelper.MergeOutgoingMetadata(ctx, md)
@@ -147,8 +149,8 @@ func testResolveConflictsStableID(t *testing.T, ctx context.Context) {
require.NoError(t, stream.Send(&gitalypb.ResolveConflictsRequest{
ResolveConflictsRequestPayload: &gitalypb.ResolveConflictsRequest_Header{
Header: &gitalypb.ResolveConflictsRequestHeader{
- Repository: repo,
- TargetRepository: repo,
+ Repository: repoProto,
+ TargetRepository: repoProto,
CommitMessage: []byte(conflictResolutionCommitMessage),
OurCommitOid: "1450cd639e0bc6721eb02800169e464f212cde06",
TheirCommitOid: "824be604a34828eb682305f0d963056cfac87b2d",
@@ -172,7 +174,7 @@ func testResolveConflictsStableID(t *testing.T, ctx context.Context) {
require.NoError(t, err)
require.Empty(t, response.GetResolutionError())
- resolvedCommit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), repo, git.Revision("conflict-resolvable"))
+ resolvedCommit, err := repo.ReadCommit(ctx, git.Revision("conflict-resolvable"))
require.NoError(t, err)
require.Equal(t, &gitalypb.GitCommit{
Id: "a5ad028fd739d7a054b07c293e77c5b7aecc2435",
diff --git a/internal/gitaly/service/objectpool/link_test.go b/internal/gitaly/service/objectpool/link_test.go
index 320d811e2..86371abc4 100644
--- a/internal/gitaly/service/objectpool/link_test.go
+++ b/internal/gitaly/service/objectpool/link_test.go
@@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git"
- "gitlab.com/gitlab-org/gitaly/internal/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/git/objectpool"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/storage"
@@ -28,14 +28,15 @@ func TestLink(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
- pool, err := objectpool.NewObjectPool(config.Config, locator, git.NewExecCommandFactory(config.Config), testRepo.GetStorageName(), testhelper.NewTestObjectPoolName(t))
+ pool, err := objectpool.NewObjectPool(config.Config, locator, git.NewExecCommandFactory(config.Config), repoProto.GetStorageName(), testhelper.NewTestObjectPoolName(t))
require.NoError(t, err)
require.NoError(t, pool.Remove(ctx), "make sure pool does not exist at start of test")
- require.NoError(t, pool.Create(ctx, testRepo), "create pool")
+ require.NoError(t, pool.Create(ctx, repoProto), "create pool")
// Mock object in the pool, which should be available to the pool members
// after linking
@@ -57,7 +58,7 @@ func TestLink(t *testing.T) {
{
desc: "Pool does not exist",
req: &gitalypb.LinkRepositoryToObjectPoolRequest{
- Repository: testRepo,
+ Repository: repoProto,
ObjectPool: nil,
},
code: codes.InvalidArgument,
@@ -65,7 +66,7 @@ func TestLink(t *testing.T) {
{
desc: "Successful request",
req: &gitalypb.LinkRepositoryToObjectPoolRequest{
- Repository: testRepo,
+ Repository: repoProto,
ObjectPool: pool.ToProto(),
},
code: codes.OK,
@@ -83,7 +84,7 @@ func TestLink(t *testing.T) {
require.NoError(t, err, "error from LinkRepositoryToObjectPool")
- commit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(poolCommitID))
+ commit, err := repo.ReadCommit(ctx, git.Revision(poolCommitID))
require.NoError(t, err)
require.NotNil(t, commit)
require.Equal(t, poolCommitID, commit.Id)
diff --git a/internal/gitaly/service/operations/apply_patch_test.go b/internal/gitaly/service/operations/apply_patch_test.go
index a15f744f1..05c2d7335 100644
--- a/internal/gitaly/service/operations/apply_patch_test.go
+++ b/internal/gitaly/service/operations/apply_patch_test.go
@@ -13,7 +13,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/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -35,8 +35,9 @@ func testSuccessfulUserApplyPatch(t *testing.T, ctx context.Context) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
testPatchReadme := "testdata/0001-A-commit-from-a-patch.patch"
testPatchFeature := "testdata/0001-This-does-not-apply-to-the-feature-branch.patch"
@@ -76,7 +77,7 @@ func testSuccessfulUserApplyPatch(t *testing.T, ctx context.Context) {
stream, err := client.UserApplyPatch(ctx)
require.NoError(t, err)
- headerRequest := applyPatchHeaderRequest(testRepo, testhelper.TestUser, testCase.branchName)
+ headerRequest := applyPatchHeaderRequest(repoProto, testhelper.TestUser, testCase.branchName)
require.NoError(t, stream.Send(headerRequest))
writer := streamio.NewWriter(func(p []byte) error {
@@ -103,14 +104,14 @@ func testSuccessfulUserApplyPatch(t *testing.T, ctx context.Context) {
response.GetBranchUpdate()
require.Equal(t, testCase.branchCreated, response.GetBranchUpdate().GetBranchCreated())
- branches := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch")
+ branches := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch")
require.Contains(t, string(branches), testCase.branchName)
maxCount := fmt.Sprintf("--max-count=%d", len(testCase.commitMessages))
gitArgs := []string{
"-C",
- testRepoPath,
+ repoPath,
"log",
testCase.branchName,
"--format=%H",
@@ -127,7 +128,7 @@ func testSuccessfulUserApplyPatch(t *testing.T, ctx context.Context) {
}
for index, sha := range shas {
- commit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(sha))
+ commit, err := repo.ReadCommit(ctx, git.Revision(sha))
require.NoError(t, err)
require.NotNil(t, commit)
@@ -146,8 +147,9 @@ func TestUserApplyPatch_stableID(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- repo, _, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
ctx, cancel := testhelper.Context()
defer cancel()
@@ -158,7 +160,7 @@ func TestUserApplyPatch_stableID(t *testing.T) {
require.NoError(t, stream.Send(&gitalypb.UserApplyPatchRequest{
UserApplyPatchRequestPayload: &gitalypb.UserApplyPatchRequest_Header_{
Header: &gitalypb.UserApplyPatchRequest_Header{
- Repository: repo,
+ Repository: repoProto,
User: testhelper.TestUser,
TargetBranch: []byte("branch"),
Timestamp: &timestamp.Timestamp{Seconds: 1234512345},
@@ -178,7 +180,7 @@ func TestUserApplyPatch_stableID(t *testing.T) {
require.NoError(t, err)
require.True(t, response.BranchUpdate.BranchCreated)
- patchedCommit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), repo, git.Revision("branch"))
+ patchedCommit, err := repo.ReadCommit(ctx, git.Revision("branch"))
require.NoError(t, err)
require.Equal(t, &gitalypb.GitCommit{
Id: "8cd17acdb54178121167078c78d874d3cc09b216",
diff --git a/internal/gitaly/service/operations/branches_test.go b/internal/gitaly/service/operations/branches_test.go
index 7ef37a9e5..447f515fa 100644
--- a/internal/gitaly/service/operations/branches_test.go
+++ b/internal/gitaly/service/operations/branches_test.go
@@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/client"
"gitlab.com/gitlab-org/gitaly/internal/git"
- "gitlab.com/gitlab-org/gitaly/internal/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
gitalyhook "gitlab.com/gitlab-org/gitaly/internal/gitaly/hook"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/service/hook"
@@ -39,8 +39,9 @@ func TestSuccessfulCreateBranchRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
serverSocketPath, stop := runOperationServiceServer(t)
defer stop()
@@ -49,7 +50,7 @@ func TestSuccessfulCreateBranchRequest(t *testing.T) {
defer conn.Close()
startPoint := "c7fbe50c7c7419d9701eebe64b1fdacc3df5b9dd"
- startPointCommit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(startPoint))
+ startPointCommit, err := repo.ReadCommit(ctx, git.Revision(startPoint))
require.NoError(t, err)
testCases := []struct {
@@ -96,7 +97,7 @@ func TestSuccessfulCreateBranchRequest(t *testing.T) {
t.Run(testCase.desc, func(t *testing.T) {
branchName := testCase.branchName
request := &gitalypb.UserCreateBranchRequest{
- Repository: testRepo,
+ Repository: repoProto,
BranchName: []byte(branchName),
StartPoint: []byte(testCase.startPoint),
User: testhelper.TestUser,
@@ -107,14 +108,14 @@ func TestSuccessfulCreateBranchRequest(t *testing.T) {
response, err := client.UserCreateBranch(ctx, request)
if testCase.expectedBranch != nil {
- defer testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", "-D", branchName)
+ defer testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", "-D", branchName)
}
require.NoError(t, err)
require.Equal(t, testCase.expectedBranch, response.Branch)
require.Empty(t, response.PreReceiveError)
- branches := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "for-each-ref", "--", "refs/heads/"+branchName)
+ branches := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "for-each-ref", "--", "refs/heads/"+branchName)
require.Contains(t, string(branches), "refs/heads/"+branchName)
})
}
@@ -265,8 +266,9 @@ func TestSuccessfulCreateBranchRequestWithStartPointRefPrefix(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
testCases := []struct {
desc string
@@ -298,12 +300,12 @@ func TestSuccessfulCreateBranchRequestWithStartPointRefPrefix(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "update-ref", "refs/heads/"+testCase.startPoint,
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "update-ref", "refs/heads/"+testCase.startPoint,
testCase.startPointCommit,
"0000000000000000000000000000000000000000",
)
request := &gitalypb.UserCreateBranchRequest{
- Repository: testRepo,
+ Repository: repoProto,
BranchName: []byte(testCase.branchName),
StartPoint: []byte(testCase.startPoint),
User: testCase.user,
@@ -313,9 +315,9 @@ func TestSuccessfulCreateBranchRequestWithStartPointRefPrefix(t *testing.T) {
// like BranchName. See
// https://gitlab.com/gitlab-org/gitaly/-/issues/3331
//
- //targetCommitOK, err := log.GetCommit(ctx, testRepo, testCase.startPointCommit)
+ //targetCommitOK, err := repo.ReadCommit(ctx, testCase.startPointCommit)
// END TODO
- targetCommitOK, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, "1e292f8fedd741b75372e19097c76d327140c312")
+ targetCommitOK, err := repo.ReadCommit(ctx, "1e292f8fedd741b75372e19097c76d327140c312")
require.NoError(t, err)
response, err := client.UserCreateBranch(ctx, request)
@@ -327,7 +329,7 @@ func TestSuccessfulCreateBranchRequestWithStartPointRefPrefix(t *testing.T) {
},
}
require.Equal(t, responseOk, response)
- branches := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "for-each-ref", "--", "refs/heads/"+testCase.branchName)
+ branches := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "for-each-ref", "--", "refs/heads/"+testCase.branchName)
require.Contains(t, string(branches), "refs/heads/"+testCase.branchName)
})
}
diff --git a/internal/gitaly/service/operations/cherry_pick_test.go b/internal/gitaly/service/operations/cherry_pick_test.go
index a8637675c..a5acabaab 100644
--- a/internal/gitaly/service/operations/cherry_pick_test.go
+++ b/internal/gitaly/service/operations/cherry_pick_test.go
@@ -7,7 +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/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -25,17 +25,17 @@ func TestSuccessfulUserCherryPickRequest(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
destinationBranch := "cherry-picking-dst"
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", destinationBranch, "master")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", destinationBranch, "master")
- gitCmdFactory := git.NewExecCommandFactory(config.Config)
- masterHeadCommit, err := log.GetCommit(ctxOuter, gitCmdFactory, testRepo, "master")
+ masterHeadCommit, err := repo.ReadCommit(ctxOuter, "master")
require.NoError(t, err)
- cherryPickedCommit, err := log.GetCommit(ctxOuter, gitCmdFactory, testRepo, "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab")
+ cherryPickedCommit, err := repo.ReadCommit(ctxOuter, "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab")
require.NoError(t, err)
testRepoCopy, testRepoCopyPath, cleanup := testhelper.NewTestRepo(t) // read-only repo
@@ -51,7 +51,7 @@ func TestSuccessfulUserCherryPickRequest(t *testing.T) {
{
desc: "branch exists",
request: &gitalypb.UserCherryPickRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: cherryPickedCommit,
BranchName: []byte(destinationBranch),
@@ -62,7 +62,7 @@ func TestSuccessfulUserCherryPickRequest(t *testing.T) {
{
desc: "nonexistent branch + start_repository == repository",
request: &gitalypb.UserCherryPickRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: cherryPickedCommit,
BranchName: []byte("to-be-cherry-picked-into-1"),
@@ -74,7 +74,7 @@ func TestSuccessfulUserCherryPickRequest(t *testing.T) {
{
desc: "nonexistent branch + start_repository != repository",
request: &gitalypb.UserCherryPickRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: cherryPickedCommit,
BranchName: []byte("to-be-cherry-picked-into-2"),
@@ -87,7 +87,7 @@ func TestSuccessfulUserCherryPickRequest(t *testing.T) {
{
desc: "nonexistent branch + empty start_repository",
request: &gitalypb.UserCherryPickRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: cherryPickedCommit,
BranchName: []byte("to-be-cherry-picked-into-3"),
@@ -158,7 +158,8 @@ func TestSuccessfulUserCherryPickRequest(t *testing.T) {
response, err := client.UserCherryPick(ctx, testCase.request)
require.NoError(t, err)
- headCommit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testCase.request.Repository, git.Revision(testCase.request.BranchName))
+ testRepo := localrepo.New(testCase.request.Repository, config.Config)
+ headCommit, err := testRepo.ReadCommit(ctx, git.Revision(testCase.request.BranchName))
require.NoError(t, err)
expectedBranchUpdate := testCase.branchUpdate
@@ -193,17 +194,18 @@ func testSuccessfulGitHooksForUserCherryPickRequest(t *testing.T, ctxOuter conte
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
destinationBranch := "cherry-picking-dst"
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", destinationBranch, "master")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", destinationBranch, "master")
- cherryPickedCommit, err := log.GetCommit(ctxOuter, git.NewExecCommandFactory(config.Config), testRepo, "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab")
+ cherryPickedCommit, err := repo.ReadCommit(ctxOuter, "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab")
require.NoError(t, err)
request := &gitalypb.UserCherryPickRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: cherryPickedCommit,
BranchName: []byte(destinationBranch),
@@ -212,7 +214,7 @@ func testSuccessfulGitHooksForUserCherryPickRequest(t *testing.T, ctxOuter conte
var hookOutputFiles []string
for _, hookName := range GitlabHooks {
- hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName)
+ hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, repoPath, hookName)
defer cleanup()
hookOutputFiles = append(hookOutputFiles, hookOutputTempPath)
}
@@ -237,21 +239,21 @@ func TestUserCherryPick_stableID(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
ctx, cancel := testhelper.Context()
defer cancel()
destinationBranch := "cherry-picking-dst"
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", destinationBranch, "master")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", destinationBranch, "master")
- gitCmdFactory := git.NewExecCommandFactory(config.Config)
- commitToPick, err := log.GetCommit(ctx, gitCmdFactory, testRepo, "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab")
+ commitToPick, err := repo.ReadCommit(ctx, "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab")
require.NoError(t, err)
request := &gitalypb.UserCherryPickRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: commitToPick,
BranchName: []byte(destinationBranch),
@@ -267,7 +269,7 @@ func TestUserCherryPick_stableID(t *testing.T) {
require.Empty(t, response.PreReceiveError)
require.Equal(t, response.BranchUpdate.CommitId, "750e8cf248a67a0be1c5e3b891697d72c19af259")
- pickedCommit, err := log.GetCommit(ctx, gitCmdFactory, testRepo, "750e8cf248a67a0be1c5e3b891697d72c19af259")
+ pickedCommit, err := repo.ReadCommit(ctx, "750e8cf248a67a0be1c5e3b891697d72c19af259")
require.NoError(t, err)
require.Equal(t, &gitalypb.GitCommit{
Id: "750e8cf248a67a0be1c5e3b891697d72c19af259",
@@ -305,10 +307,11 @@ func TestFailedUserCherryPickRequestDueToValidations(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, _, cleanup := testhelper.NewTestRepo(t)
+ repoProto, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
- cherryPickedCommit, err := log.GetCommit(ctxOuter, git.NewExecCommandFactory(config.Config), testRepo, "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab")
+ cherryPickedCommit, err := repo.ReadCommit(ctxOuter, "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab")
require.NoError(t, err)
destinationBranch := "cherry-picking-dst"
@@ -321,7 +324,7 @@ func TestFailedUserCherryPickRequestDueToValidations(t *testing.T) {
{
desc: "empty user",
request: &gitalypb.UserCherryPickRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: nil,
Commit: cherryPickedCommit,
BranchName: []byte(destinationBranch),
@@ -332,7 +335,7 @@ func TestFailedUserCherryPickRequestDueToValidations(t *testing.T) {
{
desc: "empty commit",
request: &gitalypb.UserCherryPickRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: nil,
BranchName: []byte(destinationBranch),
@@ -343,7 +346,7 @@ func TestFailedUserCherryPickRequestDueToValidations(t *testing.T) {
{
desc: "empty branch name",
request: &gitalypb.UserCherryPickRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: cherryPickedCommit,
BranchName: nil,
@@ -354,7 +357,7 @@ func TestFailedUserCherryPickRequestDueToValidations(t *testing.T) {
{
desc: "empty message",
request: &gitalypb.UserCherryPickRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: cherryPickedCommit,
BranchName: []byte(destinationBranch),
@@ -385,17 +388,18 @@ func TestFailedUserCherryPickRequestDueToPreReceiveError(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
destinationBranch := "cherry-picking-dst"
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", destinationBranch, "master")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", destinationBranch, "master")
- cherryPickedCommit, err := log.GetCommit(ctxOuter, git.NewExecCommandFactory(config.Config), testRepo, "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab")
+ cherryPickedCommit, err := repo.ReadCommit(ctxOuter, "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab")
require.NoError(t, err)
request := &gitalypb.UserCherryPickRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: cherryPickedCommit,
BranchName: []byte(destinationBranch),
@@ -406,7 +410,7 @@ func TestFailedUserCherryPickRequestDueToPreReceiveError(t *testing.T) {
for _, hookName := range GitlabPreHooks {
t.Run(hookName, func(t *testing.T) {
- remove := testhelper.WriteCustomHook(t, testRepoPath, hookName, hookContent)
+ remove := testhelper.WriteCustomHook(t, repoPath, hookName, hookContent)
defer remove()
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
@@ -429,18 +433,19 @@ func TestFailedUserCherryPickRequestDueToCreateTreeError(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
destinationBranch := "cherry-picking-dst"
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", destinationBranch, "master")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", destinationBranch, "master")
// This commit already exists in master
- cherryPickedCommit, err := log.GetCommit(ctxOuter, git.NewExecCommandFactory(config.Config), testRepo, "4a24d82dbca5c11c61556f3b35ca472b7463187e")
+ cherryPickedCommit, err := repo.ReadCommit(ctxOuter, "4a24d82dbca5c11c61556f3b35ca472b7463187e")
require.NoError(t, err)
request := &gitalypb.UserCherryPickRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: cherryPickedCommit,
BranchName: []byte(destinationBranch),
@@ -466,19 +471,20 @@ func TestFailedUserCherryPickRequestDueToCommitError(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
sourceBranch := "cherry-pick-src"
destinationBranch := "cherry-picking-dst"
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", destinationBranch, "master")
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", sourceBranch, "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", destinationBranch, "master")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", sourceBranch, "8a0f2ee90d940bfb0ba1e14e8214b0649056e4ab")
- cherryPickedCommit, err := log.GetCommit(ctxOuter, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(sourceBranch))
+ cherryPickedCommit, err := repo.ReadCommit(ctxOuter, git.Revision(sourceBranch))
require.NoError(t, err)
request := &gitalypb.UserCherryPickRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: cherryPickedCommit,
BranchName: []byte(sourceBranch),
diff --git a/internal/gitaly/service/operations/commit_files_test.go b/internal/gitaly/service/operations/commit_files_test.go
index 7ddb0808d..64d0f2927 100644
--- a/internal/gitaly/service/operations/commit_files_test.go
+++ b/internal/gitaly/service/operations/commit_files_test.go
@@ -15,7 +15,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/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag"
@@ -964,8 +964,9 @@ func testUserCommitFilesStableCommitID(t *testing.T, ctx context.Context) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- repo, repoPath, cleanup := testhelper.InitBareRepo(t)
+ repoProto, repoPath, cleanup := testhelper.InitBareRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
for key, values := range testhelper.GitalyServersMetadata(t, serverSocketPath) {
for _, value := range values {
@@ -976,7 +977,7 @@ func testUserCommitFilesStableCommitID(t *testing.T, ctx context.Context) {
stream, err := client.UserCommitFiles(ctx)
require.NoError(t, err)
- headerRequest := headerRequest(repo, testhelper.TestUser, "master", []byte("commit message"))
+ headerRequest := headerRequest(repoProto, testhelper.TestUser, "master", []byte("commit message"))
setAuthorAndEmail(headerRequest, []byte("Author Name"), []byte("author.email@example.com"))
setTimestamp(t, headerRequest, time.Unix(12345, 0))
require.NoError(t, stream.Send(headerRequest))
@@ -993,7 +994,7 @@ func testUserCommitFilesStableCommitID(t *testing.T, ctx context.Context) {
{Mode: "100644", Path: "file.txt", Content: "content"},
})
- commit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), repo, "refs/heads/master")
+ commit, err := repo.ReadCommit(ctx, "refs/heads/master")
require.NoError(t, err)
require.Equal(t, &gitalypb.GitCommit{
Id: "4f0ca1fbf05e04dbd5f68d14677034e0afee58ff",
@@ -1103,7 +1104,7 @@ func testSuccessfulUserCommitFilesRequest(t *testing.T, ctx context.Context) {
require.Equal(t, tc.repoCreated, resp.GetBranchUpdate().GetRepoCreated())
require.Equal(t, tc.branchCreated, resp.GetBranchUpdate().GetBranchCreated())
- headCommit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), tc.repo, git.Revision(tc.branchName))
+ headCommit, err := localrepo.New(tc.repo, config.Config).ReadCommit(ctx, git.Revision(tc.branchName))
require.NoError(t, err)
require.Equal(t, authorName, headCommit.Author.Name)
require.Equal(t, testhelper.TestUser.Name, headCommit.Committer.Name)
@@ -1197,26 +1198,26 @@ func testSuccessfulUserCommitFilesRequestForceCommit(t *testing.T, ctx context.C
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
authorName := []byte("Jane Doe")
authorEmail := []byte("janedoe@gitlab.com")
targetBranchName := "feature"
startBranchName := []byte("master")
- gitCmdFactory := git.NewExecCommandFactory(config.Config)
- startBranchCommit, err := log.GetCommit(ctx, gitCmdFactory, testRepo, git.Revision(startBranchName))
+ startBranchCommit, err := repo.ReadCommit(ctx, git.Revision(startBranchName))
require.NoError(t, err)
- targetBranchCommit, err := log.GetCommit(ctx, gitCmdFactory, testRepo, git.Revision(targetBranchName))
+ targetBranchCommit, err := repo.ReadCommit(ctx, git.Revision(targetBranchName))
require.NoError(t, err)
- mergeBaseOut := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "merge-base", targetBranchCommit.Id, startBranchCommit.Id)
+ mergeBaseOut := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "merge-base", targetBranchCommit.Id, startBranchCommit.Id)
mergeBaseID := text.ChompBytes(mergeBaseOut)
require.NotEqual(t, mergeBaseID, targetBranchCommit.Id, "expected %s not to be an ancestor of %s", targetBranchCommit.Id, startBranchCommit.Id)
- headerRequest := headerRequest(testRepo, testhelper.TestUser, targetBranchName, commitFilesMessage)
+ headerRequest := headerRequest(repoProto, testhelper.TestUser, targetBranchName, commitFilesMessage)
setAuthorAndEmail(headerRequest, authorName, authorEmail)
setStartBranchName(headerRequest, startBranchName)
setForce(headerRequest, true)
@@ -1231,7 +1232,7 @@ func testSuccessfulUserCommitFilesRequestForceCommit(t *testing.T, ctx context.C
require.NoError(t, err)
update := resp.GetBranchUpdate()
- newTargetBranchCommit, err := log.GetCommit(ctx, gitCmdFactory, testRepo, git.Revision(targetBranchName))
+ newTargetBranchCommit, err := repo.ReadCommit(ctx, git.Revision(targetBranchName))
require.NoError(t, err)
require.Equal(t, newTargetBranchCommit.Id, update.CommitId)
@@ -1249,16 +1250,16 @@ func testSuccessfulUserCommitFilesRequestStartSha(t *testing.T, ctx context.Cont
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
targetBranchName := "new"
- gitCmdFactory := git.NewExecCommandFactory(config.Config)
- startCommit, err := log.GetCommit(ctx, gitCmdFactory, testRepo, "master")
+ startCommit, err := repo.ReadCommit(ctx, "master")
require.NoError(t, err)
- headerRequest := headerRequest(testRepo, testhelper.TestUser, targetBranchName, commitFilesMessage)
+ headerRequest := headerRequest(repoProto, testhelper.TestUser, targetBranchName, commitFilesMessage)
setStartSha(headerRequest, startCommit.Id)
stream, err := client.UserCommitFiles(ctx)
@@ -1271,7 +1272,7 @@ func testSuccessfulUserCommitFilesRequestStartSha(t *testing.T, ctx context.Cont
require.NoError(t, err)
update := resp.GetBranchUpdate()
- newTargetBranchCommit, err := log.GetCommit(ctx, gitCmdFactory, testRepo, git.Revision(targetBranchName))
+ newTargetBranchCommit, err := repo.ReadCommit(ctx, git.Revision(targetBranchName))
require.NoError(t, err)
require.Equal(t, newTargetBranchCommit.Id, update.CommitId)
@@ -1300,11 +1301,13 @@ func testSuccessfulUserCommitFilesRemoteRepositoryRequest(setHeader func(header
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
- newRepo, _, newRepoCleanupFn := testhelper.InitBareRepo(t)
+ newRepoProto, _, newRepoCleanupFn := testhelper.InitBareRepo(t)
defer newRepoCleanupFn()
+ newRepo := localrepo.New(newRepoProto, config.Config)
for key, values := range testhelper.GitalyServersMetadata(t, serverSocketPath) {
for _, value := range values {
@@ -1314,13 +1317,12 @@ func testSuccessfulUserCommitFilesRemoteRepositoryRequest(setHeader func(header
targetBranchName := "new"
- gitCmdFactory := git.NewExecCommandFactory(config.Config)
- startCommit, err := log.GetCommit(ctx, gitCmdFactory, testRepo, "master")
+ startCommit, err := repo.ReadCommit(ctx, "master")
require.NoError(t, err)
- headerRequest := headerRequest(newRepo, testhelper.TestUser, targetBranchName, commitFilesMessage)
+ headerRequest := headerRequest(newRepoProto, testhelper.TestUser, targetBranchName, commitFilesMessage)
setHeader(headerRequest)
- setStartRepository(headerRequest, testRepo)
+ setStartRepository(headerRequest, repoProto)
stream, err := client.UserCommitFiles(ctx)
require.NoError(t, err)
@@ -1332,7 +1334,7 @@ func testSuccessfulUserCommitFilesRemoteRepositoryRequest(setHeader func(header
require.NoError(t, err)
update := resp.GetBranchUpdate()
- newTargetBranchCommit, err := log.GetCommit(ctx, gitCmdFactory, newRepo, git.Revision(targetBranchName))
+ newTargetBranchCommit, err := newRepo.ReadCommit(ctx, git.Revision(targetBranchName))
require.NoError(t, err)
require.Equal(t, newTargetBranchCommit.Id, update.CommitId)
@@ -1351,8 +1353,9 @@ func testSuccessfulUserCommitFilesRequestWithSpecialCharactersInSignature(t *tes
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, _, cleanupFn := testhelper.InitBareRepo(t)
+ repoProto, _, cleanupFn := testhelper.InitBareRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
targetBranchName := "master"
@@ -1375,7 +1378,7 @@ func testSuccessfulUserCommitFilesRequestWithSpecialCharactersInSignature(t *tes
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- headerRequest := headerRequest(testRepo, tc.user, targetBranchName, commitFilesMessage)
+ headerRequest := headerRequest(repoProto, tc.user, targetBranchName, commitFilesMessage)
setAuthorAndEmail(headerRequest, tc.user.Name, tc.user.Email)
stream, err := client.UserCommitFiles(ctx)
@@ -1385,7 +1388,7 @@ func testSuccessfulUserCommitFilesRequestWithSpecialCharactersInSignature(t *tes
_, err = stream.CloseAndRecv()
require.NoError(t, err)
- newCommit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(targetBranchName))
+ newCommit, err := repo.ReadCommit(ctx, git.Revision(targetBranchName))
require.NoError(t, err)
require.Equal(t, tc.author.Name, newCommit.Author.Name, "author name")
diff --git a/internal/gitaly/service/operations/merge_test.go b/internal/gitaly/service/operations/merge_test.go
index 91cc9e3d5..515d13a32 100644
--- a/internal/gitaly/service/operations/merge_test.go
+++ b/internal/gitaly/service/operations/merge_test.go
@@ -15,7 +15,6 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
- gitlog "gitlab.com/gitlab-org/gitaly/internal/git/log"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag"
@@ -40,8 +39,9 @@ func testWithFeature(t *testing.T, feature featureflag.FeatureFlag, testcase fun
}
func TestSuccessfulMerge(t *testing.T) {
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
serverSocketPath, stop := runOperationServiceServer(t)
defer stop()
@@ -55,7 +55,7 @@ func TestSuccessfulMerge(t *testing.T) {
mergeBidi, err := client.UserMergeBranch(ctx)
require.NoError(t, err)
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", mergeBranchName, mergeBranchHeadBefore)
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", mergeBranchName, mergeBranchHeadBefore)
hooks := GitlabHooks
hookTempfiles := make([]string, len(hooks))
@@ -66,7 +66,7 @@ func TestSuccessfulMerge(t *testing.T) {
defer os.Remove(outputFile.Name())
script := fmt.Sprintf("#!/bin/sh\n(cat && env) >%s \n", outputFile.Name())
- cleanup := testhelper.WriteCustomHook(t, testRepoPath, hook, []byte(script))
+ cleanup := testhelper.WriteCustomHook(t, repoPath, hook, []byte(script))
defer cleanup()
hookTempfiles[i] = outputFile.Name()
@@ -74,7 +74,7 @@ func TestSuccessfulMerge(t *testing.T) {
mergeCommitMessage := "Merged by Gitaly"
firstRequest := &gitalypb.UserMergeBranchRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
CommitId: commitToMerge,
Branch: []byte(mergeBranchName),
@@ -86,8 +86,7 @@ func TestSuccessfulMerge(t *testing.T) {
firstResponse, err := mergeBidi.Recv()
require.NoError(t, err, "receive first response")
- gitCmdFactory := git.NewExecCommandFactory(config.Config)
- _, err = gitlog.GetCommit(ctx, gitCmdFactory, testRepo, git.Revision(firstResponse.CommitId))
+ _, err = repo.ReadCommit(ctx, git.Revision(firstResponse.CommitId))
require.NoError(t, err, "look up git commit before merge is applied")
require.NoError(t, mergeBidi.Send(&gitalypb.UserMergeBranchRequest{Apply: true}), "apply merge")
@@ -100,7 +99,7 @@ func TestSuccessfulMerge(t *testing.T) {
return err
})
- commit, err := gitlog.GetCommit(ctx, gitCmdFactory, testRepo, git.Revision(mergeBranchName))
+ commit, err := repo.ReadCommit(ctx, git.Revision(mergeBranchName))
require.NoError(t, err, "look up git commit after call has finished")
require.Equal(t, gitalypb.OperationBranchUpdate{CommitId: commit.Id}, *(secondResponse.BranchUpdate))
@@ -129,8 +128,9 @@ func TestSuccessfulMerge(t *testing.T) {
}
func TestSuccessfulMerge_stableMergeIDs(t *testing.T) {
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
serverSocketPath, stop := runOperationServiceServer(t)
defer stop()
@@ -144,10 +144,10 @@ func TestSuccessfulMerge_stableMergeIDs(t *testing.T) {
mergeBidi, err := client.UserMergeBranch(ctx)
require.NoError(t, err)
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", mergeBranchName, mergeBranchHeadBefore)
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", mergeBranchName, mergeBranchHeadBefore)
firstRequest := &gitalypb.UserMergeBranchRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
CommitId: commitToMerge,
Branch: []byte(mergeBranchName),
@@ -173,7 +173,7 @@ func TestSuccessfulMerge_stableMergeIDs(t *testing.T) {
return err
})
- commit, err := gitlog.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(mergeBranchName))
+ commit, err := repo.ReadCommit(ctx, git.Revision(mergeBranchName))
require.NoError(t, err, "look up git commit after call has finished")
require.Equal(t, commit, &gitalypb.GitCommit{
Subject: []byte("Merged by Gitaly"),
@@ -209,13 +209,14 @@ func TestAbortedMerge(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", mergeBranchName, mergeBranchHeadBefore)
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", mergeBranchName, mergeBranchHeadBefore)
firstRequest := &gitalypb.UserMergeBranchRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
CommitId: commitToMerge,
Branch: []byte(mergeBranchName),
@@ -262,7 +263,7 @@ func TestAbortedMerge(t *testing.T) {
require.Equal(t, "", secondResponse.GetBranchUpdate().GetCommitId(), "merge should not have been applied")
require.Error(t, err)
- commit, err := gitlog.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(mergeBranchName))
+ commit, err := repo.ReadCommit(ctx, git.Revision(mergeBranchName))
require.NoError(t, err, "look up git commit after call has finished")
require.Equal(t, mergeBranchHeadBefore, commit.Id, "branch should not change when the merge is aborted")
@@ -271,8 +272,9 @@ func TestAbortedMerge(t *testing.T) {
}
func TestFailedMergeConcurrentUpdate(t *testing.T) {
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
serverSocketPath, stop := runOperationServiceServer(t)
defer stop()
@@ -286,11 +288,11 @@ func TestFailedMergeConcurrentUpdate(t *testing.T) {
mergeBidi, err := client.UserMergeBranch(ctx)
require.NoError(t, err)
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", mergeBranchName, mergeBranchHeadBefore)
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", mergeBranchName, mergeBranchHeadBefore)
mergeCommitMessage := "Merged by Gitaly"
firstRequest := &gitalypb.UserMergeBranchRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
CommitId: commitToMerge,
Branch: []byte(mergeBranchName),
@@ -302,7 +304,7 @@ func TestFailedMergeConcurrentUpdate(t *testing.T) {
require.NoError(t, err, "receive first response")
// This concurrent update of the branch we are merging into should make the merge fail.
- concurrentCommitID := testhelper.CreateCommit(t, testRepoPath, mergeBranchName, nil)
+ concurrentCommitID := testhelper.CreateCommit(t, repoPath, mergeBranchName, nil)
require.NotEqual(t, firstResponse.CommitId, concurrentCommitID)
require.NoError(t, mergeBidi.Send(&gitalypb.UserMergeBranchRequest{Apply: true}), "apply merge")
@@ -312,14 +314,15 @@ func TestFailedMergeConcurrentUpdate(t *testing.T) {
require.NoError(t, err, "receive second response")
testhelper.ProtoEqual(t, secondResponse, &gitalypb.UserMergeBranchResponse{})
- commit, err := gitlog.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(mergeBranchName))
+ commit, err := repo.ReadCommit(ctx, git.Revision(mergeBranchName))
require.NoError(t, err, "get commit after RPC finished")
require.Equal(t, commit.Id, concurrentCommitID, "RPC should not have trampled concurrent update")
}
func TestUserMergeBranch_ambiguousReference(t *testing.T) {
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
serverSocketPath, stop := runOperationServiceServer(t)
defer stop()
@@ -333,9 +336,7 @@ func TestUserMergeBranch_ambiguousReference(t *testing.T) {
merge, err := client.UserMergeBranch(ctx)
require.NoError(t, err)
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", mergeBranchName, mergeBranchHeadBefore)
-
- repo := localrepo.New(testRepo, config.Config)
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", mergeBranchName, mergeBranchHeadBefore)
masterOID, err := repo.ResolveRevision(ctx, "refs/heads/master")
require.NoError(t, err)
@@ -355,7 +356,7 @@ func TestUserMergeBranch_ambiguousReference(t *testing.T) {
mergeCommitMessage := "Merged by Gitaly"
firstRequest := &gitalypb.UserMergeBranchRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
CommitId: commitToMerge,
Branch: []byte(mergeBranchName),
@@ -377,7 +378,7 @@ func TestUserMergeBranch_ambiguousReference(t *testing.T) {
return err
})
- commit, err := gitlog.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision("refs/heads/"+mergeBranchName))
+ commit, err := repo.ReadCommit(ctx, git.Revision("refs/heads/"+mergeBranchName))
require.NoError(t, err, "look up git commit after call has finished")
require.Equal(t, gitalypb.OperationBranchUpdate{CommitId: commit.Id}, *(response.BranchUpdate))
@@ -688,10 +689,11 @@ func TestSuccessfulUserMergeToRefRequest(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", mergeBranchName, mergeBranchHeadBefore)
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", mergeBranchName, mergeBranchHeadBefore)
existingTargetRef := []byte("refs/merge-requests/x/written")
emptyTargetRef := []byte("refs/merge-requests/x/merge")
@@ -699,7 +701,7 @@ func TestSuccessfulUserMergeToRefRequest(t *testing.T) {
// Writes in existingTargetRef
beforeRefreshCommitSha := "a5391128b0ef5d21df5dd23d98557f4ef12fae20"
- out, err := exec.Command(config.Config.Git.BinPath, "-C", testRepoPath, "update-ref", string(existingTargetRef), beforeRefreshCommitSha).CombinedOutput()
+ out, err := exec.Command(config.Config.Git.BinPath, "-C", repoPath, "update-ref", string(existingTargetRef), beforeRefreshCommitSha).CombinedOutput()
require.NoError(t, err, "give an existing state to the target ref: %s", out)
testCases := []struct {
@@ -744,7 +746,7 @@ func TestSuccessfulUserMergeToRefRequest(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
request := &gitalypb.UserMergeToRefRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testCase.user,
Branch: testCase.branch,
TargetRef: testCase.targetRef,
@@ -753,8 +755,7 @@ func TestSuccessfulUserMergeToRefRequest(t *testing.T) {
FirstParentRef: testCase.firstParentRef,
}
- gitCmdFactory := git.NewExecCommandFactory(config.Config)
- commitBeforeRefMerge, fetchRefBeforeMergeErr := gitlog.GetCommit(ctx, gitCmdFactory, testRepo, git.Revision(testCase.targetRef))
+ commitBeforeRefMerge, fetchRefBeforeMergeErr := repo.ReadCommit(ctx, git.Revision(testCase.targetRef))
if testCase.emptyRef {
require.Error(t, fetchRefBeforeMergeErr, "error when fetching empty ref commit")
} else {
@@ -764,7 +765,7 @@ func TestSuccessfulUserMergeToRefRequest(t *testing.T) {
resp, err := client.UserMergeToRef(ctx, request)
require.NoError(t, err)
- commit, err := gitlog.GetCommit(ctx, gitCmdFactory, testRepo, git.Revision(testCase.targetRef))
+ commit, err := repo.ReadCommit(ctx, git.Revision(testCase.targetRef))
require.NoError(t, err, "look up git commit after call has finished")
// Asserts commit parent SHAs
@@ -848,13 +849,14 @@ func TestUserMergeToRef_stableMergeID(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", mergeBranchName, mergeBranchHeadBefore)
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", mergeBranchName, mergeBranchHeadBefore)
response, err := client.UserMergeToRef(ctx, &gitalypb.UserMergeToRefRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
FirstParentRef: []byte("refs/heads/" + mergeBranchName),
TargetRef: []byte("refs/merge-requests/x/written"),
@@ -865,7 +867,7 @@ func TestUserMergeToRef_stableMergeID(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "a04514f4e6b4e272989b39cca1ebdbb670abdfd6", response.CommitId)
- commit, err := gitlog.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision("refs/merge-requests/x/written"))
+ commit, err := repo.ReadCommit(ctx, git.Revision("refs/merge-requests/x/written"))
require.NoError(t, err, "look up git commit after call has finished")
require.Equal(t, &gitalypb.GitCommit{
Subject: []byte("Merge message"),
diff --git a/internal/gitaly/service/operations/rebase_test.go b/internal/gitaly/service/operations/rebase_test.go
index 51eeda301..f8db29d55 100644
--- a/internal/gitaly/service/operations/rebase_test.go
+++ b/internal/gitaly/service/operations/rebase_test.go
@@ -11,8 +11,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/git/catfile"
- gitlog "gitlab.com/gitlab-org/gitaly/internal/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
@@ -44,13 +43,14 @@ func TestSuccessfulUserRebaseConfirmableRequest(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
- testRepoCopy, _, cleanup := testhelper.NewTestRepo(t)
+ repoCopyProto, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
- branchSha := getBranchSha(t, testRepoPath, rebaseBranchName)
+ branchSha := getBranchSha(t, repoPath, rebaseBranchName)
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
@@ -64,19 +64,19 @@ func TestSuccessfulUserRebaseConfirmableRequest(t *testing.T) {
rebaseStream, err := client.UserRebaseConfirmable(ctx)
require.NoError(t, err)
- preReceiveHookOutputPath, removePreReceive := testhelper.WriteEnvToCustomHook(t, testRepoPath, "pre-receive")
- postReceiveHookOutputPath, removePostReceive := testhelper.WriteEnvToCustomHook(t, testRepoPath, "post-receive")
+ preReceiveHookOutputPath, removePreReceive := testhelper.WriteEnvToCustomHook(t, repoPath, "pre-receive")
+ postReceiveHookOutputPath, removePostReceive := testhelper.WriteEnvToCustomHook(t, repoPath, "post-receive")
defer removePreReceive()
defer removePostReceive()
- headerRequest := buildHeaderRequest(testRepo, testhelper.TestUser, "1", rebaseBranchName, branchSha, testRepoCopy, "master")
+ headerRequest := buildHeaderRequest(repoProto, testhelper.TestUser, "1", rebaseBranchName, branchSha, repoCopyProto, "master")
headerRequest.GetHeader().GitPushOptions = pushOptions
require.NoError(t, rebaseStream.Send(headerRequest), "send header")
firstResponse, err := rebaseStream.Recv()
require.NoError(t, err, "receive first response")
- _, err = gitlog.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(firstResponse.GetRebaseSha()))
+ _, err = repo.ReadCommit(ctx, git.Revision(firstResponse.GetRebaseSha()))
require.NoError(t, err, "look up git commit before rebase is applied")
applyRequest := buildApplyRequest(true)
@@ -90,7 +90,7 @@ func TestSuccessfulUserRebaseConfirmableRequest(t *testing.T) {
return err
})
- newBranchSha := getBranchSha(t, testRepoPath, rebaseBranchName)
+ newBranchSha := getBranchSha(t, repoPath, rebaseBranchName)
require.NotEqual(t, newBranchSha, branchSha)
require.Equal(t, newBranchSha, firstResponse.GetRebaseSha())
@@ -119,8 +119,9 @@ func TestUserRebaseConfirmable_stableCommitIDs(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
ctx, cancel := testhelper.Context()
defer cancel()
@@ -132,17 +133,17 @@ func TestUserRebaseConfirmable_stableCommitIDs(t *testing.T) {
require.NoError(t, err)
committerDate := &timestamp.Timestamp{Seconds: 100000000}
- parentSha := getBranchSha(t, testRepoPath, "master")
+ parentSha := getBranchSha(t, repoPath, "master")
require.NoError(t, rebaseStream.Send(&gitalypb.UserRebaseConfirmableRequest{
UserRebaseConfirmableRequestPayload: &gitalypb.UserRebaseConfirmableRequest_Header_{
Header: &gitalypb.UserRebaseConfirmableRequest_Header{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
RebaseId: "1",
Branch: []byte(rebaseBranchName),
- BranchSha: getBranchSha(t, testRepoPath, rebaseBranchName),
- RemoteRepository: testRepo,
+ BranchSha: getBranchSha(t, repoPath, rebaseBranchName),
+ RemoteRepository: repoProto,
RemoteBranch: []byte("master"),
Timestamp: committerDate,
},
@@ -165,7 +166,7 @@ func TestUserRebaseConfirmable_stableCommitIDs(t *testing.T) {
return err
})
- commit, err := gitlog.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(rebaseBranchName))
+ commit, err := repo.ReadCommit(ctx, git.Revision(rebaseBranchName))
require.NoError(t, err, "look up git commit")
testhelper.ProtoEqual(t, &gitalypb.GitCommit{
Subject: []byte("Add a directory with many files to allow testing of default 1,000 entry limit"),
@@ -339,13 +340,14 @@ func TestFailedUserRebaseConfirmableDueToApplyBeingFalse(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
testRepoCopy, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
- branchSha := getBranchSha(t, testRepoPath, rebaseBranchName)
+ branchSha := getBranchSha(t, repoPath, rebaseBranchName)
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
ctx := metadata.NewOutgoingContext(ctxOuter, md)
@@ -353,13 +355,13 @@ func TestFailedUserRebaseConfirmableDueToApplyBeingFalse(t *testing.T) {
rebaseStream, err := client.UserRebaseConfirmable(ctx)
require.NoError(t, err)
- headerRequest := buildHeaderRequest(testRepo, testhelper.TestUser, "1", rebaseBranchName, branchSha, testRepoCopy, "master")
+ headerRequest := buildHeaderRequest(repoProto, testhelper.TestUser, "1", rebaseBranchName, branchSha, testRepoCopy, "master")
require.NoError(t, rebaseStream.Send(headerRequest), "send header")
firstResponse, err := rebaseStream.Recv()
require.NoError(t, err, "receive first response")
- _, err = gitlog.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(firstResponse.GetRebaseSha()))
+ _, err = repo.ReadCommit(ctx, git.Revision(firstResponse.GetRebaseSha()))
require.NoError(t, err, "look up git commit before rebase is applied")
applyRequest := buildApplyRequest(false)
@@ -370,7 +372,7 @@ func TestFailedUserRebaseConfirmableDueToApplyBeingFalse(t *testing.T) {
testhelper.RequireGrpcError(t, err, codes.FailedPrecondition)
require.False(t, secondResponse.GetRebaseApplied(), "the second rebase is not applied")
- newBranchSha := getBranchSha(t, testRepoPath, rebaseBranchName)
+ newBranchSha := getBranchSha(t, repoPath, rebaseBranchName)
require.Equal(t, branchSha, newBranchSha, "branch should not change when the rebase is not applied")
require.NotEqual(t, newBranchSha, firstResponse.GetRebaseSha(), "branch should not be the sha returned when the rebase is not applied")
}
@@ -385,19 +387,20 @@ func TestFailedUserRebaseConfirmableRequestDueToPreReceiveError(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
- testRepoCopy, _, cleanup := testhelper.NewTestRepo(t)
+ repoCopyProto, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
- branchSha := getBranchSha(t, testRepoPath, rebaseBranchName)
+ branchSha := getBranchSha(t, repoPath, rebaseBranchName)
hookContent := []byte("#!/bin/sh\necho 'failure'\nexit 1")
for i, hookName := range GitlabPreHooks {
t.Run(hookName, func(t *testing.T) {
- remove := testhelper.WriteCustomHook(t, testRepoPath, hookName, hookContent)
+ remove := testhelper.WriteCustomHook(t, repoPath, hookName, hookContent)
defer remove()
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
@@ -406,13 +409,13 @@ func TestFailedUserRebaseConfirmableRequestDueToPreReceiveError(t *testing.T) {
rebaseStream, err := client.UserRebaseConfirmable(ctx)
require.NoError(t, err)
- headerRequest := buildHeaderRequest(testRepo, testhelper.TestUser, fmt.Sprintf("%v", i), rebaseBranchName, branchSha, testRepoCopy, "master")
+ headerRequest := buildHeaderRequest(repoProto, testhelper.TestUser, fmt.Sprintf("%v", i), rebaseBranchName, branchSha, repoCopyProto, "master")
require.NoError(t, rebaseStream.Send(headerRequest), "send header")
firstResponse, err := rebaseStream.Recv()
require.NoError(t, err, "receive first response")
- _, err = gitlog.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(firstResponse.GetRebaseSha()))
+ _, err = repo.ReadCommit(ctx, git.Revision(firstResponse.GetRebaseSha()))
require.NoError(t, err, "look up git commit before rebase is applied")
applyRequest := buildApplyRequest(true)
@@ -428,7 +431,7 @@ func TestFailedUserRebaseConfirmableRequestDueToPreReceiveError(t *testing.T) {
return err
})
- newBranchSha := getBranchSha(t, testRepoPath, rebaseBranchName)
+ newBranchSha := getBranchSha(t, repoPath, rebaseBranchName)
require.Equal(t, branchSha, newBranchSha, "branch should not change when the rebase fails due to PreReceiveError")
require.NotEqual(t, newBranchSha, firstResponse.GetRebaseSha(), "branch should not be the sha returned when the rebase fails due to PreReceiveError")
})
@@ -491,10 +494,11 @@ func TestRebaseRequestWithDeletedFile(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepoWithWorktree(t)
+ repoProto, repoProtoPath, cleanupFn := testhelper.NewTestRepoWithWorktree(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
- testRepoCopy, _, cleanup := testhelper.NewTestRepo(t)
+ repoCopyProto, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
@@ -502,24 +506,24 @@ func TestRebaseRequestWithDeletedFile(t *testing.T) {
branch := "rebase-delete-test"
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "config", "user.name", string(testhelper.TestUser.Name))
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "config", "user.email", string(testhelper.TestUser.Email))
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "checkout", "-b", branch, "master~1")
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "rm", "README")
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "commit", "-a", "-m", "delete file")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoProtoPath, "config", "user.name", string(testhelper.TestUser.Name))
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoProtoPath, "config", "user.email", string(testhelper.TestUser.Email))
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoProtoPath, "checkout", "-b", branch, "master~1")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoProtoPath, "rm", "README")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoProtoPath, "commit", "-a", "-m", "delete file")
- branchSha := getBranchSha(t, testRepoPath, branch)
+ branchSha := getBranchSha(t, repoProtoPath, branch)
rebaseStream, err := client.UserRebaseConfirmable(ctx)
require.NoError(t, err)
- headerRequest := buildHeaderRequest(testRepo, testhelper.TestUser, "1", branch, branchSha, testRepoCopy, "master")
+ headerRequest := buildHeaderRequest(repoProto, testhelper.TestUser, "1", branch, branchSha, repoCopyProto, "master")
require.NoError(t, rebaseStream.Send(headerRequest), "send header")
firstResponse, err := rebaseStream.Recv()
require.NoError(t, err, "receive first response")
- _, err = gitlog.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(firstResponse.GetRebaseSha()))
+ _, err = repo.ReadCommit(ctx, git.Revision(firstResponse.GetRebaseSha()))
require.NoError(t, err, "look up git commit before rebase is applied")
applyRequest := buildApplyRequest(true)
@@ -533,7 +537,7 @@ func TestRebaseRequestWithDeletedFile(t *testing.T) {
return err
})
- newBranchSha := getBranchSha(t, testRepoPath, branch)
+ newBranchSha := getBranchSha(t, repoProtoPath, branch)
require.NotEqual(t, newBranchSha, branchSha)
require.Equal(t, newBranchSha, firstResponse.GetRebaseSha())
@@ -548,8 +552,9 @@ func TestRebaseOntoRemoteBranch(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- localRepo, localRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ localRepoProto, localRepoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ localRepo := localrepo.New(localRepoProto, config.Config)
remoteRepo, remoteRepoPath, cleanup := testhelper.NewTestRepoWithWorktree(t)
defer cleanup()
@@ -574,17 +579,16 @@ func TestRebaseOntoRemoteBranch(t *testing.T) {
rebaseStream, err := client.UserRebaseConfirmable(ctx)
require.NoError(t, err)
- gitCmdFactory := git.NewExecCommandFactory(config.Config)
- _, err = gitlog.GetCommit(ctx, gitCmdFactory, localRepo, git.Revision(remoteBranchHash))
- require.True(t, catfile.IsNotFound(err), "remote commit does not yet exist in local repository")
+ _, err = localRepo.ReadCommit(ctx, git.Revision(remoteBranchHash))
+ require.Equal(t, localrepo.ErrObjectNotFound, err, "remote commit does not yet exist in local repository")
- headerRequest := buildHeaderRequest(localRepo, testhelper.TestUser, "1", localBranch, localBranchHash, remoteRepo, remoteBranch)
+ headerRequest := buildHeaderRequest(localRepoProto, testhelper.TestUser, "1", localBranch, localBranchHash, remoteRepo, remoteBranch)
require.NoError(t, rebaseStream.Send(headerRequest), "send header")
firstResponse, err := rebaseStream.Recv()
require.NoError(t, err, "receive first response")
- _, err = gitlog.GetCommit(ctx, gitCmdFactory, localRepo, git.Revision(remoteBranchHash))
+ _, err = localRepo.ReadCommit(ctx, git.Revision(remoteBranchHash))
require.NoError(t, err, "remote commit does now exist in local repository")
applyRequest := buildApplyRequest(true)
diff --git a/internal/gitaly/service/operations/revert_test.go b/internal/gitaly/service/operations/revert_test.go
index 64c10eb15..2b71be6d9 100644
--- a/internal/gitaly/service/operations/revert_test.go
+++ b/internal/gitaly/service/operations/revert_test.go
@@ -7,7 +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/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
@@ -26,17 +26,17 @@ func testServerUserRevertSuccessful(t *testing.T, ctxOuter context.Context) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
destinationBranch := "revert-dst"
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", destinationBranch, "master")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", destinationBranch, "master")
- gitCmdFactory := git.NewExecCommandFactory(config.Config)
- masterHeadCommit, err := log.GetCommit(ctxOuter, gitCmdFactory, testRepo, "master")
+ masterHeadCommit, err := repo.ReadCommit(ctxOuter, "master")
require.NoError(t, err)
- revertedCommit, err := log.GetCommit(ctxOuter, gitCmdFactory, testRepo, "d59c60028b053793cecfb4022de34602e1a9218e")
+ revertedCommit, err := repo.ReadCommit(ctxOuter, "d59c60028b053793cecfb4022de34602e1a9218e")
require.NoError(t, err)
testRepoCopy, testRepoCopyPath, cleanup := testhelper.NewTestRepo(t) // read-only repo
@@ -52,7 +52,7 @@ func testServerUserRevertSuccessful(t *testing.T, ctxOuter context.Context) {
{
desc: "branch exists",
request: &gitalypb.UserRevertRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: revertedCommit,
BranchName: []byte(destinationBranch),
@@ -63,7 +63,7 @@ func testServerUserRevertSuccessful(t *testing.T, ctxOuter context.Context) {
{
desc: "nonexistent branch + start_repository == repository",
request: &gitalypb.UserRevertRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: revertedCommit,
BranchName: []byte("to-be-reverted-into-1"),
@@ -75,7 +75,7 @@ func testServerUserRevertSuccessful(t *testing.T, ctxOuter context.Context) {
{
desc: "nonexistent branch + start_repository != repository",
request: &gitalypb.UserRevertRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: revertedCommit,
BranchName: []byte("to-be-reverted-into-2"),
@@ -88,7 +88,7 @@ func testServerUserRevertSuccessful(t *testing.T, ctxOuter context.Context) {
{
desc: "nonexistent branch + empty start_repository",
request: &gitalypb.UserRevertRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: revertedCommit,
BranchName: []byte("to-be-reverted-into-3"),
@@ -159,7 +159,8 @@ func testServerUserRevertSuccessful(t *testing.T, ctxOuter context.Context) {
response, err := client.UserRevert(ctx, testCase.request)
require.NoError(t, err)
- headCommit, err := log.GetCommit(ctx, gitCmdFactory, testCase.request.Repository, git.Revision(testCase.request.BranchName))
+ testCaseRepo := localrepo.New(testCase.request.Repository, config.Config)
+ headCommit, err := testCaseRepo.ReadCommit(ctx, git.Revision(testCase.request.BranchName))
require.NoError(t, err)
expectedBranchUpdate := testCase.branchUpdate
@@ -191,18 +192,18 @@ func testServerUserRevertStableID(t *testing.T, ctxOuter context.Context) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- repo, _, cleanup := testhelper.NewTestRepo(t)
+ repoProto, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
ctx := testhelper.MergeOutgoingMetadata(ctxOuter, md)
- gitCmdFactory := git.NewExecCommandFactory(config.Config)
- commitToRevert, err := log.GetCommit(ctxOuter, gitCmdFactory, repo, "d59c60028b053793cecfb4022de34602e1a9218e")
+ commitToRevert, err := repo.ReadCommit(ctxOuter, "d59c60028b053793cecfb4022de34602e1a9218e")
require.NoError(t, err)
response, err := client.UserRevert(ctx, &gitalypb.UserRevertRequest{
- Repository: repo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: commitToRevert,
BranchName: []byte("master"),
@@ -217,7 +218,7 @@ func testServerUserRevertStableID(t *testing.T, ctxOuter context.Context) {
require.Empty(t, response.CreateTreeError)
require.Empty(t, response.CreateTreeErrorCode)
- revertedCommit, err := log.GetCommit(ctx, gitCmdFactory, repo, git.Revision("master"))
+ revertedCommit, err := repo.ReadCommit(ctx, git.Revision("master"))
require.NoError(t, err)
require.Equal(t, &gitalypb.GitCommit{
@@ -255,26 +256,27 @@ func testServerUserRevertSuccessfulIntoNewRepo(t *testing.T, ctxOuter context.Co
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- startRepo, _, cleanup := testhelper.NewTestRepo(t)
+ startRepoProto, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ startRepo := localrepo.New(startRepoProto, config.Config)
- gitCmdFactory := git.NewExecCommandFactory(config.Config)
- revertedCommit, err := log.GetCommit(ctxOuter, gitCmdFactory, startRepo, "d59c60028b053793cecfb4022de34602e1a9218e")
+ revertedCommit, err := startRepo.ReadCommit(ctxOuter, "d59c60028b053793cecfb4022de34602e1a9218e")
require.NoError(t, err)
- masterHeadCommit, err := log.GetCommit(ctxOuter, gitCmdFactory, startRepo, "master")
+ masterHeadCommit, err := startRepo.ReadCommit(ctxOuter, "master")
require.NoError(t, err)
- testRepo, _, cleanup := testhelper.InitBareRepo(t)
+ repoProto, _, cleanup := testhelper.InitBareRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
request := &gitalypb.UserRevertRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: revertedCommit,
BranchName: []byte("dst-branch"),
Message: []byte("Reverting " + revertedCommit.Id),
- StartRepository: startRepo,
+ StartRepository: startRepoProto,
StartBranchName: []byte("master"),
}
@@ -284,7 +286,7 @@ func testServerUserRevertSuccessfulIntoNewRepo(t *testing.T, ctxOuter context.Co
response, err := client.UserRevert(ctx, request)
require.NoError(t, err)
- headCommit, err := log.GetCommit(ctx, gitCmdFactory, testRepo, git.Revision(request.BranchName))
+ headCommit, err := repo.ReadCommit(ctx, git.Revision(request.BranchName))
require.NoError(t, err)
expectedBranchUpdate := &gitalypb.OperationBranchUpdate{
@@ -311,17 +313,18 @@ func testServerUserRevertSuccessfulGitHooks(t *testing.T, ctxOuter context.Conte
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
destinationBranch := "revert-dst"
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", destinationBranch, "master")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", destinationBranch, "master")
- revertedCommit, err := log.GetCommit(ctxOuter, git.NewExecCommandFactory(config.Config), testRepo, "d59c60028b053793cecfb4022de34602e1a9218e")
+ revertedCommit, err := repo.ReadCommit(ctxOuter, "d59c60028b053793cecfb4022de34602e1a9218e")
require.NoError(t, err)
request := &gitalypb.UserRevertRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: revertedCommit,
BranchName: []byte(destinationBranch),
@@ -330,7 +333,7 @@ func testServerUserRevertSuccessfulGitHooks(t *testing.T, ctxOuter context.Conte
var hookOutputFiles []string
for _, hookName := range GitlabHooks {
- hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, testRepoPath, hookName)
+ hookOutputTempPath, cleanup := testhelper.WriteEnvToCustomHook(t, repoPath, hookName)
defer cleanup()
hookOutputFiles = append(hookOutputFiles, hookOutputTempPath)
}
@@ -359,10 +362,11 @@ func testServerUserRevertFailuedDueToValidations(t *testing.T, ctxOuter context.
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, _, cleanup := testhelper.NewTestRepo(t)
+ repoProto, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
- revertedCommit, err := log.GetCommit(ctxOuter, git.NewExecCommandFactory(config.Config), testRepo, "d59c60028b053793cecfb4022de34602e1a9218e")
+ revertedCommit, err := repo.ReadCommit(ctxOuter, "d59c60028b053793cecfb4022de34602e1a9218e")
require.NoError(t, err)
destinationBranch := "revert-dst"
@@ -375,7 +379,7 @@ func testServerUserRevertFailuedDueToValidations(t *testing.T, ctxOuter context.
{
desc: "empty user",
request: &gitalypb.UserRevertRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: nil,
Commit: revertedCommit,
BranchName: []byte(destinationBranch),
@@ -386,7 +390,7 @@ func testServerUserRevertFailuedDueToValidations(t *testing.T, ctxOuter context.
{
desc: "empty commit",
request: &gitalypb.UserRevertRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: nil,
BranchName: []byte(destinationBranch),
@@ -397,7 +401,7 @@ func testServerUserRevertFailuedDueToValidations(t *testing.T, ctxOuter context.
{
desc: "empty branch name",
request: &gitalypb.UserRevertRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: revertedCommit,
BranchName: nil,
@@ -408,7 +412,7 @@ func testServerUserRevertFailuedDueToValidations(t *testing.T, ctxOuter context.
{
desc: "empty message",
request: &gitalypb.UserRevertRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: revertedCommit,
BranchName: []byte(destinationBranch),
@@ -440,17 +444,18 @@ func testServerUserRevertFailedDueToPreReceiveError(t *testing.T, ctxOuter conte
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
destinationBranch := "revert-dst"
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", destinationBranch, "master")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", destinationBranch, "master")
- revertedCommit, err := log.GetCommit(ctxOuter, git.NewExecCommandFactory(config.Config), testRepo, "d59c60028b053793cecfb4022de34602e1a9218e")
+ revertedCommit, err := repo.ReadCommit(ctxOuter, "d59c60028b053793cecfb4022de34602e1a9218e")
require.NoError(t, err)
request := &gitalypb.UserRevertRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: revertedCommit,
BranchName: []byte(destinationBranch),
@@ -461,7 +466,7 @@ func testServerUserRevertFailedDueToPreReceiveError(t *testing.T, ctxOuter conte
for _, hookName := range GitlabPreHooks {
t.Run(hookName, func(t *testing.T) {
- remove := testhelper.WriteCustomHook(t, testRepoPath, hookName, hookContent)
+ remove := testhelper.WriteCustomHook(t, repoPath, hookName, hookContent)
defer remove()
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
@@ -485,18 +490,19 @@ func testServerUserRevertFailedDueToCreateTreeError(t *testing.T, ctxOuter conte
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
destinationBranch := "revert-dst"
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", destinationBranch, "master")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", destinationBranch, "master")
// This revert patch of the following commit cannot be applied to the destinationBranch above
- revertedCommit, err := log.GetCommit(ctxOuter, git.NewExecCommandFactory(config.Config), testRepo, "372ab6950519549b14d220271ee2322caa44d4eb")
+ revertedCommit, err := repo.ReadCommit(ctxOuter, "372ab6950519549b14d220271ee2322caa44d4eb")
require.NoError(t, err)
request := &gitalypb.UserRevertRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: revertedCommit,
BranchName: []byte(destinationBranch),
@@ -523,19 +529,20 @@ func testServerUserRevertFailedDueToCommitError(t *testing.T, ctxOuter context.C
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
sourceBranch := "revert-src"
destinationBranch := "revert-dst"
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", destinationBranch, "master")
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", sourceBranch, "a5391128b0ef5d21df5dd23d98557f4ef12fae20")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", destinationBranch, "master")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", sourceBranch, "a5391128b0ef5d21df5dd23d98557f4ef12fae20")
- revertedCommit, err := log.GetCommit(ctxOuter, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(sourceBranch))
+ revertedCommit, err := repo.ReadCommit(ctxOuter, git.Revision(sourceBranch))
require.NoError(t, err)
request := &gitalypb.UserRevertRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
Commit: revertedCommit,
BranchName: []byte(destinationBranch),
diff --git a/internal/gitaly/service/operations/squash_test.go b/internal/gitaly/service/operations/squash_test.go
index c8c1f138a..c5a714472 100644
--- a/internal/gitaly/service/operations/squash_test.go
+++ b/internal/gitaly/service/operations/squash_test.go
@@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git"
- "gitlab.com/gitlab-org/gitaly/internal/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
@@ -53,11 +53,12 @@ func testSuccessfulUserSquashRequest(t *testing.T, ctx context.Context, start, e
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanup := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
request := &gitalypb.UserSquashRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
SquashId: "1",
Author: author,
@@ -70,7 +71,7 @@ func testSuccessfulUserSquashRequest(t *testing.T, ctx context.Context, start, e
require.NoError(t, err)
require.Empty(t, response.GetGitError())
- commit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(response.SquashSha))
+ commit, err := repo.ReadCommit(ctx, git.Revision(response.SquashSha))
require.NoError(t, err)
require.Equal(t, []string{start}, commit.ParentIds)
require.Equal(t, author.Name, commit.Author.Name)
@@ -79,7 +80,7 @@ func testSuccessfulUserSquashRequest(t *testing.T, ctx context.Context, start, e
require.Equal(t, testhelper.TestUser.Email, commit.Committer.Email)
require.Equal(t, commitMessage, commit.Subject)
- treeData := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "ls-tree", "--name-only", response.SquashSha)
+ treeData := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "ls-tree", "--name-only", response.SquashSha)
files := strings.Fields(text.ChompBytes(treeData))
require.Subset(t, files, []string{"VERSION", "README", "files", ".gitattributes"}, "ensure the files remain on their places")
}
@@ -91,14 +92,15 @@ func TestUserSquash_stableID(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- repo, _, cleanup := testhelper.NewTestRepo(t)
+ repoProto, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
ctx, cancel := testhelper.Context()
defer cancel()
response, err := client.UserSquash(ctx, &gitalypb.UserSquashRequest{
- Repository: repo,
+ Repository: repoProto,
User: testhelper.TestUser,
SquashId: "1",
Author: author,
@@ -110,7 +112,7 @@ func TestUserSquash_stableID(t *testing.T) {
require.NoError(t, err)
require.Empty(t, response.GetGitError())
- commit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), repo, git.Revision(response.SquashSha))
+ commit, err := repo.ReadCommit(ctx, git.Revision(response.SquashSha))
require.NoError(t, err)
require.Equal(t, &gitalypb.GitCommit{
Id: "2773b7aee7d81ea96d2f48aa080cae08eaae26d5",
@@ -159,11 +161,12 @@ func TestSuccessfulUserSquashRequestWith3wayMerge(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
request := &gitalypb.UserSquashRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
SquashId: "1",
Author: author,
@@ -177,7 +180,7 @@ func TestSuccessfulUserSquashRequestWith3wayMerge(t *testing.T) {
require.NoError(t, err)
require.Empty(t, response.GetGitError())
- commit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(response.SquashSha))
+ commit, err := repo.ReadCommit(ctx, git.Revision(response.SquashSha))
require.NoError(t, err)
require.Equal(t, []string{"6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9"}, commit.ParentIds)
require.Equal(t, author.Name, commit.Author.Name)
@@ -187,16 +190,16 @@ func TestSuccessfulUserSquashRequestWith3wayMerge(t *testing.T) {
require.Equal(t, commitMessage, commit.Subject)
// Handle symlinks in macOS from /tmp -> /private/tmp
- testRepoPath, err = filepath.EvalSymlinks(testRepoPath)
+ repoPath, err = filepath.EvalSymlinks(repoPath)
require.NoError(t, err)
// Ensure Git metadata is cleaned up
- worktreeList := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "worktree", "list", "--porcelain"))
- expectedOut := fmt.Sprintf("worktree %s\nbare\n", testRepoPath)
+ worktreeList := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "worktree", "list", "--porcelain"))
+ expectedOut := fmt.Sprintf("worktree %s\nbare\n", repoPath)
require.Equal(t, expectedOut, worktreeList)
// Ensure actual worktree is removed
- files, err := ioutil.ReadDir(filepath.Join(testRepoPath, "gitlab-worktree"))
+ files, err := ioutil.ReadDir(filepath.Join(repoPath, "gitlab-worktree"))
require.NoError(t, err)
require.Equal(t, 0, len(files))
}
@@ -242,36 +245,37 @@ func TestSquashRequestWithRenamedFiles(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepoWithWorktree(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepoWithWorktree(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
originalFilename := "original-file.txt"
renamedFilename := "renamed-file.txt"
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "config", "testhelper.TestUser.name", string(author.Name))
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "config", "testhelper.TestUser.email", string(author.Email))
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "checkout", "-b", "squash-rename-test", "master")
- require.NoError(t, ioutil.WriteFile(filepath.Join(testRepoPath, originalFilename), []byte("This is a test"), 0644))
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "add", ".")
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "commit", "-m", "test file")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "config", "testhelper.TestUser.name", string(author.Name))
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "config", "testhelper.TestUser.email", string(author.Email))
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "checkout", "-b", "squash-rename-test", "master")
+ require.NoError(t, ioutil.WriteFile(filepath.Join(repoPath, originalFilename), []byte("This is a test"), 0644))
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "add", ".")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "commit", "-m", "test file")
- startCommitID := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "rev-parse", "HEAD"))
+ startCommitID := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "rev-parse", "HEAD"))
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "mv", originalFilename, renamedFilename)
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "commit", "-a", "-m", "renamed test file")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "mv", originalFilename, renamedFilename)
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "commit", "-a", "-m", "renamed test file")
// Modify the original file in another branch
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "checkout", "-b", "squash-rename-branch", startCommitID)
- require.NoError(t, ioutil.WriteFile(filepath.Join(testRepoPath, originalFilename), []byte("This is a change"), 0644))
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "commit", "-a", "-m", "test")
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "checkout", "-b", "squash-rename-branch", startCommitID)
+ require.NoError(t, ioutil.WriteFile(filepath.Join(repoPath, originalFilename), []byte("This is a change"), 0644))
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "commit", "-a", "-m", "test")
- require.NoError(t, ioutil.WriteFile(filepath.Join(testRepoPath, originalFilename), []byte("This is another change"), 0644))
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "commit", "-a", "-m", "test")
+ require.NoError(t, ioutil.WriteFile(filepath.Join(repoPath, originalFilename), []byte("This is another change"), 0644))
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "commit", "-a", "-m", "test")
- endCommitID := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "rev-parse", "HEAD"))
+ endCommitID := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "rev-parse", "HEAD"))
request := &gitalypb.UserSquashRequest{
- Repository: testRepo,
+ Repository: repoProto,
User: testhelper.TestUser,
SquashId: "1",
Author: author,
@@ -284,7 +288,7 @@ func TestSquashRequestWithRenamedFiles(t *testing.T) {
require.NoError(t, err)
require.Empty(t, response.GetGitError())
- commit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(response.SquashSha))
+ commit, err := repo.ReadCommit(ctx, git.Revision(response.SquashSha))
require.NoError(t, err)
require.Equal(t, []string{startCommitID}, commit.ParentIds)
require.Equal(t, author.Name, commit.Author.Name)
diff --git a/internal/gitaly/service/operations/submodules_test.go b/internal/gitaly/service/operations/submodules_test.go
index de8cebd7b..364d658f6 100644
--- a/internal/gitaly/service/operations/submodules_test.go
+++ b/internal/gitaly/service/operations/submodules_test.go
@@ -10,7 +10,6 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
- "gitlab.com/gitlab-org/gitaly/internal/git/log"
"gitlab.com/gitlab-org/gitaly/internal/git/lstree"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag"
@@ -94,7 +93,7 @@ func testSuccessfulUserUpdateSubmoduleRequest(t *testing.T, ctx context.Context)
require.Empty(t, response.GetCommitError())
require.Empty(t, response.GetPreReceiveError())
- commit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepoProto, git.Revision(response.BranchUpdate.CommitId))
+ commit, err := testRepo.ReadCommit(ctx, git.Revision(response.BranchUpdate.CommitId))
require.NoError(t, err)
require.Equal(t, commit.Author.Email, testhelper.TestUser.Email)
require.Equal(t, commit.Committer.Email, testhelper.TestUser.Email)
@@ -123,11 +122,12 @@ func testUserUpdateSubmoduleStableID(t *testing.T, ctx context.Context) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- repo, _, cleanup := testhelper.NewTestRepo(t)
+ repoProto, _, cleanup := testhelper.NewTestRepo(t)
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
response, err := client.UserUpdateSubmodule(ctx, &gitalypb.UserUpdateSubmoduleRequest{
- Repository: repo,
+ Repository: repoProto,
User: testhelper.TestUser,
Submodule: []byte("gitlab-grack"),
CommitSha: "41fa1bc9e0f0630ced6a8a211d60c2af425ecc2d",
@@ -139,7 +139,7 @@ func testUserUpdateSubmoduleStableID(t *testing.T, ctx context.Context) {
require.Empty(t, response.GetCommitError())
require.Empty(t, response.GetPreReceiveError())
- commit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), repo, git.Revision(response.BranchUpdate.CommitId))
+ commit, err := repo.ReadCommit(ctx, git.Revision(response.BranchUpdate.CommitId))
require.NoError(t, err)
require.Equal(t, &gitalypb.GitCommit{
Id: "e7752dfc2105bc830f8fa59b19dd4f3e49c8c44e",
diff --git a/internal/gitaly/service/operations/tags_test.go b/internal/gitaly/service/operations/tags_test.go
index 9cb38b03d..ba5d7a9a1 100644
--- a/internal/gitaly/service/operations/tags_test.go
+++ b/internal/gitaly/service/operations/tags_test.go
@@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/client"
"gitlab.com/gitlab-org/gitaly/internal/git"
- "gitlab.com/gitlab-org/gitaly/internal/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
gitalyhook "gitlab.com/gitlab-org/gitaly/internal/gitaly/hook"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/service/hook"
@@ -183,11 +183,12 @@ func testSuccessfulUserCreateTagRequest(t *testing.T, ctx context.Context) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
targetRevision := "c7fbe50c7c7419d9701eebe64b1fdacc3df5b9dd"
- targetRevisionCommit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(targetRevision))
+ targetRevisionCommit, err := repo.ReadCommit(ctx, git.Revision(targetRevision))
require.NoError(t, err)
inputTagName := "to-be-créated-soon"
@@ -239,12 +240,12 @@ func testSuccessfulUserCreateTagRequest(t *testing.T, ctx context.Context) {
"pre-receive": fmt.Sprintf("#!/bin/sh\n%s %s \"$@\"", preReceiveHook, testCase.expectedObjectType),
"update": fmt.Sprintf("#!/bin/sh\n%s %s \"$@\"", updateHook, testCase.expectedObjectType),
} {
- hookCleanup := testhelper.WriteCustomHook(t, testRepoPath, hook, []byte(content))
+ hookCleanup := testhelper.WriteCustomHook(t, repoPath, hook, []byte(content))
defer hookCleanup()
}
request := &gitalypb.UserCreateTagRequest{
- Repository: testRepo,
+ Repository: repoProto,
TagName: []byte(testCase.tagName),
TargetRevision: []byte(testCase.targetRevision),
User: testhelper.TestUser,
@@ -255,20 +256,20 @@ func testSuccessfulUserCreateTagRequest(t *testing.T, ctx context.Context) {
require.NoError(t, err, "error from calling RPC")
require.Empty(t, response.PreReceiveError, "PreReceiveError must be empty, signalling the push was accepted")
- defer testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "tag", "-d", inputTagName)
+ defer testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "tag", "-d", inputTagName)
responseOk := &gitalypb.UserCreateTagResponse{
Tag: testCase.expectedTag,
}
// Fake up *.Id for annotated tags
if len(testCase.expectedTag.Id) == 0 {
- id := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "rev-parse", inputTagName)
+ id := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "rev-parse", inputTagName)
responseOk.Tag.Id = text.ChompBytes(id)
}
require.Equal(t, responseOk, response)
- tag := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "tag")
+ tag := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "tag")
require.Contains(t, string(tag), inputTagName)
})
}
@@ -278,8 +279,9 @@ func TestUserCreateTagWithTransaction(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
hooksOutputDir, cleanup := testhelper.TempDir(t)
defer cleanup()
@@ -290,7 +292,7 @@ func TestUserCreateTagWithTransaction(t *testing.T) {
// check that the hooks only run on the primary node.
hooks := []string{"pre-receive", "update", "post-receive"}
for _, hook := range hooks {
- testhelper.WriteCustomHook(t, testRepoPath, hook,
+ testhelper.WriteCustomHook(t, repoPath, hook,
[]byte(fmt.Sprintf("#!/bin/sh\necho %s >>%s\n", hook, hooksOutputPath)),
)
}
@@ -369,11 +371,11 @@ func TestUserCreateTagWithTransaction(t *testing.T) {
tagName := fmt.Sprintf("tag-%d", i)
targetRevision := "c7fbe50c7c7419d9701eebe64b1fdacc3df5b9dd"
- targetCommit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(targetRevision))
+ targetCommit, err := repo.ReadCommit(ctx, git.Revision(targetRevision))
require.NoError(t, err)
request := &gitalypb.UserCreateTagRequest{
- Repository: testRepo,
+ Repository: repoProto,
TagName: []byte(tagName),
Message: []byte(testCase.message),
TargetRevision: []byte(targetRevision),
@@ -392,8 +394,8 @@ func TestUserCreateTagWithTransaction(t *testing.T) {
response, err := client.UserCreateTag(ctx, request)
require.NoError(t, err)
- targetOID := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "rev-parse", "refs/tags/"+tagName))
- peeledOID := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "rev-parse", targetOID+"^{commit}"))
+ targetOID := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "rev-parse", "refs/tags/"+tagName))
+ peeledOID := text.ChompBytes(testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "rev-parse", targetOID+"^{commit}"))
targetOIDOK := targetOID
if len(testCase.message) > 0 {
targetOIDOK = peeledOID
@@ -746,8 +748,9 @@ func TestSuccessfulUserCreateTagNestedTags(t *testing.T) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
preReceiveHook, cleanup := writeAssertObjectTypePreReceiveHook(t)
defer cleanup()
@@ -787,7 +790,7 @@ func TestSuccessfulUserCreateTagNestedTags(t *testing.T) {
"pre-receive": fmt.Sprintf("#!/bin/sh\n%s %s \"$@\"", preReceiveHook, hookObjectType),
"update": fmt.Sprintf("#!/bin/sh\n%s %s \"$@\"", updateHook, hookObjectType),
} {
- hookCleanup := testhelper.WriteCustomHook(t, testRepoPath, hook, []byte(content))
+ hookCleanup := testhelper.WriteCustomHook(t, repoPath, hook, []byte(content))
defer hookCleanup()
}
@@ -797,7 +800,7 @@ func TestSuccessfulUserCreateTagNestedTags(t *testing.T) {
tagName := fmt.Sprintf("nested-tag-%v", i)
tagMessage := fmt.Sprintf("This is level %v of a nested annotated tag to %v", i, testCase.targetObject)
request := &gitalypb.UserCreateTagRequest{
- Repository: testRepo,
+ Repository: repoProto,
TagName: []byte(tagName),
TargetRevision: []byte(targetObject),
User: testhelper.TestUser,
@@ -806,9 +809,9 @@ func TestSuccessfulUserCreateTagNestedTags(t *testing.T) {
response, err := client.UserCreateTag(ctx, request)
require.NoError(t, err)
require.Empty(t, response.PreReceiveError)
- defer testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "tag", "-d", tagName)
+ defer testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "tag", "-d", tagName)
- createdID := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "rev-parse", tagName)
+ createdID := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "rev-parse", tagName)
createdIDStr := text.ChompBytes(createdID)
responseOk := &gitalypb.UserCreateTagResponse{
Tag: &gitalypb.Tag{
@@ -822,12 +825,12 @@ func TestSuccessfulUserCreateTagNestedTags(t *testing.T) {
// Fake it up for all levels, except for ^{} == "commit"
responseOk.Tag.TargetCommit = response.Tag.TargetCommit
if testCase.targetObjectType == "commit" {
- responseOk.Tag.TargetCommit, err = log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(testCase.targetObject))
+ responseOk.Tag.TargetCommit, err = repo.ReadCommit(ctx, git.Revision(testCase.targetObject))
require.NoError(t, err)
}
require.Equal(t, responseOk, response)
- peeledID := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "rev-parse", tagName+"^{}")
+ peeledID := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "rev-parse", tagName+"^{}")
peeledIDStr := text.ChompBytes(peeledID)
require.Equal(t, testCase.targetObject, peeledIDStr)
@@ -841,13 +844,13 @@ func TestSuccessfulUserCreateTagNestedTags(t *testing.T) {
// name.
tagNameLight := fmt.Sprintf("skip-type-check-light-%s", tagName)
request = &gitalypb.UserCreateTagRequest{
- Repository: testRepo,
+ Repository: repoProto,
TagName: []byte(tagNameLight),
TargetRevision: []byte(createdIDStr),
User: testhelper.TestUser,
}
response, err = client.UserCreateTag(ctx, request)
- defer testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "tag", "-d", tagNameLight)
+ defer testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "tag", "-d", tagNameLight)
require.NoError(t, err)
require.Empty(t, response.PreReceiveError)
@@ -862,7 +865,7 @@ func TestSuccessfulUserCreateTagNestedTags(t *testing.T) {
}
require.Equal(t, responseOk, response)
- createdIDLight := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "rev-parse", tagNameLight)
+ createdIDLight := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "rev-parse", tagNameLight)
createdIDLightStr := text.ChompBytes(createdIDLight)
require.Equal(t, testCase.targetObject, createdIDLightStr)
}
@@ -962,8 +965,9 @@ func TestUserCreateTagsuccessfulCreationOfPrefixedTag(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
serverSocketPath, stop := runOperationServiceServer(t)
defer stop()
@@ -989,10 +993,10 @@ func TestUserCreateTagsuccessfulCreationOfPrefixedTag(t *testing.T) {
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
- defer testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "tag", "-d", testCase.tagNameInput)
+ defer testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "tag", "-d", testCase.tagNameInput)
request := &gitalypb.UserCreateTagRequest{
- Repository: testRepo,
+ Repository: repoProto,
TagName: []byte(testCase.tagNameInput),
TargetRevision: []byte(testCase.tagTargetRevisionInput),
User: testCase.user,
@@ -1000,7 +1004,7 @@ func TestUserCreateTagsuccessfulCreationOfPrefixedTag(t *testing.T) {
response, err := client.UserCreateTag(ctx, request)
require.Equal(t, testCase.err, err)
- commitOk, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(testCase.tagTargetRevisionInput))
+ commitOk, err := repo.ReadCommit(ctx, git.Revision(testCase.tagTargetRevisionInput))
require.NoError(t, err)
responseOk := &gitalypb.UserCreateTagResponse{
@@ -1013,7 +1017,7 @@ func TestUserCreateTagsuccessfulCreationOfPrefixedTag(t *testing.T) {
require.Equal(t, responseOk, response)
- refs := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "for-each-ref", "--", "refs/tags/"+testCase.tagNameInput)
+ refs := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "for-each-ref", "--", "refs/tags/"+testCase.tagNameInput)
require.Contains(t, string(refs), testCase.tagTargetRevisionInput, "tag created, we did not strip off refs/tags/*")
})
}
diff --git a/internal/gitaly/service/operations/update_branches_test.go b/internal/gitaly/service/operations/update_branches_test.go
index 299739bce..6ffd3cf36 100644
--- a/internal/gitaly/service/operations/update_branches_test.go
+++ b/internal/gitaly/service/operations/update_branches_test.go
@@ -8,7 +8,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git"
- "gitlab.com/gitlab-org/gitaly/internal/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
@@ -31,8 +31,9 @@ func TestSuccessfulUserUpdateBranchRequest(t *testing.T) {
}
func testSuccessfulUserUpdateBranchRequest(t *testing.T, ctx context.Context) {
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
serverSocketPath, stop := runOperationServiceServer(t)
defer stop()
@@ -86,7 +87,7 @@ func testSuccessfulUserUpdateBranchRequest(t *testing.T, ctx context.Context) {
t.Run(testCase.desc, func(t *testing.T) {
responseOk := &gitalypb.UserUpdateBranchResponse{}
request := &gitalypb.UserUpdateBranchRequest{
- Repository: testRepo,
+ Repository: repoProto,
BranchName: []byte(testCase.updateBranchName),
Newrev: testCase.newRev,
Oldrev: testCase.oldRev,
@@ -96,12 +97,12 @@ func testSuccessfulUserUpdateBranchRequest(t *testing.T, ctx context.Context) {
require.NoError(t, err)
require.Equal(t, responseOk, response)
- branchCommit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(testCase.updateBranchName))
+ branchCommit, err := repo.ReadCommit(ctx, git.Revision(testCase.updateBranchName))
require.NoError(t, err)
require.Equal(t, string(testCase.newRev), branchCommit.Id)
- branches := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "for-each-ref", "--", "refs/heads/"+branchName)
+ branches := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "for-each-ref", "--", "refs/heads/"+branchName)
require.Contains(t, string(branches), "refs/heads/"+branchName)
})
}
@@ -118,8 +119,9 @@ func testSuccessfulUserUpdateBranchRequestToDelete(t *testing.T, ctx context.Con
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
testCases := []struct {
desc string
@@ -158,12 +160,12 @@ func testSuccessfulUserUpdateBranchRequestToDelete(t *testing.T, ctx context.Con
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
if testCase.createBranch {
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", "--", testCase.updateBranchName, string(testCase.oldRev))
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", "--", testCase.updateBranchName, string(testCase.oldRev))
}
responseOk := &gitalypb.UserUpdateBranchResponse{}
request := &gitalypb.UserUpdateBranchRequest{
- Repository: testRepo,
+ Repository: repoProto,
BranchName: []byte(testCase.updateBranchName),
Newrev: testCase.newRev,
Oldrev: testCase.oldRev,
@@ -173,10 +175,10 @@ func testSuccessfulUserUpdateBranchRequestToDelete(t *testing.T, ctx context.Con
require.Nil(t, err)
require.Equal(t, responseOk, response)
- _, err = log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(testCase.updateBranchName))
- require.True(t, log.IsNotFound(err), "expected 'not found' error got %v", err)
+ _, err = repo.ReadCommit(ctx, git.Revision(testCase.updateBranchName))
+ require.Equal(t, localrepo.ErrObjectNotFound, err, "expected 'not found' error got %v", err)
- refs := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "for-each-ref", "--", "refs/heads/"+testCase.updateBranchName)
+ refs := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "for-each-ref", "--", "refs/heads/"+testCase.updateBranchName)
require.NotContains(t, string(refs), testCase.oldRev, "branch deleted from refs")
})
}
@@ -273,8 +275,9 @@ func testFailedUserUpdateBranchRequest(t *testing.T, ctx context.Context) {
client, conn := newOperationClient(t, serverSocketPath)
defer conn.Close()
- testRepo, _, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, _, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
revDoesntExist := fmt.Sprintf("%x", sha1.Sum([]byte("we need a non existent sha")))
@@ -389,7 +392,7 @@ func testFailedUserUpdateBranchRequest(t *testing.T, ctx context.Context) {
for _, testCase := range testCases {
t.Run(testCase.desc, func(t *testing.T) {
request := &gitalypb.UserUpdateBranchRequest{
- Repository: testRepo,
+ Repository: repoProto,
BranchName: []byte(testCase.branchName),
Newrev: testCase.newrev,
Oldrev: testCase.oldrev,
@@ -400,9 +403,9 @@ func testFailedUserUpdateBranchRequest(t *testing.T, ctx context.Context) {
require.Equal(t, testCase.response, response)
require.Equal(t, testCase.err, err)
- branchCommit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, git.Revision(testCase.branchName))
+ branchCommit, err := repo.ReadCommit(ctx, git.Revision(testCase.branchName))
if testCase.expectNotFoundError {
- require.True(t, log.IsNotFound(err), "expected 'not found' error got %v", err)
+ require.Equal(t, localrepo.ErrObjectNotFound, err, "expected 'not found' error got %v", err)
return
}
require.NoError(t, err)
diff --git a/internal/gitaly/service/ref/branches_test.go b/internal/gitaly/service/ref/branches_test.go
index 7176e821d..837ec78cd 100644
--- a/internal/gitaly/service/ref/branches_test.go
+++ b/internal/gitaly/service/ref/branches_test.go
@@ -6,7 +6,6 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
- "gitlab.com/gitlab-org/gitaly/internal/git/log"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -40,7 +39,7 @@ func TestSuccessfulFindBranchRequest(t *testing.T) {
err = repo.UpdateRef(ctx, branchName, oid, "")
require.NoError(t, err)
- commit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepoProto, branchName.Revision())
+ commit, err := repo.ReadCommit(ctx, branchName.Revision())
require.NoError(t, err)
branchesByName[branchName] = &gitalypb.Branch{
diff --git a/internal/gitaly/service/ref/refs_test.go b/internal/gitaly/service/ref/refs_test.go
index d52db72ac..b8ab9f815 100644
--- a/internal/gitaly/service/ref/refs_test.go
+++ b/internal/gitaly/service/ref/refs_test.go
@@ -15,6 +15,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/catfile"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/git/log"
"gitlab.com/gitlab-org/gitaly/internal/git/updateref"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
@@ -480,17 +481,18 @@ func TestSuccessfulFindAllTagsRequest(t *testing.T) {
stop, serverSocketPath := runRefServiceServer(t)
defer stop()
- testRepoCopy, testRepoCopyPath, cleanupFn := testhelper.NewTestRepoWithWorktree(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepoWithWorktree(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
// reconstruct the v1.1.2 tag from patches to test truncated tag message
// with partial PGP block
truncatedPGPTagMsg, err := ioutil.ReadFile("testdata/truncated_pgp_msg.patch")
require.NoError(t, err)
- truncatedPGPTagID := string(testhelper.MustRunCommand(t, bytes.NewBuffer(truncatedPGPTagMsg), "git", "-C", testRepoCopyPath, "mktag"))
+ truncatedPGPTagID := string(testhelper.MustRunCommand(t, bytes.NewBuffer(truncatedPGPTagMsg), "git", "-C", repoPath, "mktag"))
truncatedPGPTagID = strings.TrimSpace(truncatedPGPTagID) // remove trailing newline
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoCopyPath, "update-ref", "refs/tags/pgp-long-tag-message", truncatedPGPTagID)
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "update-ref", "refs/tags/pgp-long-tag-message", truncatedPGPTagID)
blobID := "faaf198af3a36dbf41961466703cc1d47c61d051"
commitID := "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9"
@@ -500,38 +502,38 @@ func TestSuccessfulFindAllTagsRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- bigCommitID := testhelper.CreateCommit(t, testRepoCopyPath, "local-big-commits", &testhelper.CreateCommitOpts{
+ bigCommitID := testhelper.CreateCommit(t, repoPath, "local-big-commits", &testhelper.CreateCommitOpts{
Message: "An empty commit with REALLY BIG message\n\n" + strings.Repeat("a", helper.MaxCommitOrTagMessageSize+1),
ParentID: "60ecb67744cb56576c30214ff52294f8ce2def98",
})
- bigCommit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepoCopy, git.Revision(bigCommitID))
+ bigCommit, err := repo.ReadCommit(ctx, git.Revision(bigCommitID))
require.NoError(t, err)
- annotatedTagID := testhelper.CreateTag(t, testRepoCopyPath, "v1.2.0", blobID, &testhelper.CreateTagOpts{Message: "Blob tag"})
+ annotatedTagID := testhelper.CreateTag(t, repoPath, "v1.2.0", blobID, &testhelper.CreateTagOpts{Message: "Blob tag"})
- testhelper.CreateTag(t, testRepoCopyPath, "v1.3.0", commitID, nil)
- testhelper.CreateTag(t, testRepoCopyPath, "v1.4.0", blobID, nil)
+ testhelper.CreateTag(t, repoPath, "v1.3.0", commitID, nil)
+ testhelper.CreateTag(t, repoPath, "v1.4.0", blobID, nil)
// To test recursive resolving to a commit
- testhelper.CreateTag(t, testRepoCopyPath, "v1.5.0", "v1.3.0", nil)
+ testhelper.CreateTag(t, repoPath, "v1.5.0", "v1.3.0", nil)
// A tag to commit with a big message
- testhelper.CreateTag(t, testRepoCopyPath, "v1.6.0", bigCommitID, nil)
+ testhelper.CreateTag(t, repoPath, "v1.6.0", bigCommitID, nil)
// A tag with a big message
bigMessage := strings.Repeat("a", 11*1024)
- bigMessageTag1ID := testhelper.CreateTag(t, testRepoCopyPath, "v1.7.0", commitID, &testhelper.CreateTagOpts{Message: bigMessage})
+ bigMessageTag1ID := testhelper.CreateTag(t, repoPath, "v1.7.0", commitID, &testhelper.CreateTagOpts{Message: bigMessage})
// A tag with a commit id as its name
- commitTagID := testhelper.CreateTag(t, testRepoCopyPath, commitID, commitID, &testhelper.CreateTagOpts{Message: "commit tag with a commit sha as the name"})
+ commitTagID := testhelper.CreateTag(t, repoPath, commitID, commitID, &testhelper.CreateTagOpts{Message: "commit tag with a commit sha as the name"})
// a tag of a tag
- tagOfTagID := testhelper.CreateTag(t, testRepoCopyPath, "tag-of-tag", commitTagID, &testhelper.CreateTagOpts{Message: "tag of a tag"})
+ tagOfTagID := testhelper.CreateTag(t, repoPath, "tag-of-tag", commitTagID, &testhelper.CreateTagOpts{Message: "tag of a tag"})
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
- rpcRequest := &gitalypb.FindAllTagsRequest{Repository: testRepoCopy}
+ rpcRequest := &gitalypb.FindAllTagsRequest{Repository: repoProto}
c, err := client.FindAllTags(ctx, rpcRequest)
require.NoError(t, err)
@@ -1117,8 +1119,9 @@ func TestSuccessfulFindAllBranchesRequestWithMergedBranches(t *testing.T) {
stop, serverSocketPath := runRefServiceServer(t)
defer stop()
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -1126,13 +1129,13 @@ func TestSuccessfulFindAllBranchesRequestWithMergedBranches(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- localRefs := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "for-each-ref", "--format=%(refname:strip=2)", "refs/heads")
+ localRefs := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "for-each-ref", "--format=%(refname:strip=2)", "refs/heads")
for _, ref := range strings.Split(string(localRefs), "\n") {
ref = strings.TrimSpace(ref)
if _, ok := localBranches["refs/heads/"+ref]; ok || ref == "master" || ref == "" {
continue
}
- testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "branch", "-D", ref)
+ testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "branch", "-D", ref)
}
expectedRefs := []string{"refs/heads/100%branch", "refs/heads/improve/awesome", "refs/heads/'test'"}
@@ -1149,7 +1152,7 @@ func TestSuccessfulFindAllBranchesRequestWithMergedBranches(t *testing.T) {
expectedBranches = append(expectedBranches, branch)
}
- masterCommit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepo, "master")
+ masterCommit, err := repo.ReadCommit(ctx, "master")
require.NoError(t, err)
expectedBranches = append(expectedBranches, &gitalypb.FindAllBranchesResponse_Branch{
Name: []byte("refs/heads/master"),
@@ -1164,7 +1167,7 @@ func TestSuccessfulFindAllBranchesRequestWithMergedBranches(t *testing.T) {
{
desc: "all merged branches",
request: &gitalypb.FindAllBranchesRequest{
- Repository: testRepo,
+ Repository: repoProto,
MergedOnly: true,
},
expectedBranches: expectedBranches,
@@ -1172,7 +1175,7 @@ func TestSuccessfulFindAllBranchesRequestWithMergedBranches(t *testing.T) {
{
desc: "all merged from a list of branches",
request: &gitalypb.FindAllBranchesRequest{
- Repository: testRepo,
+ Repository: repoProto,
MergedOnly: true,
MergedBranches: [][]byte{
[]byte("refs/heads/100%branch"),
@@ -1439,8 +1442,9 @@ func TestSuccessfulFindTagRequest(t *testing.T) {
stop, serverSocketPath := runRefServiceServer(t)
defer stop()
- testRepoCopy, testRepoCopyPath, cleanupFn := testhelper.NewTestRepoWithWorktree(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepoWithWorktree(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
blobID := "faaf198af3a36dbf41961466703cc1d47c61d051"
commitID := "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9"
@@ -1450,33 +1454,33 @@ func TestSuccessfulFindTagRequest(t *testing.T) {
ctx, cancel := testhelper.Context()
defer cancel()
- bigCommitID := testhelper.CreateCommit(t, testRepoCopyPath, "local-big-commits", &testhelper.CreateCommitOpts{
+ bigCommitID := testhelper.CreateCommit(t, repoPath, "local-big-commits", &testhelper.CreateCommitOpts{
Message: "An empty commit with REALLY BIG message\n\n" + strings.Repeat("a", helper.MaxCommitOrTagMessageSize+1),
ParentID: "60ecb67744cb56576c30214ff52294f8ce2def98",
})
- bigCommit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), testRepoCopy, git.Revision(bigCommitID))
+ bigCommit, err := repo.ReadCommit(ctx, git.Revision(bigCommitID))
require.NoError(t, err)
- annotatedTagID := testhelper.CreateTag(t, testRepoCopyPath, "v1.2.0", blobID, &testhelper.CreateTagOpts{Message: "Blob tag"})
+ annotatedTagID := testhelper.CreateTag(t, repoPath, "v1.2.0", blobID, &testhelper.CreateTagOpts{Message: "Blob tag"})
- testhelper.CreateTag(t, testRepoCopyPath, "v1.3.0", commitID, nil)
- testhelper.CreateTag(t, testRepoCopyPath, "v1.4.0", blobID, nil)
+ testhelper.CreateTag(t, repoPath, "v1.3.0", commitID, nil)
+ testhelper.CreateTag(t, repoPath, "v1.4.0", blobID, nil)
// To test recursive resolving to a commit
- testhelper.CreateTag(t, testRepoCopyPath, "v1.5.0", "v1.3.0", nil)
+ testhelper.CreateTag(t, repoPath, "v1.5.0", "v1.3.0", nil)
// A tag to commit with a big message
- testhelper.CreateTag(t, testRepoCopyPath, "v1.6.0", bigCommitID, nil)
+ testhelper.CreateTag(t, repoPath, "v1.6.0", bigCommitID, nil)
// A tag with a big message
bigMessage := strings.Repeat("a", 11*1024)
- bigMessageTag1ID := testhelper.CreateTag(t, testRepoCopyPath, "v1.7.0", commitID, &testhelper.CreateTagOpts{Message: bigMessage})
+ bigMessageTag1ID := testhelper.CreateTag(t, repoPath, "v1.7.0", commitID, &testhelper.CreateTagOpts{Message: bigMessage})
// A tag with a commit id as its name
- commitTagID := testhelper.CreateTag(t, testRepoCopyPath, commitID, commitID, &testhelper.CreateTagOpts{Message: "commit tag with a commit sha as the name"})
+ commitTagID := testhelper.CreateTag(t, repoPath, commitID, commitID, &testhelper.CreateTagOpts{Message: "commit tag with a commit sha as the name"})
// a tag of a tag
- tagOfTagID := testhelper.CreateTag(t, testRepoCopyPath, "tag-of-tag", commitTagID, &testhelper.CreateTagOpts{Message: "tag of a tag"})
+ tagOfTagID := testhelper.CreateTag(t, repoPath, "tag-of-tag", commitTagID, &testhelper.CreateTagOpts{Message: "tag of a tag"})
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
@@ -1596,7 +1600,7 @@ func TestSuccessfulFindTagRequest(t *testing.T) {
}
for _, expectedTag := range expectedTags {
- rpcRequest := &gitalypb.FindTagRequest{Repository: testRepoCopy, TagName: expectedTag.Name}
+ rpcRequest := &gitalypb.FindTagRequest{Repository: repoProto, TagName: expectedTag.Name}
resp, err := client.FindTag(ctx, rpcRequest)
require.NoError(t, err)
diff --git a/internal/gitaly/service/ref/remote_branches_test.go b/internal/gitaly/service/ref/remote_branches_test.go
index 88ed92469..bace51186 100644
--- a/internal/gitaly/service/ref/remote_branches_test.go
+++ b/internal/gitaly/service/ref/remote_branches_test.go
@@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git"
- "gitlab.com/gitlab-org/gitaly/internal/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -23,8 +23,9 @@ func TestSuccessfulFindAllRemoteBranchesRequest(t *testing.T) {
client, conn := newRefServiceClient(t, serverSocketPath)
defer conn.Close()
- testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ repoProto, repoPath, cleanupFn := testhelper.NewTestRepo(t)
defer cleanupFn()
+ repo := localrepo.New(repoProto, config.Config)
remoteName := "my-remote"
expectedBranches := map[string]string{
@@ -37,14 +38,14 @@ func TestSuccessfulFindAllRemoteBranchesRequest(t *testing.T) {
}
for branchName, commitID := range expectedBranches {
- testhelper.CreateRemoteBranch(t, testRepoPath, remoteName, branchName, commitID)
+ testhelper.CreateRemoteBranch(t, repoPath, remoteName, branchName, commitID)
}
for branchName, commitID := range excludedBranches {
- testhelper.CreateRemoteBranch(t, testRepoPath, excludedRemote, branchName, commitID)
+ testhelper.CreateRemoteBranch(t, repoPath, excludedRemote, branchName, commitID)
}
- request := &gitalypb.FindAllRemoteBranchesRequest{Repository: testRepo, RemoteName: remoteName}
+ request := &gitalypb.FindAllRemoteBranchesRequest{Repository: repoProto, RemoteName: remoteName}
c, err := client.FindAllRemoteBranches(ctx, request)
if err != nil {
@@ -54,9 +55,8 @@ func TestSuccessfulFindAllRemoteBranchesRequest(t *testing.T) {
branches := readFindAllRemoteBranchesResponsesFromClient(t, c)
require.Len(t, branches, len(expectedBranches))
- gitCmdFactory := git.NewExecCommandFactory(config.Config)
for branchName, commitID := range expectedBranches {
- targetCommit, err := log.GetCommit(ctx, gitCmdFactory, testRepo, git.Revision(commitID))
+ targetCommit, err := repo.ReadCommit(ctx, git.Revision(commitID))
require.NoError(t, err)
expectedBranch := &gitalypb.Branch{
@@ -68,7 +68,7 @@ func TestSuccessfulFindAllRemoteBranchesRequest(t *testing.T) {
}
for branchName, commitID := range excludedBranches {
- targetCommit, err := log.GetCommit(ctx, gitCmdFactory, testRepo, git.Revision(commitID))
+ targetCommit, err := repo.ReadCommit(ctx, git.Revision(commitID))
require.NoError(t, err)
excludedBranch := &gitalypb.Branch{
diff --git a/internal/gitaly/service/repository/create_from_bundle_test.go b/internal/gitaly/service/repository/create_from_bundle_test.go
index 22e327ffd..05228923d 100644
--- a/internal/gitaly/service/repository/create_from_bundle_test.go
+++ b/internal/gitaly/service/repository/create_from_bundle_test.go
@@ -9,8 +9,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
- "gitlab.com/gitlab-org/gitaly/internal/git"
- "gitlab.com/gitlab-org/gitaly/internal/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/tempdir"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
@@ -45,15 +44,16 @@ func TestServer_CreateRepositoryFromBundle_successful(t *testing.T) {
stream, err := client.CreateRepositoryFromBundle(ctx)
require.NoError(t, err)
- importedRepo := &gitalypb.Repository{
+ importedRepoProto := &gitalypb.Repository{
StorageName: testhelper.DefaultStorageName,
RelativePath: "a-repo-from-bundle",
}
- importedRepoPath, err := locator.GetPath(importedRepo)
+ importedRepo := localrepo.New(importedRepoProto, config.Config)
+ importedRepoPath, err := locator.GetPath(importedRepoProto)
require.NoError(t, err)
defer os.RemoveAll(importedRepoPath)
- request := &gitalypb.CreateRepositoryFromBundleRequest{Repository: importedRepo}
+ request := &gitalypb.CreateRepositoryFromBundleRequest{Repository: importedRepoProto}
writer := streamio.NewWriter(func(p []byte) error {
request.Data = p
@@ -82,7 +82,7 @@ func TestServer_CreateRepositoryFromBundle_successful(t *testing.T) {
require.NoError(t, err)
require.NotEqual(t, 0, info.Mode()&os.ModeSymlink)
- commit, err := log.GetCommit(ctx, git.NewExecCommandFactory(config.Config), importedRepo, "refs/custom-refs/ref1")
+ commit, err := importedRepo.ReadCommit(ctx, "refs/custom-refs/ref1")
require.NoError(t, err)
require.NotNil(t, commit)
}
diff --git a/internal/gitaly/service/repository/fetch_test.go b/internal/gitaly/service/repository/fetch_test.go
index 337311d57..498111e7b 100644
--- a/internal/gitaly/service/repository/fetch_test.go
+++ b/internal/gitaly/service/repository/fetch_test.go
@@ -7,7 +7,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/client"
"gitlab.com/gitlab-org/gitaly/internal/git"
- gitLog "gitlab.com/gitlab-org/gitaly/internal/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/hook"
serverPkg "gitlab.com/gitlab-org/gitaly/internal/gitaly/server"
@@ -38,8 +38,9 @@ func TestFetchSourceBranchSourceRepositorySuccess(t *testing.T) {
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
ctx = testhelper.MergeOutgoingMetadata(ctx, md)
- targetRepo, _, cleanup := newTestRepo(t, locator, "fetch-source-target.git")
+ targetRepoProto, _, cleanup := newTestRepo(t, locator, "fetch-source-target.git")
defer cleanup()
+ targetRepo := localrepo.New(targetRepoProto, config.Config)
sourceRepo, sourcePath, cleanup := newTestRepo(t, locator, "fetch-source-source.git")
defer cleanup()
@@ -49,7 +50,7 @@ func TestFetchSourceBranchSourceRepositorySuccess(t *testing.T) {
targetRef := "refs/tmp/fetch-source-branch-test"
req := &gitalypb.FetchSourceBranchRequest{
- Repository: targetRepo,
+ Repository: targetRepoProto,
SourceRepository: sourceRepo,
SourceBranch: []byte(sourceBranch),
TargetRef: []byte(targetRef),
@@ -59,7 +60,7 @@ func TestFetchSourceBranchSourceRepositorySuccess(t *testing.T) {
require.NoError(t, err)
require.True(t, resp.Result, "response.Result should be true")
- fetchedCommit, err := gitLog.GetCommit(ctx, git.NewExecCommandFactory(config.Config), targetRepo, git.Revision(targetRef))
+ fetchedCommit, err := targetRepo.ReadCommit(ctx, git.Revision(targetRef))
require.NoError(t, err)
require.Equal(t, newCommitID, fetchedCommit.GetId())
}
@@ -79,16 +80,17 @@ func TestFetchSourceBranchSameRepositorySuccess(t *testing.T) {
md := testhelper.GitalyServersMetadata(t, serverSocketPath)
ctx = testhelper.MergeOutgoingMetadata(ctx, md)
- repo, repoPath, cleanup := newTestRepo(t, locator, "fetch-source-source.git")
+ repoProto, repoPath, cleanup := newTestRepo(t, locator, "fetch-source-source.git")
defer cleanup()
+ repo := localrepo.New(repoProto, config.Config)
sourceBranch := "fetch-source-branch-test-branch"
newCommitID := testhelper.CreateCommit(t, repoPath, sourceBranch, nil)
targetRef := "refs/tmp/fetch-source-branch-test"
req := &gitalypb.FetchSourceBranchRequest{
- Repository: repo,
- SourceRepository: repo,
+ Repository: repoProto,
+ SourceRepository: repoProto,
SourceBranch: []byte(sourceBranch),
TargetRef: []byte(targetRef),
}
@@ -97,7 +99,7 @@ func TestFetchSourceBranchSameRepositorySuccess(t *testing.T) {
require.NoError(t, err)
require.True(t, resp.Result, "response.Result should be true")
- fetchedCommit, err := gitLog.GetCommit(ctx, git.NewExecCommandFactory(config.Config), repo, git.Revision(targetRef))
+ fetchedCommit, err := repo.ReadCommit(ctx, git.Revision(targetRef))
require.NoError(t, err)
require.Equal(t, newCommitID, fetchedCommit.GetId())
}
diff --git a/internal/gitaly/service/wiki/delete_page_test.go b/internal/gitaly/service/wiki/delete_page_test.go
index cc3bad0ed..93a348d7c 100644
--- a/internal/gitaly/service/wiki/delete_page_test.go
+++ b/internal/gitaly/service/wiki/delete_page_test.go
@@ -5,7 +5,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git"
- gitlog "gitlab.com/gitlab-org/gitaly/internal/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -13,8 +13,9 @@ import (
)
func TestSuccessfulWikiDeletePageRequest(t *testing.T) {
- wikiRepo, wikiRepoPath, cleanupFunc := setupWikiRepo(t)
+ wikiRepoProto, wikiRepoPath, cleanupFunc := setupWikiRepo(t)
defer cleanupFunc()
+ wikiRepo := localrepo.New(wikiRepoProto, config.Config)
ctx, cancel := testhelper.Context()
defer cancel()
@@ -41,7 +42,7 @@ func TestSuccessfulWikiDeletePageRequest(t *testing.T) {
{
desc: "with user id and username",
req: &gitalypb.WikiDeletePageRequest{
- Repository: wikiRepo,
+ Repository: wikiRepoProto,
PagePath: []byte("a-talé-of-two-wikis"),
CommitDetails: &gitalypb.WikiCommitDetails{
Name: authorName,
@@ -55,7 +56,7 @@ func TestSuccessfulWikiDeletePageRequest(t *testing.T) {
{
desc: "without user id and username", // deprecate in GitLab 11.0 https://gitlab.com/gitlab-org/gitaly/issues/1154
req: &gitalypb.WikiDeletePageRequest{
- Repository: wikiRepo,
+ Repository: wikiRepoProto,
PagePath: []byte("a-talé-of-two-wikis"),
CommitDetails: &gitalypb.WikiCommitDetails{
Name: authorName,
@@ -68,13 +69,13 @@ func TestSuccessfulWikiDeletePageRequest(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
- writeWikiPage(t, client, wikiRepo, createWikiPageOpts{title: pageName, content: content})
+ writeWikiPage(t, client, wikiRepoProto, createWikiPageOpts{title: pageName, content: content})
_, err := client.WikiDeletePage(ctx, tc.req)
require.NoError(t, err)
headID := testhelper.MustRunCommand(t, nil, "git", "-C", wikiRepoPath, "show", "--format=format:%H", "--no-patch", "HEAD")
- commit, err := gitlog.GetCommit(ctx, git.NewExecCommandFactory(config.Config), wikiRepo, git.Revision(headID))
+ commit, err := wikiRepo.ReadCommit(ctx, git.Revision(headID))
require.NoError(t, err, "look up git commit after deleting a wiki page")
require.Equal(t, authorName, commit.Author.Name, "author name mismatched")
diff --git a/internal/gitaly/service/wiki/testhelper_test.go b/internal/gitaly/service/wiki/testhelper_test.go
index 77943293d..22728debb 100644
--- a/internal/gitaly/service/wiki/testhelper_test.go
+++ b/internal/gitaly/service/wiki/testhelper_test.go
@@ -12,7 +12,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/hooks"
- gitlog "gitlab.com/gitlab-org/gitaly/internal/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/rubyserver"
"gitlab.com/gitlab-org/gitaly/internal/storage"
@@ -190,15 +190,17 @@ func sendBytes(data []byte, chunkSize int, sender func([]byte) error) (int, erro
return i, nil
}
-func createTestWikiPage(t *testing.T, locator storage.Locator, client gitalypb.WikiServiceClient, wikiRepo *gitalypb.Repository, opts createWikiPageOpts) *gitalypb.GitCommit {
+func createTestWikiPage(t *testing.T, locator storage.Locator, client gitalypb.WikiServiceClient, wikiRepoProto *gitalypb.Repository, opts createWikiPageOpts) *gitalypb.GitCommit {
ctx, cancel := testhelper.Context()
defer cancel()
- wikiRepoPath, err := locator.GetRepoPath(wikiRepo)
+ wikiRepoPath, err := locator.GetRepoPath(wikiRepoProto)
require.NoError(t, err)
- writeWikiPage(t, client, wikiRepo, opts)
+ writeWikiPage(t, client, wikiRepoProto, opts)
head1ID := testhelper.MustRunCommand(t, nil, "git", "-C", wikiRepoPath, "show", "--format=format:%H", "--no-patch", "HEAD")
- pageCommit, err := gitlog.GetCommit(ctx, git.NewExecCommandFactory(config.Config), wikiRepo, git.Revision(head1ID))
+
+ wikiRepo := localrepo.New(wikiRepoProto, config.Config)
+ pageCommit, err := wikiRepo.ReadCommit(ctx, git.Revision(head1ID))
require.NoError(t, err, "look up git commit after writing a wiki page")
return pageCommit
diff --git a/internal/gitaly/service/wiki/update_page_test.go b/internal/gitaly/service/wiki/update_page_test.go
index 6381b3aa4..46071a671 100644
--- a/internal/gitaly/service/wiki/update_page_test.go
+++ b/internal/gitaly/service/wiki/update_page_test.go
@@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git"
- gitlog "gitlab.com/gitlab-org/gitaly/internal/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -14,8 +14,9 @@ import (
)
func TestSuccessfulWikiUpdatePageRequest(t *testing.T) {
- wikiRepo, wikiRepoPath, cleanupFunc := setupWikiRepo(t)
+ wikiRepoProto, wikiRepoPath, cleanupFunc := setupWikiRepo(t)
defer cleanupFunc()
+ wikiRepo := localrepo.New(wikiRepoProto, config.Config)
ctx, cancel := testhelper.Context()
defer cancel()
@@ -27,7 +28,7 @@ func TestSuccessfulWikiUpdatePageRequest(t *testing.T) {
client, conn := newWikiClient(t, serverSocketPath)
defer conn.Close()
- writeWikiPage(t, client, wikiRepo, createWikiPageOpts{title: "Instálling Gitaly", content: []byte("foobar")})
+ writeWikiPage(t, client, wikiRepoProto, createWikiPageOpts{title: "Instálling Gitaly", content: []byte("foobar")})
authorID := int32(1)
authorUserName := []byte("ahmad")
@@ -43,7 +44,7 @@ func TestSuccessfulWikiUpdatePageRequest(t *testing.T) {
{
desc: "with user id and username",
req: &gitalypb.WikiUpdatePageRequest{
- Repository: wikiRepo,
+ Repository: wikiRepoProto,
PagePath: []byte("//Instálling Gitaly"),
Title: []byte("Instálling Gitaly"),
Format: "markdown",
@@ -60,7 +61,7 @@ func TestSuccessfulWikiUpdatePageRequest(t *testing.T) {
{
desc: "without user id and username", // deprecate in gitlab 11.0 https://gitlab.com/gitlab-org/gitaly/issues/1154
req: &gitalypb.WikiUpdatePageRequest{
- Repository: wikiRepo,
+ Repository: wikiRepoProto,
PagePath: []byte("//Instálling Gitaly"),
Title: []byte("Instálling Gitaly"),
Format: "markdown",
@@ -100,7 +101,7 @@ func TestSuccessfulWikiUpdatePageRequest(t *testing.T) {
require.NoError(t, err)
headID := testhelper.MustRunCommand(t, nil, "git", "-C", wikiRepoPath, "show", "--format=format:%H", "--no-patch", "HEAD")
- commit, err := gitlog.GetCommit(ctx, git.NewExecCommandFactory(config.Config), wikiRepo, git.Revision(headID))
+ commit, err := wikiRepo.ReadCommit(ctx, git.Revision(headID))
require.NoError(t, err, "look up git commit before merge is applied")
require.Equal(t, authorName, commit.Author.Name, "author name mismatched")
diff --git a/internal/gitaly/service/wiki/write_page_test.go b/internal/gitaly/service/wiki/write_page_test.go
index d62e6b8d1..7ae0cbbbd 100644
--- a/internal/gitaly/service/wiki/write_page_test.go
+++ b/internal/gitaly/service/wiki/write_page_test.go
@@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/require"
"gitlab.com/gitlab-org/gitaly/internal/git"
- gitlog "gitlab.com/gitlab-org/gitaly/internal/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/localrepo"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
@@ -14,8 +14,9 @@ import (
)
func TestSuccessfulWikiWritePageRequest(t *testing.T) {
- wikiRepo, wikiRepoPath, cleanupFunc := setupWikiRepo(t)
+ wikiRepoProto, wikiRepoPath, cleanupFunc := setupWikiRepo(t)
defer cleanupFunc()
+ wikiRepo := localrepo.New(wikiRepoProto, config.Config)
ctx, cancel := testhelper.Context()
defer cancel()
@@ -42,7 +43,7 @@ func TestSuccessfulWikiWritePageRequest(t *testing.T) {
{
desc: "with user id and username",
req: &gitalypb.WikiWritePageRequest{
- Repository: wikiRepo,
+ Repository: wikiRepoProto,
Name: []byte("Instálling Gitaly"),
Format: "markdown",
CommitDetails: &gitalypb.WikiCommitDetails{
@@ -59,7 +60,7 @@ func TestSuccessfulWikiWritePageRequest(t *testing.T) {
{
desc: "without user id and username", // deprecate in gitlab 11.0 https://gitlab.com/gitlab-org/gitaly/issues/1154
req: &gitalypb.WikiWritePageRequest{
- Repository: wikiRepo,
+ Repository: wikiRepoProto,
Name: []byte("Instálling Gitaly 2"),
Format: "markdown",
CommitDetails: &gitalypb.WikiCommitDetails{
@@ -103,7 +104,7 @@ func TestSuccessfulWikiWritePageRequest(t *testing.T) {
require.Empty(t, resp.DuplicateError, "DuplicateError must be empty")
headID := testhelper.MustRunCommand(t, nil, "git", "-C", wikiRepoPath, "show", "--format=format:%H", "--no-patch", "HEAD")
- commit, err := gitlog.GetCommit(ctx, git.NewExecCommandFactory(config.Config), wikiRepo, git.Revision(headID))
+ commit, err := wikiRepo.ReadCommit(ctx, git.Revision(headID))
require.NoError(t, err, "look up git commit after writing a wiki page")
require.Equal(t, authorName, commit.Author.Name, "author name mismatched")