Skip to content

Conversation

stsewd
Copy link
Member

@stsewd stsewd commented Sep 4, 2025

The basic idea is to have the value of latest in sync with the value from the default branch, which we already do. But, in case the default branch is left empty, we were falling back to master, which is just a guess of the default, so instead of guessing the value, we just don't update it if we don't know its value. When cloning the repo, we have access to the default branch, so that's when we update latest for those projects.

Note this is only relevant for projects that aren't linked to a remote repository, since for those we know the default branch. So, when we try to build the latest version of a project that doesn't have a default branch, we:

  • Omit the ref from the fetch command.
  • Use the default branch from the repository for the checkout (we could skip this step, but since we have a new feature that keeps the files from a previous clone, we need to do a checkout to make sure we are building from the given branch/commit).
  • Update the identifier from latest to the default branch we detected from the cloned repository.

There's still the problem about latest's identifier being out of sync when the default branch changes, but that's fixed after a new build, and this isn't a new problem (now users aren't blocked at least), and changing the default branch of a repo isn't something users do that often, and this only affects projects that aren't linked to a repository, so I think we are okay with that for now.

This replaces #10927
Closes #12231

Copy link

read-the-docs-community bot commented Sep 17, 2025

Documentation build overview

📚 dev | 🛠️ Build #29616556 | 📁 Comparing 8701e3c against latest (d9570fb)


🔍 Preview build

Show files changed (6 files in total): 📝 6 modified | ➕ 0 added | ➖ 0 deleted
File Status
contribute.html 📝 modified
install.html 📝 modified
search-integration.html 📝 modified
style-guide.html 📝 modified
design/embed-api.html 📝 modified
design/theme-context.html 📝 modified

Copy link

read-the-docs-community bot commented Sep 17, 2025

Documentation build overview

📚 docs | 🛠️ Build #29616557 | 📁 Comparing 8701e3c against latest (d9570fb)


🔍 Preview build

Show files changed (4 files in total): 📝 4 modified | ➕ 0 added | ➖ 0 deleted
File Status
build-customization.html 📝 modified
support.html 📝 modified
about/index.html 📝 modified
tutorial/index.html 📝 modified

Comment on lines +1184 to +1188
latest_version_identifier = (
self.versions.filter(slug=LATEST, machine=True)
.values_list("identifier", flat=True)
.first()
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is introducing an extra query for each time latest is returned in a response, since we now rely on latest having the correct value of the default branch (similar to get_original_stable_version).

@stsewd stsewd changed the title Build: skip checkout for latest when no default version is given Build: better support for empty default branch Sep 17, 2025
@humitos
Copy link
Member

humitos commented Sep 22, 2025

What happens if the default branch is main, we detect and save than, and then the user changes the default branch in GitHub to dev? Do we detect that change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Projects: can't change default branch
2 participants