Skip to content

Commit 9e064cd

Browse files
authored
Merge pull request #148 from skywarth/master
Option for excluding rename commits from last update
2 parents 3f39e65 + 36b2159 commit 9e064cd

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

docs/options.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,14 @@ export ENABLED_GIT_REVISION_DATE=false
133133
mkdocs serve
134134
```
135135

136+
## `enable_git_follow`
137+
138+
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.
139+
140+
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.
141+
142+
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.
143+
136144
## `strict`
137145

138146
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.

src/mkdocs_git_revision_date_localized_plugin/plugin.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class GitRevisionDateLocalizedPlugin(BasePlugin):
4343
("enable_creation_date", config_options.Type(bool, default=False)),
4444
("enabled", config_options.Type(bool, default=True)),
4545
("strict", config_options.Type(bool, default=True)),
46+
("enable_git_follow", config_options.Type(bool, default=True))
4647
)
4748

4849
def on_config(self, config: config_options.Config, **kwargs) -> Dict[str, Any]:

src/mkdocs_git_revision_date_localized_plugin/util.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,12 @@ def get_git_commit_timestamp(
8080
realpath = os.path.realpath(path)
8181
git = self._get_repo(realpath)
8282

83+
follow_option=self.config.get('enable_git_follow')
84+
8385
if is_first_commit:
8486
# diff_filter="A" will select the commit that created the file
8587
commit_timestamp = git.log(
86-
realpath, date="unix", format="%at", diff_filter="A", no_show_signature=True, follow=True
88+
realpath, date="unix", format="%at", diff_filter="Ar", no_show_signature=True, follow=follow_option
8789
)
8890
# A file can be created multiple times, through a file renamed.
8991
# Commits are ordered with most recent commit first
@@ -93,8 +95,11 @@ def get_git_commit_timestamp(
9395
else:
9496
# Latest commit touching a specific file
9597
commit_timestamp = git.log(
96-
realpath, date="unix", format="%at", n=1, no_show_signature=True
98+
realpath, date="unix", format="%at",
99+
diff_filter="r", n=1, no_show_signature=True, follow=follow_option,
100+
ignore_all_space=True, ignore_blank_lines=True
97101
)
102+
98103
except (InvalidGitRepositoryError, NoSuchPathError) as err:
99104
if self.config.get('fallback_to_build_date'):
100105
log(

0 commit comments

Comments
 (0)