summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDouglas Barbosa Alexandre <dbalexandre@gmail.com>2018-09-10 16:12:49 -0300
committerDouglas Barbosa Alexandre <dbalexandre@gmail.com>2018-09-10 16:12:49 -0300
commit8850fb9d671635178c2ef307dcf8df083a7285d6 (patch)
treed2a64514195199e04386499bf4c843888b43b96e /app
parent7f0a346ecd48e814eb44741ff30edf5eda3413b8 (diff)
downloadgitlab-ce-8850fb9d671635178c2ef307dcf8df083a7285d6.tar.gz
Synchronize the default branch when updating a remote mirror
Diffstat (limited to 'app')
-rw-r--r--app/models/project.rb6
-rw-r--r--app/models/repository.rb1
-rw-r--r--app/services/projects/update_remote_mirror_service.rb5
3 files changed, 10 insertions, 2 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 45cf527d7c6..8928bffd36c 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -2063,6 +2063,12 @@ class Project < ActiveRecord::Base
auto_cancel_pending_pipelines == 'enabled'
end
+ # Update the default branch querying the remote to determine its HEAD
+ def update_root_ref(remote_name)
+ root_ref = repository.find_remote_root_ref(remote_name)
+ change_head(root_ref) if root_ref.present? && root_ref != default_branch
+ end
+
private
def rename_or_migrate_repository!
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 929d28b9d88..e98021af818 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -24,6 +24,7 @@ class Repository
delegate :ref_name_for_sha, to: :raw_repository
delegate :bundle_to_disk, to: :raw_repository
+ delegate :find_remote_root_ref, to: :raw_repository
CreateTreeError = Class.new(StandardError)
diff --git a/app/services/projects/update_remote_mirror_service.rb b/app/services/projects/update_remote_mirror_service.rb
index 591b38b8151..85b9eb02803 100644
--- a/app/services/projects/update_remote_mirror_service.rb
+++ b/app/services/projects/update_remote_mirror_service.rb
@@ -5,13 +5,14 @@ module Projects
attr_reader :errors
def execute(remote_mirror)
- @errors = []
-
return success unless remote_mirror.enabled?
+ errors = []
+
begin
remote_mirror.ensure_remote!
repository.fetch_remote(remote_mirror.remote_name, no_tags: true)
+ project.update_root_ref(remote_mirror.remote_name)
opts = {}
if remote_mirror.only_protected_branches?