|
26 | 26 | stream_copy,
|
27 | 27 | WaitGroup
|
28 | 28 | )
|
29 |
| -from .exc import GitCommandError |
| 29 | +from .exc import ( |
| 30 | + GitCommandError, |
| 31 | + GitCommandNotFound |
| 32 | +) |
30 | 33 | from git.compat import (
|
31 | 34 | string_types,
|
32 | 35 | defenc,
|
@@ -241,6 +244,12 @@ class Git(LazyMixin):
|
241 | 244 | _git_exec_env_var = "GIT_PYTHON_GIT_EXECUTABLE"
|
242 | 245 | GIT_PYTHON_GIT_EXECUTABLE = os.environ.get(_git_exec_env_var, git_exec_name)
|
243 | 246 |
|
| 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 | + |
244 | 253 | class AutoInterrupt(object):
|
245 | 254 |
|
246 | 255 | """Kill/Interrupt the stored process instance once this instance goes out of scope. It is
|
@@ -543,18 +552,29 @@ def execute(self, command,
|
543 | 552 | env["LC_MESSAGES"] = "C"
|
544 | 553 | env.update(self._environment)
|
545 | 554 |
|
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 | + if sys.platform == 'win32': |
| 556 | + cmd_not_found_exception = WindowsError |
| 557 | + else: |
| 558 | + if sys.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 | + except cmd_not_found_exception as err: |
| 576 | + raise GitCommandNotFound(str(err)) |
| 577 | + |
558 | 578 | if as_process:
|
559 | 579 | return self.AutoInterrupt(proc, command)
|
560 | 580 |
|
|
0 commit comments