Skip to content

Commit

Permalink
Merge pull request #148 from skywarth/master
Browse files Browse the repository at this point in the history
Option for excluding rename commits from last update
  • Loading branch information
timvink authored Oct 17, 2024
2 parents 3f39e65 + 36b2159 commit 9e064cd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
8 changes: 8 additions & 0 deletions docs/options.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/mkdocs_git_revision_date_localized_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down
9 changes: 7 additions & 2 deletions src/mkdocs_git_revision_date_localized_plugin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand Down

0 comments on commit 9e064cd

Please sign in to comment.