Commit 4df43723 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'rs-enable-keep-divergent-refs' into 'master'

Make keep_divergent_refs generally available

Closes #208828

See merge request gitlab-org/gitlab!32381
parents 2e7e0fe4 9edc899b
- protocols = Gitlab::UrlSanitizer::ALLOWED_SCHEMES.join('|') - 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| = f.fields_for :remote_mirrors, @project.remote_mirrors.build do |rm_f|
= rm_f.hidden_field :enabled, value: '1' = 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 :url, class: 'js-mirror-url-hidden', required: true, pattern: "(#{protocols}):\/\/.+"
= rm_f.hidden_field :only_protected_branches, class: 'js-mirror-protected-hidden' = 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' = 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/ssh_host_keys', locals: { f: rm_f }
= render partial: 'projects/mirrors/authentication_method', locals: { f: rm_f } = render partial: 'projects/mirrors/authentication_method', locals: { f: rm_f }
- if keep_divergent_refs
.form-check.append-bottom-10 .form-check.append-bottom-10
= check_box_tag :keep_divergent_refs, '1', false, class: 'js-mirror-keep-divergent-refs form-check-input' = 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' = label_tag :keep_divergent_refs, _('Keep divergent refs'), class: 'form-check-label'
= link_to icon('question-circle'), help_page_path('user/project/repository/repository_mirroring', anchor: 'keep-divergent-refs-core'), target: '_blank'
---
title: Add "Keep divergent refs" option for push mirrors
merge_request: 32381
author:
type: added
...@@ -33,6 +33,7 @@ Example response: ...@@ -33,6 +33,7 @@ Example response:
"last_update_at": "2020-01-06T17:32:02.823Z", "last_update_at": "2020-01-06T17:32:02.823Z",
"last_update_started_at": "2020-01-06T17:31:55.864Z", "last_update_started_at": "2020-01-06T17:31:55.864Z",
"only_protected_branches": true, "only_protected_branches": true,
"keep_divergent_refs": true,
"update_status": "finished", "update_status": "finished",
"url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git" "url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git"
} }
...@@ -58,6 +59,7 @@ POST /projects/:id/remote_mirrors ...@@ -58,6 +59,7 @@ POST /projects/:id/remote_mirrors
| `url` | String | yes | The URL of the remote repository to be mirrored. | | `url` | String | yes | The URL of the remote repository to be mirrored. |
| `enabled` | Boolean | no | Determines if the mirror is enabled. | | `enabled` | Boolean | no | Determines if the mirror is enabled. |
| `only_protected_branches` | Boolean | no | Determines if only protected branches are mirrored. | | `only_protected_branches` | Boolean | no | Determines if only protected branches are mirrored. |
| `keep_divergent_refs` | Boolean | no | Determines if divergent refs are skipped. |
Example request: Example request:
...@@ -76,6 +78,7 @@ Example response: ...@@ -76,6 +78,7 @@ Example response:
"last_update_at": null, "last_update_at": null,
"last_update_started_at": null, "last_update_started_at": null,
"only_protected_branches": false, "only_protected_branches": false,
"keep_divergent_refs": false,
"update_status": "none", "update_status": "none",
"url": "https://*****:*****@example.com/gitlab/example.git" "url": "https://*****:*****@example.com/gitlab/example.git"
} }
...@@ -97,6 +100,7 @@ PUT /projects/:id/remote_mirrors/:mirror_id ...@@ -97,6 +100,7 @@ PUT /projects/:id/remote_mirrors/:mirror_id
| `mirror_id` | Integer | yes | The remote mirror ID. | | `mirror_id` | Integer | yes | The remote mirror ID. |
| `enabled` | Boolean | no | Determines if the mirror is enabled. | | `enabled` | Boolean | no | Determines if the mirror is enabled. |
| `only_protected_branches` | Boolean | no | Determines if only protected branches are mirrored. | | `only_protected_branches` | Boolean | no | Determines if only protected branches are mirrored. |
| `keep_divergent_refs` | Boolean | no | Determines if divergent refs are skipped. |
Example request: Example request:
...@@ -115,6 +119,7 @@ Example response: ...@@ -115,6 +119,7 @@ Example response:
"last_update_at": "2020-01-06T17:32:02.823Z", "last_update_at": "2020-01-06T17:32:02.823Z",
"last_update_started_at": "2020-01-06T17:31:55.864Z", "last_update_started_at": "2020-01-06T17:31:55.864Z",
"only_protected_branches": true, "only_protected_branches": true,
"keep_divergent_refs": true,
"update_status": "finished", "update_status": "finished",
"url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git" "url": "https://*****:*****@gitlab.com/gitlab-org/security/gitlab.git"
} }
......
...@@ -55,6 +55,7 @@ For an existing project, you can set up push mirroring as follows: ...@@ -55,6 +55,7 @@ For an existing project, you can set up push mirroring as follows:
1. Select **Push** from the **Mirror direction** dropdown. 1. Select **Push** from the **Mirror direction** dropdown.
1. Select an authentication method from the **Authentication method** dropdown, if necessary. 1. Select an authentication method from the **Authentication method** dropdown, if necessary.
1. Check the **Only mirror protected branches** box, if necessary. 1. Check the **Only mirror protected branches** box, if necessary.
1. Check the **Keep divergent refs** box, if desired.
1. Click the **Mirror repository** button to save the configuration. 1. Click the **Mirror repository** button to save the configuration.
![Repository mirroring push settings screen](img/repository_mirroring_push_settings.png) ![Repository mirroring push settings screen](img/repository_mirroring_push_settings.png)
...@@ -88,6 +89,27 @@ You can choose to only push your protected branches from GitLab to your remote r ...@@ -88,6 +89,27 @@ You can choose to only push your protected branches from GitLab to your remote r
To use this option, check the **Only mirror protected branches** box when creating a repository To use this option, check the **Only mirror protected branches** box when creating a repository
mirror. mirror.
### Keep divergent refs **(CORE)**
> [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/208828) in GitLab 13.0.
By default, if any ref on the remote mirror has diverged from the local
repository, the *entire push* will fail, and nothing will be updated.
For example, if a repository has `master`, `develop`, and `stable` branches that
have been mirrored to a remote, and then a new commit is added to `develop` on
the mirror, the next push attempt will fail, leaving `master` and `stable`
out-of-date despite not having diverged. No change on any branch can be mirrored
until the divergence is resolved.
With the **Keep divergent refs** option enabled, the `develop` branch is
skipped, allowing `master` and `stable` to be updated. The mirror status will
reflect that `develop` has diverged and was skipped, and be marked as a failed
update.
NOTE: **Note:**
After the mirror is created, this option can currently only be modified via the [API](../../../api/remote_mirrors.md).
## Setting up a push mirror from GitLab to GitHub **(CORE)** ## Setting up a push mirror from GitLab to GitHub **(CORE)**
To set up a mirror from GitLab to GitHub, you need to follow these steps: To set up a mirror from GitLab to GitHub, you need to follow these steps:
......
...@@ -12,9 +12,7 @@ module API ...@@ -12,9 +12,7 @@ module API
expose :last_successful_update_at expose :last_successful_update_at
expose :last_error expose :last_error
expose :only_protected_branches expose :only_protected_branches
expose :keep_divergent_refs, if: -> (mirror, _options) do expose :keep_divergent_refs
::Feature.enabled?(:keep_divergent_refs, mirror.project)
end
end end
end end
end end
...@@ -34,7 +34,6 @@ module API ...@@ -34,7 +34,6 @@ module API
end end
post ':id/remote_mirrors' do post ':id/remote_mirrors' do
create_params = declared_params(include_missing: false) create_params = declared_params(include_missing: false)
create_params.delete(:keep_divergent_refs) unless ::Feature.enabled?(:keep_divergent_refs, user_project)
new_mirror = user_project.remote_mirrors.create(create_params) new_mirror = user_project.remote_mirrors.create(create_params)
...@@ -59,7 +58,6 @@ module API ...@@ -59,7 +58,6 @@ module API
mirror_params = declared_params(include_missing: false) mirror_params = declared_params(include_missing: false)
mirror_params[:id] = mirror_params.delete(:mirror_id) mirror_params[:id] = mirror_params.delete(:mirror_id)
mirror_params.delete(:keep_divergent_refs) unless ::Feature.enabled?(:keep_divergent_refs, user_project)
update_params = { remote_mirrors_attributes: mirror_params } update_params = { remote_mirrors_attributes: mirror_params }
......
...@@ -12269,6 +12269,9 @@ msgstr "" ...@@ -12269,6 +12269,9 @@ msgstr ""
msgid "Just me" msgid "Just me"
msgstr "" msgstr ""
msgid "Keep divergent refs"
msgstr ""
msgid "Key" msgid "Key"
msgstr "" msgstr ""
......
...@@ -222,20 +222,6 @@ describe 'Projects > Settings > Repository settings' do ...@@ -222,20 +222,6 @@ describe 'Projects > Settings > Repository settings' do
end end
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: false)
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 context 'repository cleanup settings' do
let(:object_map_file) { Rails.root.join('spec', 'fixtures', 'bfg_object_map.txt') } let(:object_map_file) { Rails.root.join('spec', 'fixtures', 'bfg_object_map.txt') }
......
...@@ -147,13 +147,13 @@ describe RemoteMirror, :mailer do ...@@ -147,13 +147,13 @@ describe RemoteMirror, :mailer do
git_remote_mirror = stub_const('Gitlab::Git::RemoteMirror', spy) git_remote_mirror = stub_const('Gitlab::Git::RemoteMirror', spy)
mirror = build(:remote_mirror) mirror = build(:remote_mirror)
expect(mirror).to receive(:options_for_update).and_return(options: true) expect(mirror).to receive(:options_for_update).and_return(keep_divergent_refs: true)
mirror.update_repository mirror.update_repository
expect(git_remote_mirror).to have_received(:new).with( expect(git_remote_mirror).to have_received(:new).with(
mirror.project.repository.raw, mirror.project.repository.raw,
mirror.remote_name, mirror.remote_name,
options: true keep_divergent_refs: true
) )
expect(git_remote_mirror).to have_received(:update) expect(git_remote_mirror).to have_received(:update)
end end
......
...@@ -78,10 +78,6 @@ describe API::RemoteMirrors do ...@@ -78,10 +78,6 @@ describe API::RemoteMirrors do
let(:route) { ->(id) { "/projects/#{project.id}/remote_mirrors/#{id}" } } let(:route) { ->(id) { "/projects/#{project.id}/remote_mirrors/#{id}" } }
let(:mirror) { project.remote_mirrors.first } let(:mirror) { project.remote_mirrors.first }
before do
stub_feature_flags(keep_divergent_refs: false)
end
it 'requires `admin_remote_mirror` permission' do it 'requires `admin_remote_mirror` permission' do
put api(route[mirror.id], developer) put api(route[mirror.id], developer)
...@@ -100,24 +96,7 @@ describe API::RemoteMirrors do ...@@ -100,24 +96,7 @@ describe API::RemoteMirrors do
expect(response).to have_gitlab_http_status(:success) expect(response).to have_gitlab_http_status(:success)
expect(json_response['enabled']).to eq(false) expect(json_response['enabled']).to eq(false)
expect(json_response['only_protected_branches']).to eq(true) expect(json_response['only_protected_branches']).to eq(true)
# Deleted due to lack of feature availability
expect(json_response['keep_divergent_refs']).to be_nil
end
context 'with the `keep_divergent_refs` feature enabled' do
before do
stub_feature_flags(keep_divergent_refs: project)
end
it 'updates the `keep_divergent_refs` attribute' do
project.add_maintainer(user)
put api(route[mirror.id], user), params: { keep_divergent_refs: 'true' }
expect(response).to have_gitlab_http_status(:success)
expect(json_response['keep_divergent_refs']).to eq(true) expect(json_response['keep_divergent_refs']).to eq(true)
end end
end end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment