Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build: skip checkout step when building latest without an explicit default branch #10927

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
5 changes: 3 additions & 2 deletions readthedocs/api/v2/views/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from rest_framework.status import HTTP_400_BAD_REQUEST
from rest_framework.views import APIView

from readthedocs.builds.constants import LATEST
from readthedocs.builds.constants import BRANCH, LATEST
from readthedocs.core.signals import webhook_bitbucket, webhook_github, webhook_gitlab
from readthedocs.core.views.hooks import (
build_branches,
Expand Down Expand Up @@ -316,7 +316,8 @@ def update_default_branch(self, default_branch):
# Always check for the machine attribute, since latest can be user created.
# RTD doesn't manage those.
self.project.versions.filter(slug=LATEST, machine=True).update(
identifier=default_branch
identifier=default_branch,
type=BRANCH,
)


Expand Down
8 changes: 6 additions & 2 deletions readthedocs/builds/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,13 @@ def sync_versions_task(project_pk, tags_data, branches_data, **kwargs):
versions=added_versions,
)

# Sync latest and stable to match the correct type and identifier.
project.update_latest_version()
# Sync latest to match the correct type and identifier
# if the project has a default branch set,
# otherwise the latest version was already updated in the previous step.
if project.default_branch:
project.update_latest_version()
# TODO: move this to an automation rule
# Sync stable to match the correct type and identifier.
promoted_version = project.update_stable_version()
new_stable = project.get_stable_version()
if promoted_version and new_stable and new_stable.active:
Expand Down
6 changes: 3 additions & 3 deletions readthedocs/vcs_support/backends/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def clone(self):
# of the default branch. Once this case has been made redundant, we can have
# --no-checkout for all clones.
# --depth 1: Shallow clone, fetch as little data as possible.
cmd = ["git", "clone", "--depth", "1", self.repo_url, "."]
cmd = ["git", "clone", "--depth", "1", "--", self.repo_url, "."]

try:
# TODO: Explain or remove the return value
Expand Down Expand Up @@ -204,7 +204,7 @@ def fetch(self):
if remote_reference:
# TODO: We are still fetching the latest 50 commits.
# A PR might have another commit added after the build has started...
cmd.append(remote_reference)
cmd.extend(["--", remote_reference])

# Log a warning, except for machine versions since it's a known bug that
# we haven't stored a remote refspec in Version for those "stable" versions.
Expand Down Expand Up @@ -310,7 +310,7 @@ def lsremote(self, include_tags=True, include_branches=True):
if include_branches:
extra_args.append("--heads")

cmd = ["git", "ls-remote", *extra_args, self.repo_url]
cmd = ["git", "ls-remote", *extra_args, "--", self.repo_url]
stsewd marked this conversation as resolved.
Show resolved Hide resolved

self.check_working_dir()
_, stdout, _ = self.run(*cmd, demux=True, record=False)
Expand Down