mkdocs-git-revision-date-localized-plugin
mkdocs-git-revision-date-localized-plugin copied to clipboard
Improve error message for dubious git ownership
I had this stacktrace:
ERROR - [git-revision-date-localized-plugin] Unable to read git logs of '/workspace/source-repo/docs'. To ignore this error, set option 'fallback_to_build_date: true'
Traceback (most recent call last):
File "/home/python/.local/bin/mkdocs", line 8, in <module>
sys.exit(cli())
File "/home/python/.local/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/home/python/.local/lib/python3.9/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/home/python/.local/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/home/python/.local/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/home/python/.local/lib/python3.9/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/home/python/.local/lib/python3.9/site-packages/mkdocs/__main__.py", line 250, in build_command
[build.build](http://build.build/)(cfg, dirty=not clean)
File "/home/python/.local/lib/python3.9/site-packages/mkdocs/commands/build.py", line 270, in build
config = config.plugins.run_event('config', config)
File "/home/python/.local/lib/python3.9/site-packages/mkdocs/plugins.py", line 520, in run_event
result = method(item, **kwargs)
File "/home/python/.local/lib/python3.9/site-packages/mkdocs_git_revision_date_localized_plugin/plugin.py", line 70, in on_config
self.last_site_revision_timestamp = self.util.get_git_commit_timestamp(
File "/home/python/.local/lib/python3.9/site-packages/mkdocs_git_revision_date_localized_plugin/util.py", line 154, in get_git_commit_timestamp
raise err
File "/home/python/.local/lib/python3.9/site-packages/mkdocs_git_revision_date_localized_plugin/util.py", line 124, in get_git_commit_timestamp
commit_timestamp = git.log(
File "/home/python/.local/lib/python3.9/site-packages/git/cmd.py", line 741, in <lambda>
return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
File "/home/python/.local/lib/python3.9/site-packages/git/cmd.py", line 1315, in _call_process
return self.execute(call, **exec_kwargs)
File "/home/python/.local/lib/python3.9/site-packages/git/cmd.py", line 1109, in execute
raise GitCommandError(redacted_command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
cmdline: git log --date=unix --format=%at -n 1 --no-show-signature /workspace/source-repo/docs
stderr: 'fatal: detected dubious ownership in repository at '/workspace/source-repo'
To add an exception for this directory, call:
git config --global --add [safe.directory](http://safe.directory/) /workspace/source-repo'
Solution is not fallback to builddate, so we should improve the error message
@timvink sorry, how did you fallback to builddate?
Sorry, should have been more clear. The error from this plugin is the first line:
ERROR - [git-revision-date-localized-plugin] Unable to read git logs of '/workspace/source-repo/docs'. To ignore this error, set option 'fallback_to_build_date: true'
That's caused by this (too generic) bit of code:
https://github.com/timvink/mkdocs-git-revision-date-localized-plugin/blob/6150fad41a83abbf7500cf9c75696c5193532305/mkdocs_git_revision_date_localized_plugin/util.py#L148-L155
The traceback actually already has the correct solution (last line):
git config --global --add [safe.directory](http://safe.directory/) /workspace/source-repo'
I created the issue to remember when I next touch this plugin, to improve the error handling, but because the "Solution is not fallback to builddate".
This issue pops up for people with newer versions of git , and the solution (that I also contributed to the mkdocs-material docker image) is basically these two lines:
# Trust directory, required for git >= 2.35.2
# Run this inside the root of your project
# Remember to update any CI/CD pipelines also
git config --global --add safe.directory /docs
git config --global --add safe.directory /site