diff options
author | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-01-22 16:23:24 +0300 |
---|---|---|
committer | Patrick Steinhardt <psteinhardt@gitlab.com> | 2021-01-26 12:50:53 +0300 |
commit | c702217d18831e249bf0b2d8f2f86142206465dd (patch) | |
tree | c2060e976997621bf055309b749d010da777ae39 | |
parent | af409d5510ea6e341202dbc62da3e2dd1400d445 (diff) |
repository: Fix default refspec for FetchRemote
in case a RemoteParam as passed to FetchRemote, we intend do use its
MirrorRefmaps to determine how references should be mirrored, as there
is no configured remote which could have a refspec. In case no map is
provided, we should fall back to just doing a mirror-fetch, if one goes
by what the Ruby RPC did back when it still existed. But in fact we
don't set up a refspec at all in that case, which instead causes us to
simply fetch the remote's HEAD reference.
Fix this issue by using "refs/*:refs/*" in case no refspec is given.
-rw-r--r-- | internal/gitaly/service/repository/fetch_remote.go | 4 | ||||
-rw-r--r-- | internal/gitaly/service/repository/fetch_remote_test.go | 47 |
2 files changed, 51 insertions, 0 deletions
diff --git a/internal/gitaly/service/repository/fetch_remote.go b/internal/gitaly/service/repository/fetch_remote.go index 7eefa0b03..ad3d72901 100644 --- a/internal/gitaly/service/repository/fetch_remote.go +++ b/internal/gitaly/service/repository/fetch_remote.go @@ -203,6 +203,10 @@ func (s *server) validateFetchRemoteRequest(req *gitalypb.FetchRemoteRequest) er } func (s *server) getRefspecs(refmaps []string) []string { + if len(refmaps) == 0 { + return []string{"+refs/*:refs/*"} + } + refspecs := make([]string, 0, len(refmaps)) for _, refmap := range refmaps { diff --git a/internal/gitaly/service/repository/fetch_remote_test.go b/internal/gitaly/service/repository/fetch_remote_test.go index c0577df6a..7614e9458 100644 --- a/internal/gitaly/service/repository/fetch_remote_test.go +++ b/internal/gitaly/service/repository/fetch_remote_test.go @@ -13,6 +13,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/gitaly/config" "gitlab.com/gitlab-org/gitaly/internal/helper/text" "gitlab.com/gitlab-org/gitaly/internal/storage" @@ -73,6 +74,52 @@ func TestFetchRemoteSuccess(t *testing.T) { require.Equal(t, resp.TagsChanged, true) } +func TestFetchRemote_withDefaultRefmaps(t *testing.T) { + locator := config.NewLocator(config.Config) + serverSocketPath, stop := runRepoServer(t, locator, testhelper.WithInternalSocket(config.Config)) + defer stop() + + client, conn := newRepositoryClient(t, serverSocketPath) + defer conn.Close() + + sourceRepoProto, sourceRepoPath, cleanup := testhelper.NewTestRepo(t) + defer cleanup() + sourceRepo := git.NewRepository(sourceRepoProto, config.Config) + + targetRepoProto, targetRepoPath := copyRepoWithNewRemote(t, sourceRepoProto, locator, "my-remote") + defer func() { + require.NoError(t, os.RemoveAll(targetRepoPath)) + }() + targetRepo := git.NewRepository(targetRepoProto, config.Config) + + port, stopGitServer := testhelper.GitServer(t, config.Config, sourceRepoPath, nil) + defer func() { require.NoError(t, stopGitServer()) }() + + ctx, cancel := testhelper.Context() + defer cancel() + + require.NoError(t, sourceRepo.UpdateRef(ctx, "refs/heads/foobar", "refs/heads/master", "")) + + // With no refmap given, FetchRemote should fall back to + // "refs/heads/*:refs/heads/*" and thus mirror what's in the source + // repository. + resp, err := client.FetchRemote(ctx, &gitalypb.FetchRemoteRequest{ + Repository: targetRepoProto, + RemoteParams: &gitalypb.Remote{ + Url: fmt.Sprintf("http://127.0.0.1:%d/%s", port, filepath.Base(sourceRepoPath)), + Name: "my-remote", + }, + }) + require.NoError(t, err) + require.NotNil(t, resp) + + sourceRefs, err := sourceRepo.GetReferences(ctx, "") + require.NoError(t, err) + targetRefs, err := targetRepo.GetReferences(ctx, "") + require.NoError(t, err) + require.Equal(t, sourceRefs, targetRefs) +} + func TestFetchRemoteFailure(t *testing.T) { repo, _, cleanup := testhelper.NewTestRepo(t) defer cleanup() |