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

docs: Document how to fetch additional branches #10795

Merged

Conversation

stephenfin
Copy link
Contributor

@stephenfin stephenfin commented Oct 4, 2023

Tools like reno depend on a complete git history. Simply unshallowing a clone is not sufficient, as we specifically fetch from the branch or tag that we are building docs for, e.g.:

git fetch origin --force --prune --prune-tags --depth 50 refs/heads/main:refs/remotes/origin/main

Add documentation describing how you can correct this if necessary.


📚 Documentation previews 📚

Tools like reno depend on a complete git history. Simply unshallowing a
clone is not sufficient, as we specifically fetch from the branch or tag
that we are building docs for, e.g.:

   git fetch origin --force --prune --prune-tags --depth 50 refs/heads/main:refs/remotes/origin/main

Add documentation describing how you can correct this if necessary.

Signed-off-by: Stephen Finucane <stephen@that.guru>
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution. If there's a specific tool that this is useful for, it's probably worth mentioning in the text, so it's easier to Google for.

jobs:
post_checkout:
- git fetch --unshallow || true
- git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*' || true
Copy link
Member

Choose a reason for hiding this comment

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

Why is this line required? Seems pretty specific to a use case, and something I'd expect git to do by default?

Copy link
Contributor Author

@stephenfin stephenfin Oct 7, 2023

Choose a reason for hiding this comment

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

This is necessary because we're configuring git to only fetch a single branch in this command (which you'll see a variant of in all builds):

git fetch origin --force --prune --prune-tags --depth 50 refs/heads/main:refs/remotes/origin/main

If you shallow clone a repo then run the above locally and look at .git/config, you'll see something like the following:

[remote "origin"]
fetch = +refs/heads/main:refs/remotes/origin/main

Which means "map the main ref locally to the main remote ref". Because we've limited fetch to a single branch, we will always get just that single branch no matter what flags we pass. To fix this, you need to tell git to fetch all branches and map them to the same name locally, which is what we're doing here.

Perhaps there's another way to override the config file during a fetch operation, but if there is I'm not aware of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, and as I mentioned in the blurb beforehand, you'll need to do this if you have a tool that needs access to other branches rather than just other tags.

Copy link
Member

Choose a reason for hiding this comment

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

Gotcha -- Thanks!

@ericholscher ericholscher merged commit 277a5a4 into readthedocs:main Oct 24, 2023
3 checks passed
@stephenfin stephenfin deleted the docs/fetch-additional-actions branch October 26, 2023 11:29
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.

2 participants