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

Diff for: git/cmd.py

+16-8
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)