Skip to content

Commit

Permalink
Resolve tags in Commit constructor
Browse files Browse the repository at this point in the history
`bark` currently fails to run if there are annotated tags in the repository.
Lightweight tags work, though.

First off, no tags works:
```
$ poetry run -- bark -l debug setup
INFO 19:20:37.605 [gitbark.logging.set_log_level:18] Logging at level: DEBUG
Define what Bark Modules to add!

Module to add (leave blank to skip): ^CAborted!
```

A lightweight tag also does not interfere:
```
$ git tag tag-lightweight
$ poetry run -- bark -l debug setup
INFO 19:20:58.889 [gitbark.logging.set_log_level:18] Logging at level: DEBUG
Define what Bark Modules to add!

Module to add (leave blank to skip): ^CAborted!
```

But an annotated tag does make `bark` crash on startup:

```
$ git tag tag-annotated -m "TEST"
$ poetry run -- bark -l debug setup
INFO 19:21:09.945 [gitbark.logging.set_log_level:18] Logging at level: DEBUG
ERROR 19:21:09.964 [gitbark.cli.__main__.main:333] An unexpected error occured.
Traceback (most recent call last):
  File "/home/emlun/dev/gitbark/gitbark/cli/__main__.py", line 324, in main
    cli(obj={})
  File "/home/emlun/.cache/pypoetry/virtualenvs/gitbark-X6l5axH9-py3.11/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emlun/.cache/pypoetry/virtualenvs/gitbark-X6l5axH9-py3.11/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/home/emlun/.cache/pypoetry/virtualenvs/gitbark-X6l5axH9-py3.11/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emlun/.cache/pypoetry/virtualenvs/gitbark-X6l5axH9-py3.11/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emlun/.cache/pypoetry/virtualenvs/gitbark-X6l5axH9-py3.11/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emlun/.cache/pypoetry/virtualenvs/gitbark-X6l5axH9-py3.11/lib/python3.11/site-packages/click/decorators.py", line 26, in new_func
    return f(get_current_context(), *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emlun/dev/gitbark/gitbark/cli/__main__.py", line 120, in setup
    setup_cmd(project)
  File "/home/emlun/dev/gitbark/gitbark/commands/setup.py", line 304, in setup
    if not has_valid_bark_rules(project):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emlun/dev/gitbark/gitbark/commands/setup.py", line 119, in has_valid_bark_rules
    if BARK_RULES_REF in project.repo.references:
                         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emlun/dev/gitbark/gitbark/git.py", line 201, in references
    return {
           ^
  File "/home/emlun/dev/gitbark/gitbark/git.py", line 202, in <dictcomp>
    ref.name: Commit(ref.resolve().target.raw, self)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/emlun/dev/gitbark/gitbark/git.py", line 76, in __init__
    raise ValueError(f"No commit found with hash {hash.hex()}")
ValueError: No commit found with hash 75b81168733bfc515e7204d5be9767ccb1dc2be5
```
  • Loading branch information
emlun committed Jan 24, 2024
1 parent 5bd4951 commit 133306e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions gitbark/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from .objects import RuleData
from .util import cmd

from pygit2 import Commit as _Commit, Tree, Repository as _Repository
from pygit2 import Commit as _Commit, Tree, Repository as _Repository, Tag as _Tag
from typing import Union, Tuple, Optional
import yaml
import re
Expand Down Expand Up @@ -72,7 +72,9 @@ def __init__(self, hash: bytes, repo: "Repository") -> None:
if not isinstance(hash, bytes):
raise ValueError(f"Commit hash is not bytes {hash}")
self._object: _Commit = repo._object.get(hash.hex())
if not isinstance(self._object, _Commit):
if isinstance(self._object, _Tag):
self._object = self._object.get_object()
if not isinstance(self._object, (_Commit, _Tag)):
raise ValueError(f"No commit found with hash {hash.hex()}")

@property
Expand Down

0 comments on commit 133306e

Please sign in to comment.