Skip to content

Support retrieve first commit timestamp with follow mode #90

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 2 commits into from
Jul 2, 2022
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
2 changes: 1 addition & 1 deletion mkdocs_git_revision_date_localized_plugin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def get_git_commit_timestamp(
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
realpath, date="unix", format="%at", diff_filter="A", no_show_signature=True, follow=True
)
# A file can be created multiple times, through a file renamed.
# Commits are ordered with most recent commit first
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/basic_project/docs/page_with_renamed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Page for testing creation date follow mode
19 changes: 17 additions & 2 deletions tests/test_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,16 @@ def setup_commit_history(testproject_path):
repo.git.add("docs/page_with_tag.md")
repo.git.commit(message="update homepage", author=author, date="1642911026") # Sun Jan 23 2022 04:10:26 GMT+0000

bf_file_name = os.path.join(testproject_path, "docs/page_with_renamed.md")
af_file_name = os.path.join(testproject_path, "docs/subfolder/page_with_renamed.md")
# Since git.mv would actually remove the file, move page_with_renamed.md back to docs if it has been moved
if os.path.exists(af_file_name):
os.replace(af_file_name, bf_file_name)
repo.git.add("docs/page_with_renamed.md")
repo.git.commit(message="page_with_renamed.md before renamed", author=author, date="1655229469") # Tue Jun 14 2022 17:57:49 GMT+0000
repo.git.mv("docs/page_with_renamed.md", "docs/subfolder/page_with_renamed.md")
repo.git.commit(message="page_with_renamed.md after renamed", author=author, date="1655229515") # Tue Jun 14 2022 17:58:35 GMT+0000

repo.git.add("docs/first_page.md")
repo.git.commit(message="first page", author=author, date="1500854705") # Mon Jul 24 2017 00:05:05 GMT+0000
file_name = os.path.join(testproject_path, "docs/first_page.md")
Expand Down Expand Up @@ -254,6 +264,11 @@ def validate_build(testproject_path, plugin_config: dict = {}):
searches = [x in contents for x in date_formats.values()]
assert any(searches), "No correct creation date formats output was found"

commit_timestamp=repo.get_git_commit_timestamp(
path=str(testproject_path / "docs/subfolder/page_with_renamed.md"),
is_first_commit=True
)
assert commit_timestamp == 1655229469

def validate_mkdocs_file(temp_path: str, mkdocs_yml_file: str):
"""
Expand Down Expand Up @@ -355,10 +370,10 @@ def test_tags_are_replaced(tmp_path, mkdocs_file):
pytest.skip("Not necessary to test the JS library")

# Make sure count_commits() works
# We created 8 commits in setup_commit_history()
# We created 10 commits in setup_commit_history()
with working_directory(testproject_path):
u = Util()
assert commit_count(u._get_repo("docs/page_with_tag.md")) == 8
assert commit_count(u._get_repo("docs/page_with_tag.md")) == 10


# the revision date was in 'setup_commit_history' was set to 1642911026 (Sun Jan 23 2022 04:10:26 GMT+0000)
Expand Down