Skip to content

Commit 11b4c99

Browse files
committed
Search for .git folder in docs directory first, then traverse upwards
1 parent e8d240d commit 11b4c99

File tree

2 files changed

+4
-13
lines changed

2 files changed

+4
-13
lines changed

mkdocs_git_revision_date_localized_plugin/plugin.py

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ class GitRevisionDateLocalizedPlugin(BasePlugin):
1818
("type", config_options.Type(str, default="date")),
1919
)
2020

21-
def __init__(self):
22-
self.util = Util()
23-
2421
def on_config(self, config: config_options.Config) -> dict:
2522
"""
2623
Determine which locale to use.
@@ -36,6 +33,7 @@ def on_config(self, config: config_options.Config) -> dict:
3633
Returns:
3734
dict: global configuration object
3835
"""
36+
self.util = Util(path=config["docs_dir"])
3937

4038
# Get locale settings - might be added in future mkdocs versions
4139
# see: https://github.com/timvink/mkdocs-git-revision-date-localized-plugin/issues/24
@@ -161,11 +159,3 @@ def on_page_markdown(
161159
markdown,
162160
flags=re.IGNORECASE,
163161
)
164-
165-
166-
# ##############################################################################
167-
# ##### Stand alone program ########
168-
# ##################################
169-
if __name__ == "__main__":
170-
"""Standalone execution and quick tests."""
171-
pass

mkdocs_git_revision_date_localized_plugin/util.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
# 3rd party
88
from babel.dates import format_date
9-
from git import Git, GitCommandError, GitCommandNotFound
9+
from git import Repo, Git, GitCommandError, GitCommandNotFound
1010

1111

1212
class Util:
1313
def __init__(self, path: str = "."):
14-
self.repo = Git(path)
14+
git_repo = Repo(path, search_parent_directories=True)
15+
self.repo = git_repo.git
1516

1617
# Checks when running builds on CI
1718
# See https://github.com/timvink/mkdocs-git-revision-date-localized-plugin/issues/10

0 commit comments

Comments
 (0)