diff options
author | LI Zhennan <znli@jihulab.com> | 2022-03-15 00:30:05 +0300 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2022-03-15 00:30:05 +0300 |
commit | 7209dff05de90b79d89d8cf3fa526b432194fc88 (patch) | |
tree | e6708a9c6702f9fad36249e6830954be6a3098ee /internal/gitaly/service | |
parent | c62615c15090e5627f8f5fc62661f7360130c5d1 (diff) |
repository: Add updateHeadFromBundle in CreateRepositoryFromBundle
Diffstat (limited to 'internal/gitaly/service')
-rw-r--r-- | internal/gitaly/service/repository/create_repository_from_bundle.go | 4 | ||||
-rw-r--r-- | internal/gitaly/service/repository/create_repository_from_bundle_test.go | 35 |
2 files changed, 34 insertions, 5 deletions
diff --git a/internal/gitaly/service/repository/create_repository_from_bundle.go b/internal/gitaly/service/repository/create_repository_from_bundle.go index 4ecce9dc6..14ece1c43 100644 --- a/internal/gitaly/service/repository/create_repository_from_bundle.go +++ b/internal/gitaly/service/repository/create_repository_from_bundle.go @@ -75,6 +75,10 @@ func (s *server) CreateRepositoryFromBundle(stream gitalypb.RepositoryService_Cr return helper.ErrInternalf("fetch from bundle: %w, stderr: %q", err, sanitizedStderr) } + if err := s.updateHeadFromBundle(ctx, s.localrepo(repo), bundlePath); err != nil { + return helper.ErrInternal(err) + } + return nil }); err != nil { return helper.ErrInternalf("creating repository: %w", err) diff --git a/internal/gitaly/service/repository/create_repository_from_bundle_test.go b/internal/gitaly/service/repository/create_repository_from_bundle_test.go index 8f544432e..024c36400 100644 --- a/internal/gitaly/service/repository/create_repository_from_bundle_test.go +++ b/internal/gitaly/service/repository/create_repository_from_bundle_test.go @@ -2,6 +2,7 @@ package repository import ( "bytes" + "context" "io" "os" "path/filepath" @@ -15,6 +16,7 @@ import ( "gitlab.com/gitlab-org/gitaly/v14/internal/gitaly/transaction" "gitlab.com/gitlab-org/gitaly/v14/internal/helper/text" "gitlab.com/gitlab-org/gitaly/v14/internal/metadata" + "gitlab.com/gitlab-org/gitaly/v14/internal/metadata/featureflag" "gitlab.com/gitlab-org/gitaly/v14/internal/praefect/praefectutil" "gitlab.com/gitlab-org/gitaly/v14/internal/tempdir" "gitlab.com/gitlab-org/gitaly/v14/internal/testhelper" @@ -29,8 +31,11 @@ import ( func TestCreateRepositoryFromBundle_successful(t *testing.T) { t.Parallel() - ctx := testhelper.Context(t) + testhelper.NewFeatureSets(featureflag.TransactionalSymbolicRefUpdates).Run(t, testCreateRepositoryFromBundleSuccessful) +} + +func testCreateRepositoryFromBundleSuccessful(t *testing.T, ctx context.Context) { cfg, repo, repoPath, client := setupRepositoryService(ctx, t) locator := config.NewLocator(cfg) @@ -40,6 +45,10 @@ func TestCreateRepositoryFromBundle_successful(t *testing.T) { gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/custom-refs/ref1", "HEAD") + // A user may use a default branch other than "main" or "master" + const wantDefaultBranch = "refs/heads/markdown" + gittest.Exec(t, cfg, "-C", repoPath, "symbolic-ref", "HEAD", wantDefaultBranch) + gittest.Exec(t, cfg, "-C", repoPath, "bundle", "create", bundlePath, "--all") defer func() { require.NoError(t, os.RemoveAll(bundlePath)) }() @@ -87,12 +96,19 @@ func TestCreateRepositoryFromBundle_successful(t *testing.T) { commit, err := importedRepo.ReadCommit(ctx, "refs/custom-refs/ref1") require.NoError(t, err) require.NotNil(t, commit) + + gotDefaultBranch, err := importedRepo.GetDefaultBranch(ctx) + require.NoError(t, err) + require.Equal(t, wantDefaultBranch, gotDefaultBranch.String()) } func TestCreateRepositoryFromBundle_transactional(t *testing.T) { t.Parallel() - ctx := testhelper.Context(t) + testhelper.NewFeatureSets(featureflag.TransactionalSymbolicRefUpdates).Run(t, testCreateRepositoryFromBundleTransactional) +} + +func testCreateRepositoryFromBundleTransactional(t *testing.T, ctx context.Context) { txManager := transaction.NewTrackingManager() cfg, repoProto, repoPath, client := setupRepositoryService(ctx, t, testserver.WithTransactionManager(txManager)) @@ -158,8 +174,11 @@ func TestCreateRepositoryFromBundle_transactional(t *testing.T) { func TestCreateRepositoryFromBundle_invalidBundle(t *testing.T) { t.Parallel() - ctx := testhelper.Context(t) + testhelper.NewFeatureSets(featureflag.TransactionalSymbolicRefUpdates).Run(t, testCreateRepositoryFromBundleInvalidBundle) +} + +func testCreateRepositoryFromBundleInvalidBundle(t *testing.T, ctx context.Context) { cfg, client := setupRepositoryServiceWithoutRepo(t) stream, err := client.CreateRepositoryFromBundle(ctx) @@ -195,8 +214,11 @@ func TestCreateRepositoryFromBundle_invalidBundle(t *testing.T) { func TestCreateRepositoryFromBundle_invalidArgument(t *testing.T) { t.Parallel() - ctx := testhelper.Context(t) + testhelper.NewFeatureSets(featureflag.TransactionalSymbolicRefUpdates).Run(t, testCreateRepositoryFromBundleInvalidArgument) +} + +func testCreateRepositoryFromBundleInvalidArgument(t *testing.T, ctx context.Context) { _, client := setupRepositoryServiceWithoutRepo(t) stream, err := client.CreateRepositoryFromBundle(ctx) @@ -210,8 +232,11 @@ func TestCreateRepositoryFromBundle_invalidArgument(t *testing.T) { func TestCreateRepositoryFromBundle_existingRepository(t *testing.T) { t.Parallel() - ctx := testhelper.Context(t) + testhelper.NewFeatureSets(featureflag.TransactionalSymbolicRefUpdates).Run(t, testCreateRepositoryFromBundleExistingRepository) +} + +func testCreateRepositoryFromBundleExistingRepository(t *testing.T, ctx context.Context) { cfg, client := setupRepositoryServiceWithoutRepo(t) // The above test creates the second repository on the server. As this test can run with Praefect in front of it, |