Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
1800a854
Commit
1800a854
authored
Feb 15, 2018
by
Tiago Botelho
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds option to overwrite a diverged branch when mirroring
parent
0c71e3df
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
104 additions
and
16 deletions
+104
-16
changelogs/unreleased-ee/4723-add-option-to-overwrite-diverged-branches-when-pull-mirroring.yml
...on-to-overwrite-diverged-branches-when-pull-mirroring.yml
+5
-0
db/schema.rb
db/schema.rb
+2
-1
doc/workflow/repository_mirroring.md
doc/workflow/repository_mirroring.md
+9
-0
ee/app/controllers/projects/mirrors_controller.rb
ee/app/controllers/projects/mirrors_controller.rb
+1
-0
ee/app/serializers/project_mirror_entity.rb
ee/app/serializers/project_mirror_entity.rb
+2
-0
ee/app/services/projects/update_mirror_service.rb
ee/app/services/projects/update_mirror_service.rb
+15
-4
ee/app/views/projects/mirrors/_pull.html.haml
ee/app/views/projects/mirrors/_pull.html.haml
+9
-0
ee/db/migrate/20180215143644_add_mirror_overwrites_diverged_branches_to_project.rb
...644_add_mirror_overwrites_diverged_branches_to_project.rb
+7
-0
ee/spec/serializers/project_mirror_entity_spec.rb
ee/spec/serializers/project_mirror_entity_spec.rb
+6
-0
ee/spec/services/projects/update_mirror_service_spec.rb
ee/spec/services/projects/update_mirror_service_spec.rb
+43
-11
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+4
-0
lib/gitlab/import_export/import_export.yml
lib/gitlab/import_export/import_export.yml
+1
-0
No files found.
changelogs/unreleased-ee/4723-add-option-to-overwrite-diverged-branches-when-pull-mirroring.yml
0 → 100644
View file @
1800a854
---
title
:
Add option to overwrite diverged branches for pull mirrors
merge_request
:
4559
author
:
type
:
added
db/schema.rb
View file @
1800a854
...
...
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2018021
3131630
)
do
ActiveRecord
::
Schema
.
define
(
version:
2018021
5143644
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -1913,6 +1913,7 @@ ActiveRecord::Schema.define(version: 20180213131630) do
t
.
boolean
"only_mirror_protected_branches"
t
.
boolean
"pull_mirror_available_overridden"
t
.
integer
"jobs_cache_index"
t
.
boolean
"mirror_overwrites_diverged_branches"
end
add_index
"projects"
,
[
"ci_id"
],
name:
"index_projects_on_ci_id"
,
using: :btree
...
...
doc/workflow/repository_mirroring.md
View file @
1800a854
...
...
@@ -102,6 +102,15 @@ You can choose to only pull the protected branches from your remote repository t
To use this option go to your project's repository settings page under pull mirror.
### Overwrite diverged branches
>[Introduced][ee-4559] in GitLab Enterprise Edition 10.6.
You can choose to always update your local branch with the remote version even
if your local version has diverged from the remote.
To use this option go to your project's repository settings page under pull mirror.
### Hard failure
>[Introduced][ee-3117] in GitLab Enterprise Edition 10.2.
...
...
ee/app/controllers/projects/mirrors_controller.rb
View file @
1800a854
...
...
@@ -81,6 +81,7 @@ class Projects::MirrorsController < Projects::ApplicationController
:mirror_user_id
,
:mirror_trigger_builds
,
:only_mirror_protected_branches
,
:mirror_overwrites_diverged_branches
,
import_data_attributes:
%i[
id
...
...
ee/app/serializers/project_mirror_entity.rb
View file @
1800a854
...
...
@@ -5,6 +5,8 @@ class ProjectMirrorEntity < Grape::Entity
expose
:username_only_import_url
expose
:mirror_user_id
expose
:mirror_trigger_builds
expose
:only_mirror_protected_branches
expose
:mirror_overwrites_diverged_branches
expose
:import_data_attributes
do
|
project
|
import_data
=
project
.
import_data
...
...
ee/app/services/projects/update_mirror_service.rb
View file @
1800a854
...
...
@@ -45,10 +45,7 @@ module Projects
elsif
local_branch
.
dereferenced_target
==
upstream_branch
.
dereferenced_target
# Already up to date
elsif
repository
.
diverged_from_upstream?
(
name
)
# Cannot be updated
if
name
==
project
.
default_branch
errors
<<
"The default branch (
#{
project
.
default_branch
}
) has diverged from its upstream counterpart and could not be updated automatically."
end
handle_diverged_branch
(
upstream_branch
,
local_branch
,
name
,
errors
)
else
begin
repository
.
ff_merge
(
current_user
,
upstream_branch
.
dereferenced_target
,
name
)
...
...
@@ -95,6 +92,20 @@ module Projects
fetch_result
end
def
handle_diverged_branch
(
upstream
,
local
,
branch_name
,
errors
)
if
project
.
mirror_overwrites_diverged_branches?
newrev
=
upstream
.
dereferenced_target
.
sha
oldrev
=
local
.
dereferenced_target
.
sha
repository
.
update_branch
(
current_user
,
branch_name
,
newrev
,
oldrev
)
elsif
branch_name
==
project
.
default_branch
# Cannot be updated
errors
<<
"The default branch (
#{
project
.
default_branch
}
) has diverged from its upstream counterpart and could not be updated automatically."
else
# We ignore diverged branches other than the default branch
end
end
# In Git is possible to tag blob objects, and those blob objects don't point to a Git commit so those tags
# have no target.
def
repository_tags_with_target
...
...
ee/app/views/projects/mirrors/_pull.html.haml
View file @
1800a854
...
...
@@ -47,6 +47,15 @@
=
f
.
label
:only_mirror_protected_branches
,
class:
'label-light'
=
link_to
icon
(
'question-circle'
),
help_page_path
(
'user/project/protected_branches'
)
.form-group
=
f
.
check_box
:mirror_overwrites_diverged_branches
,
class:
'pull-left'
.prepend-left-20
=
f
.
label
:mirror_overwrites_diverged_branches
,
"Overwrite diverged branches"
,
class:
'label-light'
.help-block
If disabled, a diverged local branch will not be automatically updated with commits from its remote counterpart,
to prevent local data loss. If the default branch (
#{
@project
.
default_branch
}
) has diverged and cannot be updated,
mirroring will fail. Other diverged branches are silently ignored.
-
if
@project
.
builds_enabled?
=
render
"shared/mirror_trigger_builds_setting"
,
f:
f
...
...
ee/db/migrate/20180215143644_add_mirror_overwrites_diverged_branches_to_project.rb
0 → 100644
View file @
1800a854
class
AddMirrorOverwritesDivergedBranchesToProject
<
ActiveRecord
::
Migration
DOWNTIME
=
false
def
change
add_column
:projects
,
:mirror_overwrites_diverged_branches
,
:boolean
end
end
ee/spec/serializers/project_mirror_entity_spec.rb
View file @
1800a854
...
...
@@ -20,6 +20,8 @@ describe ProjectMirrorEntity do
username_only_import_url:
project
.
username_only_import_url
,
mirror_user_id:
project
.
mirror_user_id
,
mirror_trigger_builds:
project
.
mirror_trigger_builds
,
only_mirror_protected_branches:
project
.
only_mirror_protected_branches
,
mirror_overwrites_diverged_branches:
project
.
mirror_overwrites_diverged_branches
,
import_data_attributes:
{
id:
import_data
.
id
,
auth_method:
'password'
,
...
...
@@ -48,6 +50,8 @@ describe ProjectMirrorEntity do
username_only_import_url:
project
.
username_only_import_url
,
mirror_user_id:
project
.
mirror_user_id
,
mirror_trigger_builds:
project
.
mirror_trigger_builds
,
only_mirror_protected_branches:
project
.
only_mirror_protected_branches
,
mirror_overwrites_diverged_branches:
project
.
mirror_overwrites_diverged_branches
,
import_data_attributes:
{
id:
import_data
.
id
,
auth_method:
'ssh_public_key'
,
...
...
@@ -75,6 +79,8 @@ describe ProjectMirrorEntity do
username_only_import_url:
nil
,
mirror_user_id:
nil
,
mirror_trigger_builds:
false
,
only_mirror_protected_branches:
true
,
mirror_overwrites_diverged_branches:
nil
,
import_data_attributes:
nil
,
remote_mirrors_attributes:
[
{
...
...
ee/spec/services/projects/update_mirror_service_spec.rb
View file @
1800a854
...
...
@@ -55,6 +55,8 @@ describe Projects::UpdateMirrorService do
end
describe
"updating branches"
do
subject
{
described_class
.
new
(
project
,
project
.
owner
)
}
context
'when mirror only protected branches option is set'
do
let
(
:new_protected_branch_name
)
{
'new-branch'
}
let
(
:protected_branch_name
)
{
'existing-branch'
}
...
...
@@ -69,7 +71,7 @@ describe Projects::UpdateMirrorService do
stub_fetch_mirror
(
project
)
described_class
.
new
(
project
,
project
.
owner
)
.
execute
subject
.
execute
expect
(
project
.
repository
.
branch_names
).
to
include
(
new_protected_branch_name
)
end
...
...
@@ -88,7 +90,7 @@ describe Projects::UpdateMirrorService do
stub_fetch_mirror
(
project
)
described_class
.
new
(
project
,
project
.
owner
)
.
execute
subject
.
execute
expect
(
project
.
repository
.
find_branch
(
protected_branch_name
).
dereferenced_target
)
.
to
eq
(
project
.
repository
.
find_branch
(
'master'
).
dereferenced_target
)
...
...
@@ -97,7 +99,7 @@ describe Projects::UpdateMirrorService do
it
"does not update unprotected branches"
do
stub_fetch_mirror
(
project
)
described_class
.
new
(
project
,
project
.
owner
)
.
execute
subject
.
execute
expect
(
project
.
repository
.
find_branch
(
protected_branch_name
).
dereferenced_target
)
.
not_to
eq
(
project
.
repository
.
find_branch
(
'master'
).
dereferenced_target
)
...
...
@@ -107,7 +109,7 @@ describe Projects::UpdateMirrorService do
it
"creates new branches"
do
stub_fetch_mirror
(
project
)
described_class
.
new
(
project
,
project
.
owner
)
.
execute
subject
.
execute
expect
(
project
.
repository
.
branch_names
).
to
include
(
'new-branch'
)
end
...
...
@@ -115,19 +117,49 @@ describe Projects::UpdateMirrorService do
it
"updates existing branches"
do
stub_fetch_mirror
(
project
)
described_class
.
new
(
project
,
project
.
owner
)
.
execute
subject
.
execute
expect
(
project
.
repository
.
find_branch
(
'existing-branch'
).
dereferenced_target
)
.
to
eq
(
project
.
repository
.
find_branch
(
'master'
).
dereferenced_target
)
end
it
"doesn't update diverged branches"
do
stub_fetch_mirror
(
project
)
context
'with diverged branches'
do
before
do
stub_fetch_mirror
(
project
)
end
described_class
.
new
(
project
,
project
.
owner
).
execute
context
'when mirror_overwrites_diverged_branches is true'
do
it
'update diverged branches'
do
project
.
mirror_overwrites_diverged_branches
=
true
expect
(
project
.
repository
.
find_branch
(
'markdown'
).
dereferenced_target
)
.
not_to
eq
(
project
.
repository
.
find_branch
(
'master'
).
dereferenced_target
)
subject
.
execute
expect
(
project
.
repository
.
find_branch
(
'markdown'
).
dereferenced_target
)
.
to
eq
(
project
.
repository
.
find_branch
(
'master'
).
dereferenced_target
)
end
end
context
'when mirror_overwrites_diverged_branches is false'
do
it
"doesn't update diverged branches"
do
project
.
mirror_overwrites_diverged_branches
=
false
subject
.
execute
expect
(
project
.
repository
.
find_branch
(
'markdown'
).
dereferenced_target
)
.
not_to
eq
(
project
.
repository
.
find_branch
(
'master'
).
dereferenced_target
)
end
end
context
'when mirror_overwrites_diverged_branches is nil'
do
it
"doesn't update diverged branches"
do
project
.
mirror_overwrites_diverged_branches
=
nil
subject
.
execute
expect
(
project
.
repository
.
find_branch
(
'markdown'
).
dereferenced_target
)
.
not_to
eq
(
project
.
repository
.
find_branch
(
'master'
).
dereferenced_target
)
end
end
end
describe
'when project is empty'
do
...
...
@@ -139,7 +171,7 @@ describe Projects::UpdateMirrorService do
allow
(
project
).
to
receive
(
:fetch_mirror
)
{
create_file
(
repository
)
}
expect
(
CreateBranchService
).
not_to
receive
(
:create_master_branch
)
described_class
.
new
(
project
,
project
.
owner
)
.
execute
subject
.
execute
expect
(
repository
.
branch_names
).
not_to
include
(
'master'
)
end
...
...
lib/gitlab/git/repository.rb
View file @
1800a854
...
...
@@ -939,6 +939,10 @@ module Gitlab
nil
end
def
update_branch
(
user
,
branch_name
,
newrev
,
oldrev
)
Gitlab
::
Git
::
OperationService
.
new
(
user
,
self
).
update_branch
(
branch_name
,
newrev
,
oldrev
)
end
AUTOCRLF_VALUES
=
{
"true"
=>
true
,
"false"
=>
false
,
...
...
lib/gitlab/import_export/import_export.yml
View file @
1800a854
...
...
@@ -111,6 +111,7 @@ excluded_attributes:
-
:remote_mirror_available_overridden
-
:only_mirror_protected_branches
-
:pull_mirror_available_overridden
-
:mirror_overwrites_diverged_branches
snippets
:
-
:expired_at
merge_request_diff
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment