Skip to content

Version: don't use default_branch when getting the commit name #10885

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,10 @@ def commit_name(self):
"""
# LATEST is special as it is usually a branch but does not contain the
# name in verbose_name.
if self.slug == LATEST:
return self.project.get_default_branch()
if self.slug == LATEST and self.machine:
return self.identifier

if self.slug == STABLE:
if self.slug == STABLE and self.machine:
if self.type == BRANCH:
# Special case, as we do not store the original branch name
# that the stable version works on. We can only interpolate the
Expand All @@ -356,7 +356,7 @@ def commit_name(self):
return self.identifier

# By now we must have handled all special versions.
if self.slug in NON_REPOSITORY_VERSIONS:
if self.machine and self.slug in NON_REPOSITORY_VERSIONS:
# pylint: disable=broad-exception-raised
raise Exception('All special versions must be handled by now.')

Expand Down
29 changes: 29 additions & 0 deletions readthedocs/projects/tests/test_build_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,35 @@ def test_failed_build(
assert revoke_key_request._request.method == "POST"
assert revoke_key_request.path == "/api/v2/revoke/"

@mock.patch.object(Backend, "ref_exists")
@mock.patch("readthedocs.doc_builder.director.load_yaml_config")
def test_checkout_latest(self, load_yaml_config, ref_exists):
ref_exists.return_value = False
self.version.identifier = "main"
self.version.save()
load_yaml_config.return_value = get_build_config({})

self._trigger_update_docs_task(build_commit=None)

self.mocker.mocks["git.Backend.run"].assert_has_calls(
[
mock.call("git", "clone", "--depth", "1", mock.ANY, "."),
mock.call(
"git",
"fetch",
"origin",
"--force",
"--prune",
"--prune-tags",
"--depth",
"50",
"refs/heads/main:refs/remotes/origin/main",
),
mock.call("git", "checkout", "--force", "main"),
mock.call("git", "clean", "-d", "-f", "-f"),
]
)

@mock.patch.object(Backend, "ref_exists")
@mock.patch("readthedocs.doc_builder.director.load_yaml_config")
def test_checkout_tag_by_name(self, load_yaml_config, ref_exists):
Expand Down