summaryrefslogtreecommitdiff
path: root/app/models/remote_mirror.rb
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-08-22 10:43:15 -0700
committerStan Hu <stanhu@gmail.com>2018-08-22 17:02:09 -0700
commit578137f6e4817591e98019bf3e88065fae0a2879 (patch)
treedb9c2abd185dad5782d6efd7747ac4d6edbc1926 /app/models/remote_mirror.rb
parentf1315c85f91c76d308069a741db2a4a0d89d509e (diff)
downloadgitlab-ce-578137f6e4817591e98019bf3e88065fae0a2879.tar.gz
Fix remote mirrors failing if Git remotes have not been added
Remote mirrors only get created when the URL changes, However, during the GCP migration, the remote mirror did not get created automatically. Plus, there's no guarantee someone restoring a repository from backup would have this remote. We now add the remote each time we attempt to fetch from the repository. This works because Gitaly doesn't throw up an exception or error if the remote already exists: https://gitlab.com/gitlab-org/gitaly/issues/1317 In the future, we should attempt to add if the remote doesn't exist: https://gitlab.com/gitlab-org/gitaly/issues/1316 Closes #50562
Diffstat (limited to 'app/models/remote_mirror.rb')
-rw-r--r--app/models/remote_mirror.rb9
1 files changed, 9 insertions, 0 deletions
diff --git a/app/models/remote_mirror.rb b/app/models/remote_mirror.rb
index 833faf3bc82..c1f53b5da4f 100644
--- a/app/models/remote_mirror.rb
+++ b/app/models/remote_mirror.rb
@@ -150,6 +150,15 @@ class RemoteMirror < ActiveRecord::Base
result.to_s
end
+ def ensure_remote!
+ return unless project
+ return unless remote_name && url
+
+ # If this fails or the remote already exists, we won't know due to
+ # https://gitlab.com/gitlab-org/gitaly/issues/1317
+ project.repository.add_remote(remote_name, url)
+ end
+
private
def raw