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

Commit1c2dd54

Browse files
committed
fix(cmd): throw GitCommandNotFoundError ...
... if it is not found. Previously, especially on windows, this wasn'texplicit.Fixes#248, affects#126
1 parente9f8f15 commit1c2dd54

File tree

3 files changed

+44
-13
lines changed

3 files changed

+44
-13
lines changed

‎doc/source/changes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ Changelog
1212
these operations to never raise. However, that behavious is undesirable as it would effectively hide the fact that there
1313
was an error. See `this issue<https://github.com/gitpython-developers/GitPython/issues/271>`_ for more information.
1414

15+
* If the git executable can't be found in the PATH or at the path provided by `GIT_PYTHON_GIT_EXECUTABLE`, this is made
16+
obvious by throwing `GitCommandNotFound`, both on unix and on windows.
17+
18+
- Those who support **GUI on windows** will now have to set `git.Git.USE_SHELL = True` to get the previous behaviour.
19+
1520
0.3.6 - Features
1621
================
1722
* **DOCS**

‎git/cmd.py

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
stream_copy,
2727
WaitGroup
2828
)
29-
from .excimportGitCommandError
29+
from .excimport (
30+
GitCommandError,
31+
GitCommandNotFound
32+
)
3033
fromgit.compatimport (
3134
string_types,
3235
defenc,
@@ -241,6 +244,12 @@ class Git(LazyMixin):
241244
_git_exec_env_var="GIT_PYTHON_GIT_EXECUTABLE"
242245
GIT_PYTHON_GIT_EXECUTABLE=os.environ.get(_git_exec_env_var,git_exec_name)
243246

247+
# If True, a shell will be used when executing git commands.
248+
# This should only be desirable on windows, see https://github.com/gitpython-developers/GitPython/pull/126
249+
# for more information
250+
# Override this value using `Git.USE_SHELL = True`
251+
USE_SHELL=False
252+
244253
classAutoInterrupt(object):
245254

246255
"""Kill/Interrupt the stored process instance once this instance goes out of scope. It is
@@ -543,18 +552,29 @@ def execute(self, command,
543552
env["LC_MESSAGES"]="C"
544553
env.update(self._environment)
545554

546-
proc=Popen(command,
547-
env=env,
548-
cwd=cwd,
549-
stdin=istream,
550-
stderr=PIPE,
551-
stdout=PIPE,
552-
# Prevent cmd prompt popups on windows by using a shell ... .
553-
# See https://github.com/gitpython-developers/GitPython/pull/126
554-
shell=sys.platform=='win32',
555-
close_fds=(os.name=='posix'),# unsupported on windows
556-
**subprocess_kwargs
557-
)
555+
ifsys.platform=='win32':
556+
cmd_not_found_exception=WindowsError
557+
else:
558+
ifsys.version_info[0]>2:
559+
cmd_not_found_exception=FileNotFoundError# NOQA # this is defined, but flake8 doesn't know
560+
else:
561+
cmd_not_found_exception=OSError
562+
# end handle
563+
564+
try:
565+
proc=Popen(command,
566+
env=env,
567+
cwd=cwd,
568+
stdin=istream,
569+
stderr=PIPE,
570+
stdout=PIPE,
571+
shell=self.USE_SHELL,
572+
close_fds=(os.name=='posix'),# unsupported on windows
573+
**subprocess_kwargs
574+
)
575+
exceptcmd_not_found_exceptionaserr:
576+
raiseGitCommandNotFound(str(err))
577+
558578
ifas_process:
559579
returnself.AutoInterrupt(proc,command)
560580

‎git/exc.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ class NoSuchPathError(OSError):
1818
""" Thrown if a path could not be access by the system. """
1919

2020

21+
classGitCommandNotFound(Exception):
22+
"""Thrown if we cannot find the `git` executable in the PATH or at the path given by
23+
the GIT_PYTHON_GIT_EXECUTABLE environment variable"""
24+
pass
25+
26+
2127
classGitCommandError(Exception):
2228
""" Thrown if execution of the git command fails with non-zero status code. """
2329

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp