From 76e373c0259505c638020b986cf82c0268373b49 Mon Sep 17 00:00:00 2001 From: Niels Bantilan Date: Thu, 14 Dec 2023 10:57:41 -0500 Subject: [PATCH] monodocs - gracefully handle case when external repo doesn't contain tags: use current commit (#4598) --- docs/_ext/import_projects.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/_ext/import_projects.py b/docs/_ext/import_projects.py index 1cb46f08f5..214f6b5387 100644 --- a/docs/_ext/import_projects.py +++ b/docs/_ext/import_projects.py @@ -145,12 +145,20 @@ def import_projects(app: Sphinx, config: Config): local_docs_path = local_dir / project.docs_path dest_docs_dir = srcdir / project.dest - # use the latest git tag when building docs if repo: tags = sorted(repo.tags, key=lambda t: t.commit.committed_datetime) - tag = tags[-1] - update_html_context(project, str(tag), str(tag.commit)[:7], config) - repo.git.checkout(str(tag)) + if not tags: + # If tags don't exist just use the current commit. This occurs + # when the git repo is a shallow clone. + tag_str = "dev" + commit = repo.head.commit + else: + tag = tags[-1] + tag_str = str(tag) + commit = str(tag.commit)[:7] + repo.git.checkout(tag_str) + + update_html_context(project, tag_str, commit, config) if project.refresh or not dest_docs_dir.exists(): shutil.rmtree(dest_docs_dir, ignore_errors=True)