Skip to content

Commit 06bd2c7

Browse files
committed
Omit CWD in executable search even when shell=True
1 parent c1f6c17 commit 06bd2c7

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

git/cmd.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -985,23 +985,31 @@ def execute(
985985
if inline_env is not None:
986986
env.update(inline_env)
987987

988+
if shell is None:
989+
shell = self.USE_SHELL
990+
991+
cmd_not_found_exception = FileNotFoundError
992+
maybe_patch_caller_env = contextlib.nullcontext()
993+
988994
if os.name == "nt":
989-
cmd_not_found_exception = OSError
990995
if kill_after_timeout is not None:
991996
raise GitCommandError(
992997
redacted_command,
993998
'"kill_after_timeout" feature is not supported on Windows.',
994999
)
995-
# Only search PATH, not CWD. This must be in the *caller* environment. The "1" can be any value.
996-
maybe_patch_caller_env = patch_env("NoDefaultCurrentDirectoryInExePath", "1")
997-
else:
998-
cmd_not_found_exception = FileNotFoundError
999-
maybe_patch_caller_env = contextlib.nullcontext()
1000+
1001+
cmd_not_found_exception = OSError
1002+
1003+
# Search PATH, but do not search CWD. The "1" can be any value.
1004+
if shell:
1005+
# If the direct subprocess is a shell, this must go in its environment.
1006+
env["NoDefaultCurrentDirectoryInExePath"] = "1"
1007+
else:
1008+
# If we're not using a shell, the variable goes in our own environment.
1009+
maybe_patch_caller_env = patch_env("NoDefaultCurrentDirectoryInExePath", "1")
10001010
# END handle
10011011

10021012
stdout_sink = PIPE if with_stdout else getattr(subprocess, "DEVNULL", None) or open(os.devnull, "wb")
1003-
if shell is None:
1004-
shell = self.USE_SHELL
10051013
log.debug(
10061014
"Popen(%s, cwd=%s, stdin=%s, shell=%s, universal_newlines=%s)",
10071015
redacted_command,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy