diff options
author | Jacob Vosmaer <jacob@gitlab.com> | 2018-10-24 17:47:01 +0300 |
---|---|---|
committer | Jacob Vosmaer <jacob@gitlab.com> | 2018-10-24 17:47:01 +0300 |
commit | f8b5523be70444a7f6f3045719bee2c5b79d160d (patch) | |
tree | 0d943bd5d639dcd146d670b1f33453cb19019c78 | |
parent | 9001a0fd6f21966c7fa4cd0d00085a4faa86ba1f (diff) | |
parent | df0ac9353e33b0fca40470a16d4a416a4a5bb68b (diff) |
Merge branch 'zj-repack-full-local' into 'master'
Repack full uses --local option
Closes #1350
See merge request gitlab-org/gitaly!931
-rw-r--r-- | internal/service/repository/repack.go | 2 | ||||
-rw-r--r-- | internal/service/repository/repack_test.go | 40 | ||||
-rw-r--r-- | internal/testhelper/commit.go | 1 |
3 files changed, 41 insertions, 2 deletions
diff --git a/internal/service/repository/repack.go b/internal/service/repository/repack.go index 3f031c0be..265ecadcd 100644 --- a/internal/service/repository/repack.go +++ b/internal/service/repository/repack.go @@ -11,7 +11,7 @@ import ( ) func (server) RepackFull(ctx context.Context, in *gitalypb.RepackFullRequest) (*gitalypb.RepackFullResponse, error) { - if err := repackCommand(ctx, "RepackFull", in.GetRepository(), in.GetCreateBitmap(), "-A", "--pack-kept-objects"); err != nil { + if err := repackCommand(ctx, "RepackFull", in.GetRepository(), in.GetCreateBitmap(), "-A", "--pack-kept-objects", "-l"); err != nil { return nil, err } return &gitalypb.RepackFullResponse{}, nil diff --git a/internal/service/repository/repack_test.go b/internal/service/repository/repack_test.go index b825aa6e6..0c9861f1f 100644 --- a/internal/service/repository/repack_test.go +++ b/internal/service/repository/repack_test.go @@ -2,12 +2,14 @@ package repository import ( "context" + "os/exec" "path" "path/filepath" "testing" "time" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/gitaly-proto/go/gitalypb" "gitlab.com/gitlab-org/gitaly/internal/testhelper" "google.golang.org/grpc/codes" @@ -40,6 +42,44 @@ func TestRepackIncrementalSuccess(t *testing.T) { assertModTimeAfter(t, testTime, packPath) } +func TestRepackLocal(t *testing.T) { + server, serverSocketPath := runRepoServer(t) + defer server.Stop() + + client, conn := newRepositoryClient(t, serverSocketPath) + defer conn.Close() + + testRepo, repoPath, cleanupFn := testhelper.NewTestRepoWithWorktree(t) + defer cleanupFn() + + commiterArgs := []string{"-c", "user.name=Scrooge McDuck", "-c", "user.email=scrooge@mcduck.com"} + cmdArgs := append(commiterArgs, "-C", repoPath, "commit", "--allow-empty", "-m", "An empty commit") + cmd := exec.Command("git", cmdArgs...) + altDirsCommit, altObjectsDir := testhelper.CreateCommitInAlternateObjectDirectory(t, repoPath, cmd) + + repoCommit := testhelper.CreateCommit(t, repoPath, t.Name(), &testhelper.CreateCommitOpts{Message: t.Name()}) + + ctx, cancelFn := testhelper.Context() + defer cancelFn() + + // Set GIT_ALTERNATE_OBJECT_DIRECTORIES on the outgoing request. The + // intended use case of the behavior we're testing here is that + // alternates are found through the objects/info/alternates file instead + // of GIT_ALTERNATE_OBJECT_DIRECTORIES. But for the purpose of this test + // it doesn't matter. + testRepo.GitAlternateObjectDirectories = []string{altObjectsDir} + _, err := client.RepackFull(ctx, &gitalypb.RepackFullRequest{Repository: testRepo}) + require.NoError(t, err) + + packFiles, err := filepath.Glob(path.Join(repoPath, ".git", "objects", "pack", "pack-*.pack")) + require.NoError(t, err) + require.Len(t, packFiles, 1) + + packContents := testhelper.MustRunCommand(t, nil, "git", "-C", repoPath, "verify-pack", "-v", packFiles[0]) + require.NotContains(t, string(packContents), string(altDirsCommit)) + require.Contains(t, string(packContents), string(repoCommit)) +} + func TestRepackIncrementalFailure(t *testing.T) { server, serverSocketPath := runRepoServer(t) defer server.Stop() diff --git a/internal/testhelper/commit.go b/internal/testhelper/commit.go index eb139438d..bee4e3e51 100644 --- a/internal/testhelper/commit.go +++ b/internal/testhelper/commit.go @@ -18,7 +18,6 @@ type CreateCommitOpts struct { // CreateCommit makes a new empty commit and updates the named branch to point to it. func CreateCommit(t *testing.T, repoPath, branchName string, opts *CreateCommitOpts) string { - message := "message" // The ID of an arbitrary commit known to exist in the test repository. parentID := "1a0b36b3cdad1d2ee32457c102a8c0b7056fa863" |