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
206 stars 44 forks source link

Issue with commit count? #46

Closed connerxyz closed 3 years ago

connerxyz commented 3 years ago

Running mkdocs-git-revision-date-localized-plugin (0.5.2) and seeing the following error.

[Container] 2021/01/07 19:59:22 Running command poetry run mkdocs build
Traceback (most recent call last):
  File "/codebuild/output/src095207431/src/github.com/tr/hx-site/.venv/bin/mkdocs", line 8, in <module>
    sys.exit(cli())
  File "/codebuild/output/src095207431/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/codebuild/output/src095207431/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/codebuild/output/src095207431/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/codebuild/output/src095207431/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/codebuild/output/src095207431/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/codebuild/output/src095207431/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/mkdocs/__main__.py", line 152, in build_command
    build.build(config.load_config(**kwargs), dirty=not clean)
  File "/codebuild/output/src095207431/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/mkdocs/commands/build.py", line 236, in build
    config = config['plugins'].run_event('config', config)
  File "/codebuild/output/src095207431/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/mkdocs/plugins.py", line 94, in run_event
    result = method(item, **kwargs)
  File "/codebuild/output/src095207431/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/mkdocs_git_revision_date_localized_plugin/plugin.py", line 36, in on_config
    self.util = Util(path=config["docs_dir"])
  File "/codebuild/output/src095207431/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/mkdocs_git_revision_date_localized_plugin/util.py", line 20, in __init__
    n_commits = commit_count(self.repo)
  File "/codebuild/output/src095207431/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/mkdocs_git_revision_date_localized_plugin/util.py", line 156, in commit_count
    refs = repo.for_each_ref().split("\n")
  File "/codebuild/output/src095207431/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/git/cmd.py", line 542, in <lambda>
    return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
  File "/codebuild/output/src095207431/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/git/cmd.py", line 1006, in _call_process
    return self.execute(call, **exec_kwargs)
  File "/codebuild/output/src095207431/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/git/cmd.py", line 823, in execute
    raise GitCommandError(command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
  cmdline: git for-each-re
timvink commented 3 years ago

Hi @connerxyz , thanks for posting a bug report!

Can you try upgrading to the latest version first? pip install --upgrade mkdocs-git-revision-date-localized-plugin

If that doesn't solve it, some additional questions:

connerxyz commented 3 years ago

Tried it with 0.8 with similar result.

[Container] 2021/01/07 20:56:27 Running command poetry run mkdocs build
--
325 | INFO    -  Cleaning site directory
326 | INFO    -  Building documentation to directory: /codebuild/output/src393512817/src/github.com/tr/hx-site/site
327 | ERROR   -  [git-revision-date-localized-plugin] Unable to read git logs of '/codebuild/output/src393512817/src/github.com/tr/hx-site/docs/index.md'.  To ignore this error, set option 'fallback_to_build_date: true'
328 | ERROR   -  Error reading page 'index.md': Cmd('git') failed due to: exit code(128)
329 | cmdline: git for-each-ref
330 | stderr: 'fatal: missing object d779ac054d402a59f34593fadb9e2102734144ae for refs/pull/3/head'
331 | Traceback (most recent call last):
332 | File "/codebuild/output/src393512817/src/github.com/tr/hx-site/.venv/bin/mkdocs", line 8, in <module>
333 | sys.exit(cli())
334 | File "/codebuild/output/src393512817/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/click/core.py", line 829, in __call__
335 | return self.main(*args, **kwargs)
336 | File "/codebuild/output/src393512817/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/click/core.py", line 782, in main
337 | rv = self.invoke(ctx)
338 | File "/codebuild/output/src393512817/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
339 | return _process_result(sub_ctx.command.invoke(sub_ctx))
340 | File "/codebuild/output/src393512817/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
341 | return ctx.invoke(self.callback, **ctx.params)
342 | File "/codebuild/output/src393512817/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/click/core.py", line 610, in invoke
343 | return callback(*args, **kwargs)
344 | File "/codebuild/output/src393512817/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/mkdocs/__main__.py", line 152, in build_command
345 | build.build(config.load_config(**kwargs), dirty=not clean)
346 | File "/codebuild/output/src393512817/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/mkdocs/commands/build.py", line 271, in build
347 | _populate_page(file.page, config, files, dirty)
348 | File "/codebuild/output/src393512817/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/mkdocs/commands/build.py", line 167, in _populate_page
349 | page.markdown = config['plugins'].run_event(
350 | File "/codebuild/output/src393512817/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/mkdocs/plugins.py", line 94, in run_event
351 | result = method(item, **kwargs)
352 | File "/codebuild/output/src393512817/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/mkdocs_git_revision_date_localized_plugin/plugin.py", line 150, in on_page_markdown
353 | revision_dates = self.util.get_revision_date_for_file(
354 | File "/codebuild/output/src393512817/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/mkdocs_git_revision_date_localized_plugin/util.py", line 135, in get_revision_date_for_file
355 | raise err
356 | File "/codebuild/output/src393512817/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/mkdocs_git_revision_date_localized_plugin/util.py", line 107, in get_revision_date_for_file
357 | unix_timestamp = self._get_repo(realpath).log(
358 | File "/codebuild/output/src393512817/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/mkdocs_git_revision_date_localized_plugin/util.py", line 43, in _get_repo
359 | raise_ci_warnings(self.repo_cache[path])
360 | File "/codebuild/output/src393512817/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/mkdocs_git_revision_date_localized_plugin/ci.py", line 21, in raise_ci_warnings
361 | n_commits = commit_count(repo)
362 | File "/codebuild/output/src393512817/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/mkdocs_git_revision_date_localized_plugin/ci.py", line 87, in commit_count
363 | refs = repo.for_each_ref().split("\n")
364 | File "/codebuild/output/src393512817/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/git/cmd.py", line 542, in <lambda>
365 | return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
366 | File "/codebuild/output/src393512817/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/git/cmd.py", line 1006, in _call_process
367 | return self.execute(call, **exec_kwargs)
368 | File "/codebuild/output/src393512817/src/github.com/tr/hx-site/.venv/lib/python3.8/site-packages/git/cmd.py", line 823, in execute
369 | raise GitCommandError(command, status, stderr_value, stdout_value)
370 | git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
371 | cmdline: git for-each-ref
372 | stderr: 'fatal: missing object d779ac054d402a59f34593fadb9e2102734144ae for refs/pull/3/head'
connerxyz commented 3 years ago

which OS are you running? aws/codebuild/amazonlinux2-x86_64-standard:3.0

Which version of python (python -V) 3.8

Does running git rev-list --count HEAD work for you (to see if you have a problem with git`) Doesn't seem to output anything.

Do you specificy any plugin options other than the defaults?

- git-revision-date-localized:  # https://squidfunk.github.io/mkdocs-material/plugins/revision-date/
      type: timeago

Which version of mkdocs are you using? run mkdocs -V mkdocs (1.1.2)

Are you using any other plugins? Can you try disabling all others? Can you paste your mkdocs.yml file?

plugins: # https://github.com/mkdocs/mkdocs/wiki/MkDocs-Plugins
  - search:                       # https://squidfunk.github.io/mkdocs-material/plugins/search/
      lang: en
      separator: '[\s\-\.]+'
      prebuild_index: true
  - minify:                       # https://squidfunk.github.io/mkdocs-material/plugins/minification/
      minify_html: true
  - git-revision-date-localized:  # https://squidfunk.github.io/mkdocs-material/plugins/revision-date/
      type: timeago
  - awesome-pages                 # https://github.com/lukasgeiter/mkdocs-awesome-pages-plugin , https://squidfunk.github.io/mkdocs-material/plugins/awesome-pages/ 
  #- tags https://github.com/jldiaz/mkdocs-plugin-tags
timvink commented 3 years ago

which OS are you running? aws/codebuild/amazonlinux2-x86_64-standard:3.0

Are you using AWS codebuild to build your docs? The problem with many build systems is that they do what's called a shallow git clone, meaning to speed up builds they do not retrieve the full git history. This plugin for every page looks at every line, and determines the date of the corresponding commit that touched that line, in order to determine when the page was last updated. See https://github.com/timvink/mkdocs-git-revision-date-localized-plugin#note-when-using-build-environments

This might also be the reason you are getting an error. I am not familiar with AWS codebuild, but you can try setting a very high value for git clone depth, or choose to do a full clone: https://docs.aws.amazon.com/codebuild/latest/userguide/run-build-console.html

connerxyz commented 3 years ago

Indeed! Ahh that makes sense. Thanks!