Skip to content

Commit 30f77cc

Browse files
committed
Add support for symlinks
1 parent c87530c commit 30f77cc

File tree

2 files changed

+14
-23
lines changed

2 files changed

+14
-23
lines changed

mkdocs_git_revision_date_localized_plugin/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def on_config(self, config: config_options.Config, **kwargs) -> dict:
3434
Returns:
3535
dict: global configuration object
3636
"""
37-
self.util = Util(path=config["docs_dir"], config=self.config)
37+
self.util = Util(config=self.config)
3838

3939
# Get locale settings - might be added in future mkdocs versions
4040
# see: https://github.com/timvink/mkdocs-git-revision-date-localized-plugin/issues/24

mkdocs_git_revision_date_localized_plugin/util.py

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# standard library
22
import logging
3+
import os
34
import time
45
from datetime import datetime
56

@@ -11,31 +12,20 @@
1112

1213

1314
class Util:
14-
def __init__(self, path: str = ".", config={}):
15+
def __init__(self, config={}):
1516

1617
self.fallback_enabled = False
18+
self.config = config
19+
self.repo_cache = {}
1720

18-
try:
19-
git_repo = Repo(path, search_parent_directories=True)
20-
self.repo = git_repo.git
21-
except:
22-
if config.get("fallback_to_build_date"):
23-
self.fallback_enabled = True
24-
logging.warning(
25-
"[git-revision-date-localized-plugin] Unable to find a git directory and/or git is not installed."
26-
" Option 'fallback_to_build_date' set to 'true': Falling back to build date"
27-
)
28-
return None
29-
else:
30-
logging.error(
31-
"[git-revision-date-localized-plugin] Unable to find a git directory and/or git is not installed."
32-
" To ignore this error, set option 'fallback_to_build_date: true'"
33-
)
34-
raise
21+
def _get_repo(self, path: str):
22+
if path not in self.repo_cache:
23+
self.repo_cache[path] = Repo(path, search_parent_directories=True).git
24+
# Checks if user is running builds on CI
25+
# and raise appropriate warnings
26+
raise_ci_warnings(self.repo_cache[path])
3527

36-
# Checks if user is running builds on CI
37-
# and raise appropriate warnings
38-
raise_ci_warnings(self.repo)
28+
return self.repo_cache[path]
3929

4030
@staticmethod
4131
def _date_formats(
@@ -94,7 +84,8 @@ def get_revision_date_for_file(
9484
if not self.fallback_enabled:
9585
# Retrieve author date in UNIX format (%at)
9686
# https://git-scm.com/docs/git-log#Documentation/git-log.txt-ematem
97-
unix_timestamp = self.repo.log(path, n=1, date="short", format="%at")
87+
realpath = os.path.realpath(path)
88+
unix_timestamp = self._get_repo(realpath).log(realpath, n=1, date="short", format="%at")
9889

9990
except GitCommandError as err:
10091
if fallback_to_build_date:

0 commit comments

Comments
 (0)