diff --git a/changelogs/unreleased/rs-delete-divergent-refs-option.yml b/changelogs/unreleased/rs-delete-divergent-refs-option.yml new file mode 100644 index 0000000000000000000000000000000000000000..9e4187cae97dffc1cfa64aa05010ceeed6e86c1e --- /dev/null +++ b/changelogs/unreleased/rs-delete-divergent-refs-option.yml @@ -0,0 +1,5 @@ +--- +title: Optionally keep divergent refs when mirroring +merge_request: 1828 +author: +type: added diff --git a/internal/service/remote/update_remote_mirror_test.go b/internal/service/remote/update_remote_mirror_test.go index cf6823c6f49d2bc90200d561cc6d2d4c1258e5b5..87e51eb8cdb9165e01b07a5bc0dc0379fa0aeac0 100644 --- a/internal/service/remote/update_remote_mirror_test.go +++ b/internal/service/remote/update_remote_mirror_test.go @@ -172,6 +172,62 @@ func TestSuccessfulUpdateRemoteMirrorRequestWithWildcards(t *testing.T) { require.NotContains(t, mirrorRefs, "refs/tags/v1.2.0") } +func TestSuccessfulUpdateRemoteMirrorRequestWithKeepDivergentRefs(t *testing.T) { + server, serverSocketPath := runRemoteServiceServer(t) + defer server.Stop() + + client, conn := NewRemoteClient(t, serverSocketPath) + defer conn.Close() + + testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t) + defer cleanupFn() + + _, mirrorPath, mirrorCleanupFn := testhelper.NewTestRepo(t) + defer mirrorCleanupFn() + + remoteName := "remote_mirror_1" + + testhelper.CreateTag(t, mirrorPath, "v2.0.0", "master", nil) + + setupCommands := [][]string{ + // Preconditions + {"config", "user.email", "gitalytest@example.com"}, + {"remote", "add", remoteName, mirrorPath}, + {"fetch", remoteName}, + + // Delete a branch and a tag to ensure they're kept around in the mirror + {"branch", "-D", "not-merged-branch"}, + {"tag", "-d", "v2.0.0"}, + } + + for _, args := range setupCommands { + gitArgs := []string{"-C", testRepoPath} + gitArgs = append(gitArgs, args...) + testhelper.MustRunCommand(t, nil, "git", gitArgs...) + } + + ctx, cancel := testhelper.Context() + defer cancel() + + firstRequest := &gitalypb.UpdateRemoteMirrorRequest{ + Repository: testRepo, + RefName: remoteName, + KeepDivergentRefs: true, + } + + stream, err := client.UpdateRemoteMirror(ctx) + require.NoError(t, err) + require.NoError(t, stream.Send(firstRequest)) + + _, err = stream.CloseAndRecv() + require.NoError(t, err) + + mirrorRefs := string(testhelper.MustRunCommand(t, nil, "git", "-C", mirrorPath, "for-each-ref")) + + require.Contains(t, mirrorRefs, "refs/heads/not-merged-branch") + require.Contains(t, mirrorRefs, "refs/tags/v2.0.0") +} + func TestFailedUpdateRemoteMirrorRequestDueToValidation(t *testing.T) { server, serverSocketPath := runRemoteServiceServer(t) defer server.Stop() diff --git a/proto/go/gitalypb/remote.pb.go b/proto/go/gitalypb/remote.pb.go index 8ec9bdc30974ed081f735ea0afa7a70b8dbd4196..35119836a6d47901b4e78353bc26db27ce4dec86 100644 --- a/proto/go/gitalypb/remote.pb.go +++ b/proto/go/gitalypb/remote.pb.go @@ -297,6 +297,7 @@ type UpdateRemoteMirrorRequest struct { OnlyBranchesMatching [][]byte `protobuf:"bytes,3,rep,name=only_branches_matching,json=onlyBranchesMatching,proto3" json:"only_branches_matching,omitempty"` SshKey string `protobuf:"bytes,4,opt,name=ssh_key,json=sshKey,proto3" json:"ssh_key,omitempty"` KnownHosts string `protobuf:"bytes,5,opt,name=known_hosts,json=knownHosts,proto3" json:"known_hosts,omitempty"` + KeepDivergentRefs bool `protobuf:"varint,6,opt,name=keep_divergent_refs,json=keepDivergentRefs,proto3" json:"keep_divergent_refs,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -362,6 +363,13 @@ func (m *UpdateRemoteMirrorRequest) GetKnownHosts() string { return "" } +func (m *UpdateRemoteMirrorRequest) GetKeepDivergentRefs() bool { + if m != nil { + return m.KeepDivergentRefs + } + return false +} + type UpdateRemoteMirrorResponse struct { XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` @@ -713,53 +721,55 @@ func init() { func init() { proto.RegisterFile("remote.proto", fileDescriptor_eefc82927d57d89b) } var fileDescriptor_eefc82927d57d89b = []byte{ - // 732 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x55, 0xcd, 0x6e, 0xd3, 0x4a, - 0x14, 0x96, 0xe3, 0x34, 0x71, 0x4e, 0xd2, 0xab, 0x74, 0x52, 0xf5, 0x3a, 0x4e, 0xa5, 0x9b, 0xfa, - 0xde, 0x2b, 0x79, 0x41, 0x93, 0xaa, 0xfc, 0x88, 0x05, 0x12, 0xa2, 0x0b, 0x54, 0x7e, 0x5a, 0x81, - 0xa1, 0x1b, 0x36, 0xc6, 0x49, 0xc6, 0xb1, 0x55, 0xc7, 0x63, 0x66, 0x9c, 0x42, 0x9e, 0xa4, 0x2c, - 0x78, 0x01, 0x36, 0x3c, 0x06, 0xcf, 0xc1, 0x73, 0x74, 0x85, 0xc6, 0x33, 0x4e, 0x9c, 0xd6, 0x09, - 0x8b, 0xc2, 0x6e, 0xe6, 0x3b, 0x67, 0xce, 0xf9, 0xce, 0xe7, 0x73, 0x8e, 0xa1, 0x41, 0xf1, 0x84, - 0x24, 0xb8, 0x17, 0x53, 0x92, 0x10, 0x54, 0x19, 0x07, 0x89, 0x1b, 0xce, 0x8c, 0x06, 0xf3, 0x5d, - 0x8a, 0x47, 0x02, 0x35, 0xbf, 0x29, 0xd0, 0x7c, 0x32, 0x1a, 0xd9, 0xa9, 0xa7, 0x8d, 0x3f, 0x4c, - 0x31, 0x4b, 0xd0, 0x43, 0x00, 0x8a, 0x63, 0xc2, 0x82, 0x84, 0xd0, 0x99, 0xae, 0x74, 0x15, 0xab, - 0x7e, 0x88, 0x7a, 0xe2, 0x7d, 0xcf, 0x9e, 0x5b, 0x8e, 0xca, 0x9f, 0xbf, 0xdf, 0x51, 0xec, 0x9c, - 0x2f, 0x42, 0x50, 0x8e, 0xdc, 0x09, 0xd6, 0x4b, 0x5d,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0x07, 0x83, 0x4a, 0x0a, 0xdd, 0xfd, 0x19, - 0x00, 0x00, 0xff, 0xff, 0xf0, 0x1b, 0x4b, 0x61, 0x32, 0x08, 0x00, 0x00, + // 753 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0xc9, 0x6e, 0xd3, 0x40, + 0x18, 0x96, 0x93, 0x34, 0xcb, 0x9f, 0x14, 0x25, 0x93, 0xaa, 0x38, 0x4e, 0x25, 0x52, 0x03, 0x92, + 0x0f, 0x34, 0xa9, 0xca, 0x22, 0x0e, 0x48, 0x88, 0x0a, 0xa1, 0xb2, 0xb4, 0x02, 0x43, 0x2f, 0x5c, + 0x8c, 0x93, 0x8c, 0x63, 0x2b, 0x8e, 0xc7, 0xcc, 0x38, 0x85, 0xbc, 0x05, 0xb7, 0x72, 0xe0, 0x05, + 0xb8, 0xf0, 0x18, 0x3c, 0x54, 0x4f, 0x68, 0x3c, 0xe3, 0xc4, 0x69, 0x9d, 0x70, 0x28, 0xdc, 0x3c, + 0xdf, 0xbf, 0x7d, 0xff, 0x2a, 0x43, 0x8d, 0xe2, 0x09, 0x89, 0x70, 0x37, 0xa4, 0x24, 0x22, 0xa8, + 0x38, 0xf2, 0x22, 0xdb, 0x9f, 0x69, 0x35, 0xe6, 0xda, 0x14, 0x0f, 0x05, 0xaa, 0xff, 0x52, 0xa0, + 0xfe, 0x6c, 0x38, 0x34, 0x63, 0x4d, 0x13, 0x7f, 0x9e, 0x62, 0x16, 0xa1, 0xc7, 0x00, 0x14, 0x87, + 0x84, 0x79, 0x11, 0xa1, 0x33, 0x55, 0xe9, 0x28, 0x46, 0xf5, 0x00, 0x75, 0x85, 0x7d, 0xd7, 0x9c, + 0x4b, 0x0e, 0x0b, 0xdf, 0x7f, 0xdf, 0x53, 0xcc, 0x94, 0x2e, 0x42, 0x50, 0x08, 0xec, 0x09, 0x56, + 0x73, 0x1d, 0x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91, 0xeb, 0xf9, 0x76, 0xbf, 0x3b, 0x20, 0x93, 0x9e, 0xf8, + 0xdc, 0x23, 0x74, 0xd4, 0x13, 0xd6, 0xbd, 0xf8, 0x4f, 0xa1, 0x37, 0x22, 0xf2, 0x1d, 0xf6, 0xfb, + 0xc5, 0x18, 0xba, 0xff, 0x27, 0x00, 0x00, 0xff, 0xff, 0x84, 0x8d, 0xa5, 0xca, 0x62, 0x08, 0x00, + 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/proto/remote.proto b/proto/remote.proto index f4fd61f3e10278da32b493a91e2c784d3b483949..2f7970c89a75f64f7f2ad3ba13500bf39fb4e282 100644 --- a/proto/remote.proto +++ b/proto/remote.proto @@ -83,6 +83,7 @@ message UpdateRemoteMirrorRequest { repeated bytes only_branches_matching = 3; string ssh_key = 4; string known_hosts = 5; + bool keep_divergent_refs = 6; } message UpdateRemoteMirrorResponse {} diff --git a/ruby/lib/gitaly_server/remote_service.rb b/ruby/lib/gitaly_server/remote_service.rb index 39cc6e60e00a5a6cab598bb1beb10137dba6e3f6..fa62ec09253ca7e86953260ea741cde14ab86b93 100644 --- a/ruby/lib/gitaly_server/remote_service.rb +++ b/ruby/lib/gitaly_server/remote_service.rb @@ -24,16 +24,16 @@ module GitalyServer def update_remote_mirror(call) request_enum = call.each_remote_read first_request = request_enum.next - repo = Gitlab::Git::Repository.from_gitaly(first_request.repository, call) - only_branches_matching = first_request.only_branches_matching.to_a + only_branches_matching = first_request.only_branches_matching.to_a only_branches_matching += request_enum.flat_map(&:only_branches_matching) remote_mirror = Gitlab::Git::RemoteMirror.new( - repo, + Gitlab::Git::Repository.from_gitaly(first_request.repository, call), first_request.ref_name, + ssh_auth: Gitlab::Git::SshAuth.from_gitaly(first_request), only_branches_matching: only_branches_matching, - ssh_auth: Gitlab::Git::SshAuth.from_gitaly(first_request) + keep_divergent_refs: first_request.keep_divergent_refs ) remote_mirror.update diff --git a/ruby/lib/gitlab/git/remote_mirror.rb b/ruby/lib/gitlab/git/remote_mirror.rb index f1f110dfb305b0c4a3e9eaeffe74305def4f2f1f..9311a8b2568a9810a0d238d0175e5492f34878c8 100644 --- a/ruby/lib/gitlab/git/remote_mirror.rb +++ b/ruby/lib/gitlab/git/remote_mirror.rb @@ -3,11 +3,12 @@ module Gitlab class RemoteMirror attr_reader :repository, :remote_name, :ssh_auth, :only_branches_matching - def initialize(repository, remote_name, ssh_auth:, only_branches_matching: []) + def initialize(repository, remote_name, ssh_auth:, only_branches_matching:, keep_divergent_refs:) @repository = repository @remote_name = remote_name @ssh_auth = ssh_auth @only_branches_matching = only_branches_matching + @keep_divergent_refs = keep_divergent_refs end def update @@ -81,6 +82,8 @@ module Gitlab end def delete_refs(local_refs, remote_refs, env:) + return if @keep_divergent_refs + refs = refs_to_delete(local_refs, remote_refs) return unless refs.present? @@ -96,7 +99,7 @@ module Gitlab remote_ref_id = remote_ref.dereferenced_target.try(:id) - remote_ref_id && repository.ancestor?(remote_ref_id, default_branch_id) + repository.ancestor?(remote_ref_id, default_branch_id) end end diff --git a/ruby/proto/gitaly/remote_pb.rb b/ruby/proto/gitaly/remote_pb.rb index 48c51650e519ae2ea6da637ccc814ab16c82156c..770f5e4e88d84db6b6f9813600ea3b60661f70c2 100644 --- a/ruby/proto/gitaly/remote_pb.rb +++ b/ruby/proto/gitaly/remote_pb.rb @@ -33,6 +33,7 @@ Google::Protobuf::DescriptorPool.generated_pool.build do repeated :only_branches_matching, :bytes, 3 optional :ssh_key, :string, 4 optional :known_hosts, :string, 5 + optional :keep_divergent_refs, :bool, 6 end add_message "gitaly.UpdateRemoteMirrorResponse" do end diff --git a/ruby/spec/lib/gitlab/git/remote_mirror_spec.rb b/ruby/spec/lib/gitlab/git/remote_mirror_spec.rb index 34503d0b087b747e443832bed293fc9557634cb0..2b7bc06051839e3fc82259ca87913d11e5bb800d 100644 --- a/ruby/spec/lib/gitlab/git/remote_mirror_spec.rb +++ b/ruby/spec/lib/gitlab/git/remote_mirror_spec.rb @@ -18,7 +18,8 @@ describe Gitlab::Git::RemoteMirror do repository, ref_name, ssh_auth: ssh_auth, - only_branches_matching: [] + only_branches_matching: [], + keep_divergent_refs: false ) end @@ -33,7 +34,8 @@ describe Gitlab::Git::RemoteMirror do repository, ref_name, ssh_auth: ssh_auth, - only_branches_matching: ['master', '*-stable'] + only_branches_matching: ['master', '*-stable'], + keep_divergent_refs: false ) end