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

Appearance settings

Commit 3af3d43

Browse filesBrowse files
committed
Deprecate USE_SHELL; caution in Git.execute shell doc
This builds on 106bbe6 (#1782) to actually deprecate Git.USE_SHELL. Its docstring is updated to state this, but no DeprecationWarning is issued for its use at this time. The documentation for the `shell` parameter of Git.execute is also updated to caution against passing shell=True, but the deprecation is not currently extended to that parameter. Some information is duplicated across the two docstrings. I have done this because the the USE_SHELL attribute's docstring, while it is displayed by many editors, doesn't currently appear in generated HTML documentation (see #1734).
1 parent a0fa2bd commit 3af3d43
Copy full SHA for 3af3d43

File tree

1 file changed

+15
-7
lines changed
Filter options

1 file changed

+15
-7
lines changed

‎git/cmd.py

Copy file name to clipboardExpand all lines: git/cmd.py
+15-7Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,20 +280,20 @@ def __setstate__(self, d: Dict[str, Any]) -> None:
280280
"""Enables debugging of GitPython's git commands."""
281281

282282
USE_SHELL = False
283-
"""If True, a shell will be used when executing git commands.
283+
"""Deprecated. If set to True, a shell will be used when executing git commands.
284284
285-
This exists to avoid breaking old code that may access it, but it is no longer
286-
needed and should rarely if ever be used. Prior to GitPython 2.0.8, it had a narrow
287-
purpose in suppressing console windows in graphical Windows applications. In 2.0.8
288-
and higher, it provides no benefit, as GitPython solves that problem more robustly
289-
and safely by using the ``CREATE_NO_WINDOW`` process creation flag on Windows.
285+
Prior to GitPython 2.0.8, this had a narrow purpose in suppressing console windows
286+
in graphical Windows applications. In 2.0.8 and higher, it provides no benefit, as
287+
GitPython solves that problem more robustly and safely by using the
288+
``CREATE_NO_WINDOW`` process creation flag on Windows.
290289
291290
Code that uses ``USE_SHELL = True`` or that passes ``shell=True`` to any GitPython
292291
functions should be updated to use the default value of ``False`` instead. ``True``
293292
is unsafe unless the effect of shell expansions is fully considered and accounted
294293
for, which is not possible under most circumstances.
295294
296295
See:
296+
- :meth:`Git.execute` (on the ``shell`` parameter).
297297
- https://github.com/gitpython-developers/GitPython/commit/0d9390866f9ce42870d3116094cd49e0019a970a
298298
- https://learn.microsoft.com/en-us/windows/win32/procthread/process-creation-flags
299299
"""
@@ -919,7 +919,15 @@ def execute(
919919
920920
:param shell:
921921
Whether to invoke commands through a shell (see `Popen(..., shell=True)`).
922-
It overrides :attr:`USE_SHELL` if it is not `None`.
922+
If this is not `None`, it overrides :attr:`USE_SHELL`.
923+
924+
Passing ``shell=True`` to this or any other GitPython function should be
925+
avoided, as it is unsafe under most circumstances. This is because it is
926+
typically not feasible to fully consider and account for the effect of shell
927+
expansions, especially when passing ``shell=True`` to other methods that
928+
forward it to :meth:`Git.execute`. Passing ``shell=True`` is also no longer
929+
needed (nor useful) to work around any known operating system specific
930+
issues.
923931
924932
:param env:
925933
A dictionary of environment variables to be passed to :class:`subprocess.Popen`.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.