bennorth / literate-git

Render hierarchical git repositories into HTML
GNU General Public License v3.0
71 stars 4 forks source link

literategit 0.4.8 runtime failure `'literategit.LeafCommit object' has no attribute 'diff'` #11

Closed chenrui333 closed 1 week ago

chenrui333 commented 1 month ago

👋 seeing some runtime failure while building literategit 0.4.8

==> git literate-render test one two create_url.CreateUrl
Traceback (most recent call last):
  File "/opt/homebrew/bin/git-literate-render", line 8, in <module>
    sys.exit(render())
             ^^^^^^^^
  File "/opt/homebrew/Cellar/literate-git/0.4.8/libexec/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/literate-git/0.4.8/libexec/lib/python3.12/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/literate-git/0.4.8/libexec/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/literate-git/0.4.8/libexec/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/literate-git/0.4.8/libexec/lib/python3.12/site-packages/literategit/cli/render.py", line 83, in render
    render_(title, begin_commit, end_commit, create_url, results)
  File "/opt/homebrew/Cellar/literate-git/0.4.8/libexec/lib/python3.12/site-packages/literategit/cli/render.py", line 66, in render_
    _print(literategit.render(sections, create_url, title, results))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/literate-git/0.4.8/libexec/lib/python3.12/site-packages/literategit/__init__.py", line 257, in render
    content = templates.content.render(nodes=nodes)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/literate-git/0.4.8/libexec/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/opt/homebrew/Cellar/literate-git/0.4.8/libexec/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/opt/homebrew/Cellar/literate-git/0.4.8/libexec/lib/python3.12/site-packages/literategit/content.html.tmpl", line 3, in top-level template code
    {% for node in nodes %}{{ node | as_html_fragment }}{% endfor %}
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/literate-git/0.4.8/libexec/lib/python3.12/site-packages/literategit/__init__.py", line 68, in as_html_fragment
    return x.as_html_fragment(self)
           ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/literate-git/0.4.8/libexec/lib/python3.12/site-packages/literategit/__init__.py", line 106, in as_html_fragment
    return template_suite.node.render(node=self)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/literate-git/0.4.8/libexec/lib/python3.12/site-packages/jinja2/environment.py", line 1304, in render
    self.environment.handle_exception()
  File "/opt/homebrew/Cellar/literate-git/0.4.8/libexec/lib/python3.12/site-packages/jinja2/environment.py", line 939, in handle_exception
    raise rewrite_traceback_stack(source=source)
  File "/opt/homebrew/Cellar/literate-git/0.4.8/libexec/lib/python3.12/site-packages/literategit/node.html.tmpl", line 25, in top-level template code
    <div class="diff">{{ node.diff | as_html_fragment }}</div>
    ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/literate-git/0.4.8/libexec/lib/python3.12/site-packages/literategit/__init__.py", line 68, in as_html_fragment
    return x.as_html_fragment(self)
           ^^^^^^^^^^^^^^^^^^
jinja2.exceptions.UndefinedError: 'literategit.LeafCommit object' has no attribute 'diff'

relates to https://github.com/Homebrew/homebrew-core/pull/177485

bennorth commented 1 month ago

Thanks for the report. I'm afraid I can't reproduce this. I don't have access to a macOS machine, but the linked Homebrew PR includes brew test --verbose literate-git failed on Linux!, so I installed Homebrew on my Linux machine. Checking out the brew-pip-audit-literate-git-1721126744 branch of homebrew-core, I could install successfully. Then brew test literate-git failed because git couldn't find my user.name or user.email. I added lines to the test do section of the formula to configure these, then brew test literate-git ran successfully.

Couple of other things:

Any ideas welcome!

branchvincent commented 1 month ago

The exception is misleading, the issue is pygit2==1.15.0 made several breaking changes (including renaming oid to id): https://github.com/libgit2/pygit2/blob/master/CHANGELOG.md#1150-2024-05-18

bennorth commented 3 weeks ago

Thanks, @branchvincent, for the pointer. I've now updated the dependency to pygit2 1.15.1, and fixed the handful of places in the code relating to those breaking changes. I've published literategit-0.5.0, which hopefully will build under Homebrew too.

branchvincent commented 3 weeks ago

Thank you @bennorth! Confirmed everything looks good on the homebrew side with https://github.com/Homebrew/homebrew-core/pull/181390

bennorth commented 1 week ago

Thanks for confirming!