diff --git a/app/assets/javascripts/mirrors/mirror_repos.js b/app/assets/javascripts/mirrors/mirror_repos.js index e5acaaf9366dd3525f8714d9a776e2d1f0bd653e..5401fb7b6ec0ba1a9e7170b222ad4270b563606d 100644 --- a/app/assets/javascripts/mirrors/mirror_repos.js +++ b/app/assets/javascripts/mirrors/mirror_repos.js @@ -22,15 +22,18 @@ export default class MirrorRepos { } initMirrorPush() { + this.$keepDivergentRefsInput = $('.js-mirror-keep-divergent-refs', this.$form); this.$passwordGroup = $('.js-password-group', this.$container); this.$password = $('.js-password', this.$passwordGroup); this.$authMethod = $('.js-auth-method', this.$form); + this.$keepDivergentRefsInput.on('change', () => this.updateKeepDivergentRefs()); this.$authMethod.on('change', () => this.togglePassword()); this.$password.on('input.updateUrl', () => this.debouncedUpdateUrl()); this.initMirrorSSH(); this.updateProtectedBranches(); + this.updateKeepDivergentRefs(); } initMirrorSSH() { @@ -61,6 +64,16 @@ export default class MirrorRepos { $('.js-mirror-protected-hidden', this.$form).val(val); } + updateKeepDivergentRefs() { + const field = this.$keepDivergentRefsInput.get(0); + + // This field only exists after the form is switched to 'Push' mode + if (field) { + const val = field.checked ? this.$keepDivergentRefsInput.val() : '0'; + $('.js-mirror-keep-divergent-refs-hidden', this.$form).val(val); + } + } + registerUpdateListeners() { this.debouncedUpdateUrl = debounce(() => this.updateUrl(), 200); this.$urlInput.on('input', () => this.debouncedUpdateUrl()); diff --git a/app/controllers/projects/mirrors_controller.rb b/app/controllers/projects/mirrors_controller.rb index 936f89e58e75854c61ce617cf0a4cffc946d6be1..518e6a92afa861872ae030397226f46d9bd591f0 100644 --- a/app/controllers/projects/mirrors_controller.rb +++ b/app/controllers/projects/mirrors_controller.rb @@ -77,6 +77,7 @@ def mirror_params_attributes id enabled only_protected_branches + keep_divergent_refs auth_method password ssh_known_hosts diff --git a/app/views/projects/mirrors/_mirror_repos_push.html.haml b/app/views/projects/mirrors/_mirror_repos_push.html.haml index b7c885b4a63fc12d28c30161d8d3a564e4bb0ee6..8482424a184aea813e2b8a5d793b2cbc835996ce 100644 --- a/app/views/projects/mirrors/_mirror_repos_push.html.haml +++ b/app/views/projects/mirrors/_mirror_repos_push.html.haml @@ -1,8 +1,15 @@ - protocols = Gitlab::UrlSanitizer::ALLOWED_SCHEMES.join('|') +- keep_divergent_refs = Feature.enabled?(:keep_divergent_refs, @project) = f.fields_for :remote_mirrors, @project.remote_mirrors.build do |rm_f| = rm_f.hidden_field :enabled, value: '1' = rm_f.hidden_field :url, class: 'js-mirror-url-hidden', required: true, pattern: "(#{protocols}):\/\/.+" = rm_f.hidden_field :only_protected_branches, class: 'js-mirror-protected-hidden' + - if keep_divergent_refs + = rm_f.hidden_field :keep_divergent_refs, class: 'js-mirror-keep-divergent-refs-hidden' = render partial: 'projects/mirrors/ssh_host_keys', locals: { f: rm_f } = render partial: 'projects/mirrors/authentication_method', locals: { f: rm_f } + - if keep_divergent_refs + .form-check.append-bottom-10 + = check_box_tag :keep_divergent_refs, '1', false, class: 'js-mirror-keep-divergent-refs form-check-input' + = label_tag :keep_divergent_refs, 'Keep divergent refs', class: 'form-check-label' diff --git a/spec/features/projects/settings/repository_settings_spec.rb b/spec/features/projects/settings/repository_settings_spec.rb index 9b956dee08943bec0f1d5eb0ef70bb8c1d019952..28a238a542378765ce2cc08a2d35fb00536a2c75 100644 --- a/spec/features/projects/settings/repository_settings_spec.rb +++ b/spec/features/projects/settings/repository_settings_spec.rb @@ -72,6 +72,21 @@ expect(project.remote_mirrors.first.only_protected_branches).to eq(true) end + it 'creates a push mirror that keeps divergent refs', :js do + select_direction + + fill_in 'url', with: 'ssh://user@localhost/project.git' + fill_in 'Password', with: 'password' + check 'Keep divergent refs' + + Sidekiq::Testing.fake! do + click_button 'Mirror repository' + end + + expect(page).to have_content('Mirroring settings were successfully updated') + expect(project.reload.remote_mirrors.first.keep_divergent_refs).to eq(true) + end + it 'generates an SSH public key on submission', :js do fill_in 'url', with: 'ssh://user@localhost/project.git' select 'SSH public key', from: 'Authentication method' @@ -110,6 +125,20 @@ def select_direction(direction = 'push') end end + # Removal: https://gitlab.com/gitlab-org/gitlab/-/issues/208828 + context 'with the `keep_divergent_refs` feature flag disabled' do + before do + stub_feature_flags(keep_divergent_refs: { enabled: false, thing: project }) + end + + it 'hides the "Keep divergent refs" option' do + visit project_settings_repository_path(project) + + expect(page).not_to have_selector('#keep_divergent_refs') + expect(page).not_to have_text('Keep divergent refs') + end + end + context 'repository cleanup settings' do let(:object_map_file) { Rails.root.join('spec', 'fixtures', 'bfg_object_map.txt') }