Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fails on import with custom exception #637

Copy link
Copy link

Description

@vidartf
Issue body actions

On Windows, without git available on path, the following happens on import of GitPython:

[package stack]
    from git.exc import GitError
  File "C:\Miniconda3\lib\site-packages\git\__init__.py", line 45, in <module>
    from git.repo import Repo               # @NoMove @IgnorePep8
  File "C:\Miniconda3\lib\site-packages\git\repo\__init__.py", line 4, in <module>
    from .base import *
  File "C:\Miniconda3\lib\site-packages\git\repo\base.py", line 31, in <module>
    from git.remote import Remote, add_progress, to_progress_instance
  File "C:\Miniconda3\lib\site-packages\git\remote.py", line 190, in <module>
    class FetchInfo(object):
  File "C:\Miniconda3\lib\site-packages\git\remote.py", line 219, in FetchInfo
    v = Git().version_info[:2]
  File "C:\Miniconda3\lib\site-packages\git\cmd.py", line 461, in version_info
    return self._version_info
  File "C:\Miniconda3\lib\site-packages\git\cmd.py", line 424, in __getattr__
    return LazyMixin.__getattr__(self, name)
  File "C:\Miniconda3\lib\site-packages\gitdb\util.py", line 256, in __getattr__
    self._set_cache_(attr)
  File "C:\Miniconda3\lib\site-packages\git\cmd.py", line 444, in _set_cache_
    version_numbers = self._call_process('version').split(' ')[2]
  File "C:\Miniconda3\lib\site-packages\git\cmd.py", line 877, in _call_process
    return self.execute(call, **exec_kwargs)
  File "C:\Miniconda3\lib\site-packages\git\cmd.py", line 602, in execute
    raise GitCommandNotFound(command, err)
git.exc.GitCommandNotFound: Cmd('git') not found due to: FileNotFoundError('[WinError 2] The system cannot find the file specified')
  cmdline: git version

Since it fails while trying to import the exception type that it raises (GitError), the only way to catch the error is with a try: ... except Exception: block, which is needlessly wide. It would be nice if a better pattern was available for conditional use of the package.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.