timvink / mkdocs-git-revision-date-localized-plugin

MkDocs plugin to add a last updated date to your site pages
https://timvink.github.io/mkdocs-git-revision-date-localized-plugin/index.html
MIT License
198 stars 40 forks source link

get_git_commit_timestamp fails if git log shows signature #87

Closed ianrobrien closed 2 years ago

ianrobrien commented 2 years ago

Hello! I ran into an issue where get_git_commit_timestamp will fail if I have the following option set in .gitconfig

[log]
    showSignature = true

The error I get is:

File "/Users/me/my-app/.venv/lib/python3.10/site-packages/mkdocs_git_revision_date_localized_plugin/util.py", line 177, in get_git_commit_timestamp
    return int(commit_timestamp)
ValueError: invalid literal for int() with base 10: "gpg: Signature made Fri Mar  4 14:41:04 2022 CET\ngpg:                using RSA key SOMEVALUE\ngpg: Can't check signature: No public key\nSOMEOTHERVALUE"

It looks like the function could either run a git log without signature git log --no-show-signature or have logic to handle a signature.

timvink commented 2 years ago

Indeed looks like a bug! Thanks for reporting.

Fix is likely a one-liner, changing

https://github.com/timvink/mkdocs-git-revision-date-localized-plugin/blob/708128b1358d45da4aaa4629f4e1ca7df76a3236/mkdocs_git_revision_date_localized_plugin/util.py#L114-L116

to

commit_timestamp = git.log( 
     realpath, date="unix", format="%at", diff_filter="A", no_show_signature=True
 )

Would you like to provide a PR or shall I pick it up?

ianrobrien commented 2 years ago

Thanks for the quick reply! It would be better for you to pick it up as I haven't even cloned the repository yet. I don't mind making a PR if you are busy or want help but I will have to do it tomorrow. Thanks again!

ianrobrien commented 2 years ago

I made a PR for this - one of the tests is failing though but I don't think it's related to the change here. If you could run the changes on your machine and see then maybe it isn't a problem.

But otherwise I can take a look if this is a new issue. (master branch wouldn't pass the tests either)

timvink commented 2 years ago

Awesome thnx I'll have a look later this week!

timvink commented 2 years ago

Fix released in v1.0.1. Thanks @ianrobrien !