From 0b39da6869dff49da135f8a63cda290e6830eca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Cab=C3=A9?= Date: Thu, 23 Nov 2023 14:02:19 +0100 Subject: [PATCH] doc: Do not fail when manually authored doc file is not tracked by git MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a bug where a newly created documentation file not yet tracked by git would cause the documentation generation to fail. Signed-off-by: Benjamin Cabé --- doc/_extensions/zephyr/gh_utils.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/doc/_extensions/zephyr/gh_utils.py b/doc/_extensions/zephyr/gh_utils.py index 6ba75ce5ab7c..38c5cff316ea 100644 --- a/doc/_extensions/zephyr/gh_utils.py +++ b/doc/_extensions/zephyr/gh_utils.py @@ -173,7 +173,8 @@ def git_info_filter(app: Sphinx, pagename) -> Optional[Tuple[str, str]]: Returns: Optional[Tuple[str, str]] -- Tuple with the date and SHA1 of the last commit made to the - page, or None if the page is not in the repo. + page, or None if the page is not in the repo (generated file, or manually authored file not + yet tracked by git). """ page_prefix = get_page_prefix(app, pagename) @@ -186,6 +187,15 @@ def git_info_filter(app: Sphinx, pagename) -> Optional[Tuple[str, str]]: app.env.doc2path(pagename, False), ) + # Check if the file is tracked by git + try: + subprocess.check_output( + ["git", "ls-files", "--error-unmatch", orig_path], + stderr=subprocess.STDOUT, + ) + except subprocess.CalledProcessError: + return None + try: date_and_sha1 = ( subprocess.check_output( @@ -212,7 +222,6 @@ def git_info_filter(app: Sphinx, pagename) -> Optional[Tuple[str, str]]: except subprocess.CalledProcessError: return None - def add_jinja_filter(app: Sphinx): if app.builder.format != "html": return