Skip to content

Commit 05de5c0

Browse files
committed
Implement instance USE_SHELL lookup in __getattr__
This is with the intention of making it so that Git.USE_SHELL is unittest.mock.patch patchable. However, while this moves in the right direction, it can't be done this way, as the attribute is found to be absent on the class, so when unittest.mock.patch unpatches, it tries to delete the attribute it has set, which fails due to the metaclass's USE_SHELL instance property having no deleter.
1 parent d38e721 commit 05de5c0

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

Diff for: git/cmd.py

+20-18
Original file line numberDiff line numberDiff line change
@@ -399,28 +399,25 @@ def __setstate__(self, d: Dict[str, Any]) -> None:
399399

400400
_USE_SHELL: bool = False
401401

402-
@property
403-
def USE_SHELL(self) -> bool:
404-
"""Deprecated. If set to ``True``, a shell will be used to execute git commands.
402+
USE_SHELL: bool
403+
"""Deprecated. If set to ``True``, a shell will be used to execute git commands.
405404
406-
Prior to GitPython 2.0.8, this had a narrow purpose in suppressing console
407-
windows in graphical Windows applications. In 2.0.8 and higher, it provides no
408-
benefit, as GitPython solves that problem more robustly and safely by using the
409-
``CREATE_NO_WINDOW`` process creation flag on Windows.
405+
Prior to GitPython 2.0.8, this had a narrow purpose in suppressing console windows
406+
in graphical Windows applications. In 2.0.8 and higher, it provides no benefit, as
407+
GitPython solves that problem more robustly and safely by using the
408+
``CREATE_NO_WINDOW`` process creation flag on Windows.
410409
411-
Code that uses ``USE_SHELL = True`` or that passes ``shell=True`` to any
412-
GitPython functions should be updated to use the default value of ``False``
413-
instead. ``True`` is unsafe unless the effect of shell expansions is fully
414-
considered and accounted for, which is not possible under most circumstances.
410+
Code that uses ``USE_SHELL = True`` or that passes ``shell=True`` to any GitPython
411+
functions should be updated to use the default value of ``False`` instead. ``True``
412+
is unsafe unless the effect of shell expansions is fully considered and accounted
413+
for, which is not possible under most circumstances.
415414
416-
See:
415+
See:
417416
418-
- :meth:`Git.execute` (on the ``shell`` parameter).
419-
- https://github.com/gitpython-developers/GitPython/commit/0d9390866f9ce42870d3116094cd49e0019a970a
420-
- https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags
421-
"""
422-
_warn_use_shell(False)
423-
return self._USE_SHELL
417+
- :meth:`Git.execute` (on the ``shell`` parameter).
418+
- https://github.com/gitpython-developers/GitPython/commit/0d9390866f9ce42870d3116094cd49e0019a970a
419+
- https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags
420+
"""
424421

425422
_git_exec_env_var = "GIT_PYTHON_GIT_EXECUTABLE"
426423
_refresh_env_var = "GIT_PYTHON_REFRESH"
@@ -921,6 +918,11 @@ def __getattr__(self, name: str) -> Any:
921918
"""
922919
if name.startswith("_"):
923920
return super().__getattribute__(name)
921+
922+
if name == "USE_SHELL":
923+
_warn_use_shell(False)
924+
return self._USE_SHELL
925+
924926
return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
925927

926928
def set_persistent_git_options(self, **kwargs: Any) -> None:

0 commit comments

Comments
 (0)