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:
authorToon Claes <toon@gitlab.com>2022-03-15 00:30:05 +0300
committerToon Claes <toon@gitlab.com>2022-03-15 00:30:05 +0300
commitd7fcf59e9183da0785b81ff07e0bcf2ca7c115f8 (patch)
tree7db3bd8c0b79b036bb6afab0c199be9ca2a0436b
parent07d8371c7a77eee9813b2810f6605e3710c689da (diff)
parent7209dff05de90b79d89d8cf3fa526b432194fc88 (diff)
Merge branch 'nanmu42-update-head' into 'master'
repository: Add updateHeadFromBundle in CreateRepositoryFromBundle Closes #4086 See merge request gitlab-org/gitaly!4401
-rw-r--r--internal/gitaly/service/repository/create_repository_from_bundle.go4
-rw-r--r--internal/gitaly/service/repository/create_repository_from_bundle_test.go35
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,