diff --git a/docs/options.md b/docs/options.md index 98c9f99..3eabf8c 100644 --- a/docs/options.md +++ b/docs/options.md @@ -133,6 +133,14 @@ export ENABLED_GIT_REVISION_DATE=false mkdocs serve ``` +## `enable_git_follow` + +Default is `true`. When enabled it will issue `--follow` option for git history tracing; meaning it will also track file's previous history for rename and move operations. + +When disabled (by setting it to `false`), each file's history will only consist of its current name and path, it's history from the previous paths or names will not be included. + +When enabled (by setting it to `true`), history tracking with `--follow` will be enabled and history will include the file's history from rename and other paths. + ## `strict` Default is `true`. When enabled, the logs will show warnings when something is wrong but a fallback has been used. When disabled, the logger will use the INFO level instead. diff --git a/src/mkdocs_git_revision_date_localized_plugin/plugin.py b/src/mkdocs_git_revision_date_localized_plugin/plugin.py index f0360c9..4b7fef2 100644 --- a/src/mkdocs_git_revision_date_localized_plugin/plugin.py +++ b/src/mkdocs_git_revision_date_localized_plugin/plugin.py @@ -43,6 +43,7 @@ class GitRevisionDateLocalizedPlugin(BasePlugin): ("enable_creation_date", config_options.Type(bool, default=False)), ("enabled", config_options.Type(bool, default=True)), ("strict", config_options.Type(bool, default=True)), + ("enable_git_follow", config_options.Type(bool, default=True)) ) def on_config(self, config: config_options.Config, **kwargs) -> Dict[str, Any]: diff --git a/src/mkdocs_git_revision_date_localized_plugin/util.py b/src/mkdocs_git_revision_date_localized_plugin/util.py index 1cbb474..275f6b5 100644 --- a/src/mkdocs_git_revision_date_localized_plugin/util.py +++ b/src/mkdocs_git_revision_date_localized_plugin/util.py @@ -80,10 +80,12 @@ def get_git_commit_timestamp( realpath = os.path.realpath(path) git = self._get_repo(realpath) + follow_option=self.config.get('enable_git_follow') + if is_first_commit: # diff_filter="A" will select the commit that created the file commit_timestamp = git.log( - realpath, date="unix", format="%at", diff_filter="A", no_show_signature=True, follow=True + realpath, date="unix", format="%at", diff_filter="Ar", no_show_signature=True, follow=follow_option ) # A file can be created multiple times, through a file renamed. # Commits are ordered with most recent commit first @@ -93,8 +95,11 @@ def get_git_commit_timestamp( else: # Latest commit touching a specific file commit_timestamp = git.log( - realpath, date="unix", format="%at", n=1, no_show_signature=True + realpath, date="unix", format="%at", + diff_filter="r", n=1, no_show_signature=True, follow=follow_option, + ignore_all_space=True, ignore_blank_lines=True ) + except (InvalidGitRepositoryError, NoSuchPathError) as err: if self.config.get('fallback_to_build_date'): log(