Skip to content

Commit 8ea7576

Browse files
committed
Build: fix mismatch between webhook and version sync for latest
Closes #10915
1 parent 6723e59 commit 8ea7576

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

readthedocs/api/v2/views/integrations.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from rest_framework.status import HTTP_400_BAD_REQUEST
1818
from rest_framework.views import APIView
1919

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

322323

readthedocs/builds/tasks.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,13 @@ def sync_versions_task(project_pk, tags_data, branches_data, **kwargs):
359359
versions=added_versions,
360360
)
361361

362-
# Sync latest and stable to match the correct type and identifier.
363-
project.update_latest_version()
362+
# Sync latest to match the correct type and identifier
363+
# if the project has a default branch set,
364+
# otherwise the latest version was already updated in the previous step.
365+
if project.default_branch:
366+
project.update_latest_version()
364367
# TODO: move this to an automation rule
368+
# Sync stable to match the correct type and identifier.
365369
promoted_version = project.update_stable_version()
366370
new_stable = project.get_stable_version()
367371
if promoted_version and new_stable and new_stable.active:

readthedocs/vcs_support/backends/git.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def clone(self):
173173
# of the default branch. Once this case has been made redundant, we can have
174174
# --no-checkout for all clones.
175175
# --depth 1: Shallow clone, fetch as little data as possible.
176-
cmd = ["git", "clone", "--depth", "1", self.repo_url, "."]
176+
cmd = ["git", "clone", "--depth", "1", "--", self.repo_url, "."]
177177

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

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

313-
cmd = ["git", "ls-remote", *extra_args, self.repo_url]
313+
cmd = ["git", "ls-remote", *extra_args, "--", self.repo_url]
314314

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

0 commit comments

Comments
 (0)