Skip to content

Commit be8f4de

Browse files
ericholschersaadmk11
authored andcommitted
Sync External versions to our database
This is just an initial proof of concept. We still need to update the External type properly, and do lots of other work. This is just a start to show how we can sync and build them.
1 parent 0beaad6 commit be8f4de

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

readthedocs/projects/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,8 @@
333333
'https://gitlab.com/{user}/{repo}/'
334334
'{action}/{version}{docroot}{path}{source_suffix}'
335335
)
336+
337+
DEFAULT_GIT_PATTERN = 'refs/heads/*:refs/remotes/origin/*'
338+
GITHUB_GIT_PATTERN = 'refs/pull/*/head:refs/remotes/origin/external/*'
339+
GITLAB_GIT_PATTERN = 'refs/merge-requests/*/head:refs/remotes/origin/external/*'
340+
BITBUCKET_GIT_PATTERN = 'refs/pull/*/head:refs/remotes/origin/external/*'

readthedocs/vcs_support/backends/git.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from git.exc import BadName, InvalidGitRepositoryError
1212

1313
from readthedocs.config import ALL
14+
from readthedocs.projects.constants import GITHUB_GIT_PATTERN, DEFAULT_GIT_PATTERN
1415
from readthedocs.projects.exceptions import RepositoryError
1516
from readthedocs.projects.validators import validate_submodule_url
1617
from readthedocs.vcs_support.base import BaseVCS, VCSVersion
@@ -55,9 +56,12 @@ def update(self):
5556
super().update()
5657
if self.repo_exists():
5758
self.set_remote_url(self.repo_url)
58-
return self.fetch()
59+
self.fetch()
60+
return
5961
self.make_clean_working_dir()
60-
return self.clone()
62+
self.clone()
63+
# Do a fetch to make sure we get all external versions
64+
self.fetch()
6165

6266
def repo_exists(self):
6367
try:
@@ -144,7 +148,8 @@ def use_shallow_clone(self):
144148
return not self.project.has_feature(Feature.DONT_SHALLOW_CLONE)
145149

146150
def fetch(self):
147-
cmd = ['git', 'fetch', '--tags', '--prune', '--prune-tags']
151+
cmd = ['git', 'fetch', 'origin', DEFAULT_GIT_PATTERN, GITHUB_GIT_PATTERN,
152+
'--tags', '--prune', '--prune-tags']
148153

149154
if self.use_shallow_clone():
150155
cmd.extend(['--depth', str(self.repo_depth)])

0 commit comments

Comments
 (0)