Skip to content

Option for excluding rename commits from last update #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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