Skip to content

error on non-existent Git repository is very non-specific #645

@dlenski

Description

@dlenski

When I try to open a Repository using a path that doesn't actually contain a Git repo, the error is a very non-specific KeyError:

>>> print(pygit2.__version__)
0.24.1
>>> os.mkdir('/tmp/foobarbaz')
>>> gitrepo=pygit2.Repository('/tmp/foobarbaz')
Traceback (most recent call last):

  File "<ipython-input-30-782283f588bb>", line 1, in <module>
    gitrepo=pygit2.Repository('/tmp/foobarbaz')

  File "/usr/local/lib/python2.7/dist-packages/pygit2/repository.py", line 64, in __init__
    super(Repository, self).__init__(path, *args, **kwargs)

KeyError: '/tmp/foobarbaz'

It would be helpful to replace this with a more specific GitError, so that the error from Git can be distinguished from a "normal" KeyError in a statement like this:

>>> repos = { "repo1":"/path/to/repo1", "repo2":"/path/to/repo2" }
>>> gitrepo = pygit2.Repository( repos["repo3"] )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions