@@ -985,23 +985,31 @@ def execute(
985
985
if inline_env is not None :
986
986
env .update (inline_env )
987
987
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
+
988
994
if os .name == "nt" :
989
- cmd_not_found_exception = OSError
990
995
if kill_after_timeout is not None :
991
996
raise GitCommandError (
992
997
redacted_command ,
993
998
'"kill_after_timeout" feature is not supported on Windows.' ,
994
999
)
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" )
1000
1010
# END handle
1001
1011
1002
1012
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
1005
1013
log .debug (
1006
1014
"Popen(%s, cwd=%s, stdin=%s, shell=%s, universal_newlines=%s)" ,
1007
1015
redacted_command ,
0 commit comments