Skip to content

Commit f1b7fd6

Browse files
authored
VCS: remove unused methods and make new Git pattern the default (#8968)
* VCS: remove unused methods to "update" an existing copy * VCS backends: minor update to Git * Lint: pre-commit * VCS git: keep return code and stdout * Minor updates * VCS: make new Git pattern the default Remove `GIT_CLONE_FETCH_CHECKOUT_PATTERN` feature flag and always use it. We have been testing this new pattern and it has been working great. * Remove `set_remote_url` which is not being used anymore * Update some tests * VCS: remove `GitPython` We are not depending on GitPython anymore. With the introduction of `git ls-remote` we don't require to parse the repository anymore and GitPython is not required. This commit also removes the methods `.branches` and `.tags` that are not used anymore when using Git as VCS backend. * Remove shallow clone repository test * More defensive logic and tests updated * Update common/ * Delete old tests * Remove `_skip_fetch` that wasn't used
1 parent 2f4334d commit f1b7fd6

File tree

16 files changed

+39
-654
lines changed

16 files changed

+39
-654
lines changed

readthedocs/projects/models.py

-7
Original file line numberDiff line numberDiff line change
@@ -1961,7 +1961,6 @@ def add_features(sender, **kwargs):
19611961
INDEX_FROM_HTML_FILES = 'index_from_html_files'
19621962

19631963
# Build related features
1964-
GIT_CLONE_FETCH_CHECKOUT_PATTERN = "git_clone_fetch_checkout_pattern"
19651964
HOSTING_INTEGRATIONS = "hosting_integrations"
19661965
SCALE_IN_PROTECTION = "scale_in_prtection"
19671966

@@ -2090,12 +2089,6 @@ def add_features(sender, **kwargs):
20902089
"sources"
20912090
),
20922091
),
2093-
(
2094-
GIT_CLONE_FETCH_CHECKOUT_PATTERN,
2095-
_(
2096-
"Build: Use simplified and optimized git clone + git fetch + git checkout patterns"
2097-
),
2098-
),
20992092
(
21002093
HOSTING_INTEGRATIONS,
21012094
_(

readthedocs/projects/tasks/mixins.py

+3-16
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,6 @@ def sync_versions(self, vcs_repository):
4141
# and just validate them trigger the task. All the other logic should
4242
# be done by the BuildDirector or the VCS backend. We should not
4343
# check this here and do not depend on ``vcs_repository``.
44-
45-
# Do not use ``ls-remote`` if the VCS does not support it or if we
46-
# have already cloned the repository locally. The latter happens
47-
# when triggering a normal build.
48-
# Always use lsremote when we have GIT_CLONE_FETCH_CHECKOUT_PATTERN on
49-
# and the repo supports lsremote.
50-
# The new pattern does not fetch branch and tag data, so we always
51-
# have to do ls-remote.
52-
use_lsremote = vcs_repository.supports_lsremote and (
53-
self.data.project.has_feature(Feature.GIT_CLONE_FETCH_CHECKOUT_PATTERN)
54-
or not vcs_repository.repo_exists()
55-
)
5644
sync_tags = vcs_repository.supports_tags and not self.data.project.has_feature(
5745
Feature.SKIP_SYNC_TAGS
5846
)
@@ -62,15 +50,14 @@ def sync_versions(self, vcs_repository):
6250
)
6351
tags = []
6452
branches = []
65-
if use_lsremote:
53+
if vcs_repository.supports_lsremote:
6654
branches, tags = vcs_repository.lsremote(
6755
include_tags=sync_tags,
6856
include_branches=sync_branches,
6957
)
7058

71-
# GIT_CLONE_FETCH_CHECKOUT_PATTERN: When the feature flag becomes default, we
72-
# can remove this segment since lsremote is always on.
73-
# We can even factor out the dependency to gitpython.
59+
# Remove this block once we drop support for Bazaar, SVG and Mercurial.
60+
# Since we will only support Git, lsremote will be always available.
7461
else:
7562
if sync_tags:
7663
tags = vcs_repository.tags

readthedocs/projects/tests/mockers.py

-16
Original file line numberDiff line numberDiff line change
@@ -140,25 +140,9 @@ def _mock_git_repository(self):
140140
return_value=self.project_repository_path,
141141
)
142142

143-
def _repo_exists_side_effect(*args, **kwargs):
144-
if self._counter == 0:
145-
# TODO: create a miniamal git repository nicely or mock `git.Repo` if possible
146-
os.system(f'cd {self.project_repository_path} && git init')
147-
self._counter += 1
148-
return False
149-
150-
self._counter += 1
151-
return True
152-
153-
154143
self.patches['git.Backend.make_clean_working_dir'] = mock.patch(
155144
'readthedocs.vcs_support.backends.git.Backend.make_clean_working_dir',
156145
)
157-
self.patches['git.Backend.repo_exists'] = mock.patch(
158-
'readthedocs.vcs_support.backends.git.Backend.repo_exists',
159-
side_effect=_repo_exists_side_effect,
160-
)
161-
162146

163147
# Make a the backend to return 3 submodules when asked
164148
self.patches['git.Backend.submodules'] = mock.patch(

readthedocs/projects/tests/test_build_tasks.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,16 @@ def test_build_commands_executed(
710710

711711
self.mocker.mocks["git.Backend.run"].assert_has_calls(
712712
[
713+
mock.call("git", "clone", "--depth", "1", mock.ANY, "."),
713714
mock.call(
714-
"git", "clone", "--no-single-branch", "--depth", "50", mock.ANY, "."
715+
"git",
716+
"fetch",
717+
"origin",
718+
"--force",
719+
"--prune",
720+
"--prune-tags",
721+
"--depth",
722+
"50",
715723
),
716724
mock.call(
717725
"git",
@@ -724,6 +732,15 @@ def test_build_commands_executed(
724732
),
725733
mock.call("git", "checkout", "--force", "origin/a1b2c3"),
726734
mock.call("git", "clean", "-d", "-f", "-f"),
735+
mock.call(
736+
"git",
737+
"ls-remote",
738+
"--tags",
739+
"--heads",
740+
mock.ANY,
741+
demux=True,
742+
record=False,
743+
),
727744
]
728745
)
729746

0 commit comments

Comments
 (0)