Skip to content

Commit

Permalink
doc: Do not fail when manually authored doc file is not tracked by git
Browse files Browse the repository at this point in the history
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é <[email protected]>
  • Loading branch information
kartben authored and nashif committed Nov 25, 2023
1 parent 12cefe1 commit 0b39da6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions doc/_extensions/zephyr/gh_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand All @@ -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
Expand Down

0 comments on commit 0b39da6

Please sign in to comment.