Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

import git fails when current working directory is not accessible #1334

Closed
@comzyh

Description

@comzyh

Very similar to#1319
Steps to reproduce:

$ mkdir /tmp/foo$cd /tmp/foo$ chmod -x.$ python -c"import git"

Crash with:

Traceback (most recent call last):  File "/home/comzyh/.local/lib/python3.8/site-packages/git/__init__.py", line 87, in <module>    refresh()  File "/home/comzyh/.local/lib/python3.8/site-packages/git/__init__.py", line 76, in refresh    if not Git.refresh(path=path):  File "/home/comzyh/.local/lib/python3.8/site-packages/git/cmd.py", line 305, in refresh    raise ImportError(err)ImportError: Bad git executable.The git executable must be specified in one of the following ways:    - be included in your $PATH    - be set via $GIT_PYTHON_GIT_EXECUTABLE    - explicitly set via git.refresh()All git commands will error until this is rectified.This initial warning can be silenced or aggravated in the future by setting the$GIT_PYTHON_REFRESH environment variable. Use one of the following values:    - quiet|q|silence|s|none|n|0: for no warning or exception    - warn|w|warning|1: for a printed warning    - error|e|raise|r|2: for a raised exceptionExample:    export GIT_PYTHON_REFRESH=quietThe above exception was the direct cause of the following exception:Traceback (most recent call last):  File "<string>", line 1, in <module>  File "/home/comzyh/.local/lib/python3.8/site-packages/git/__init__.py", line 89, in <module>    raise ImportError('Failed to initialize: {0}'.format(exc)) from excImportError: Failed to initialize: Bad git executable.The git executable must be specified in one of the following ways:    - be included in your $PATH    - be set via $GIT_PYTHON_GIT_EXECUTABLE    - explicitly set via git.refresh()All git commands will error until this is rectified.This initial warning can be silenced or aggravated in the future by setting the$GIT_PYTHON_REFRESH environment variable. Use one of the following values:    - quiet|q|silence|s|none|n|0: for no warning or exception    - warn|w|warning|1: for a printed warning    - error|e|raise|r|2: for a raised exceptionExample:    export GIT_PYTHON_REFRESH=quiet

GitPython: 3.1.20

GitPython will run agit version when importing, but if the current workding dir is not accessible, the Popen clause will fail.

cwd=cwd,

This can be fixed by adding 2 lines after5b3669e, but I'm not sure if this fix will break some of your assumption.

# Allow the user to have the command executed in their working dir.try:cwd=self._working_diroros.getcwd()# type: Union[None, str]exceptFileNotFoundError:cwd=Noneifnotos.access(cwd,os.X_OK):cwd=None

I found this issue when I'm a previliedged user and try to switch user usingsudo su <user> and then run a Python script which need a package depending on GitPython.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp