summaryrefslogtreecommitdiff
path: root/git/cmd.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2015-04-08 11:43:10 +0200
committerSebastian Thiel <byronimo@gmail.com>2015-04-08 11:50:49 +0200
commit1c2dd54358dd526d1d08a8e4a977f041aff74174 (patch)
tree43b1e954c59e0a83f80a9697c4cc1b011e8fdb8f /git/cmd.py
parente9f8f159ebad405b2c08aa75f735146bb8e216ef (diff)
downloadgitpython-1c2dd54358dd526d1d08a8e4a977f041aff74174.tar.gz
fix(cmd): throw GitCommandNotFoundError ...
... if it is not found. Previously, especially on windows, this wasn't explicit. Fixes #248, affects #126
Diffstat (limited to 'git/cmd.py')
-rw-r--r--git/cmd.py46
1 files changed, 33 insertions, 13 deletions
diff --git a/git/cmd.py b/git/cmd.py
index 911bb9f3..429046be 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -26,7 +26,10 @@ from .util import (
stream_copy,
WaitGroup
)
-from .exc import GitCommandError
+from .exc import (
+ GitCommandError,
+ GitCommandNotFound
+)
from git.compat import (
string_types,
defenc,
@@ -241,6 +244,12 @@ class Git(LazyMixin):
_git_exec_env_var = "GIT_PYTHON_GIT_EXECUTABLE"
GIT_PYTHON_GIT_EXECUTABLE = os.environ.get(_git_exec_env_var, git_exec_name)
+ # If True, a shell will be used when executing git commands.
+ # This should only be desirable on windows, see https://github.com/gitpython-developers/GitPython/pull/126
+ # for more information
+ # Override this value using `Git.USE_SHELL = True`
+ USE_SHELL = False
+
class AutoInterrupt(object):
"""Kill/Interrupt the stored process instance once this instance goes out of scope. It is
@@ -543,18 +552,29 @@ class Git(LazyMixin):
env["LC_MESSAGES"] = "C"
env.update(self._environment)
- proc = Popen(command,
- env=env,
- cwd=cwd,
- stdin=istream,
- stderr=PIPE,
- stdout=PIPE,
- # Prevent cmd prompt popups on windows by using a shell ... .
- # See https://github.com/gitpython-developers/GitPython/pull/126
- shell=sys.platform == 'win32',
- close_fds=(os.name == 'posix'), # unsupported on windows
- **subprocess_kwargs
- )
+ if sys.platform == 'win32':
+ cmd_not_found_exception = WindowsError
+ else:
+ if sys.version_info[0] > 2:
+ cmd_not_found_exception = FileNotFoundError # NOQA # this is defined, but flake8 doesn't know
+ else:
+ cmd_not_found_exception = OSError
+ # end handle
+
+ try:
+ proc = Popen(command,
+ env=env,
+ cwd=cwd,
+ stdin=istream,
+ stderr=PIPE,
+ stdout=PIPE,
+ shell=self.USE_SHELL,
+ close_fds=(os.name == 'posix'), # unsupported on windows
+ **subprocess_kwargs
+ )
+ except cmd_not_found_exception as err:
+ raise GitCommandNotFound(str(err))
+
if as_process:
return self.AutoInterrupt(proc, command)