Skip to content
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

Improve error message for dubious git ownership #109

Open
timvink opened this issue Mar 1, 2023 · 2 comments
Open

Improve error message for dubious git ownership #109

timvink opened this issue Mar 1, 2023 · 2 comments

Comments

@timvink
Copy link
Owner

timvink commented Mar 1, 2023

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

@alexef
Copy link

alexef commented May 11, 2023

@timvink sorry, how did you fallback to builddate?

@timvink
Copy link
Owner Author

timvink commented May 22, 2023

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:

except GitCommandError as err:
if self.config.get('fallback_to_build_date'):
log(
"[git-revision-date-localized-plugin] Unable to read git logs of '%s'. Is git log readable?"
" Option 'fallback_to_build_date' set to 'true': Falling back to build date"
% path
)
commit_timestamp = time.time()

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants