33
44"""Standalone functions to accompany the index implementation and make it more versatile."""
55
6+ import contextlib
67from io import BytesIO
78import os
89import os .path as osp
2627 traverse_trees_recursive ,
2728 tree_to_stream ,
2829)
29- from git .util import IndexFileSHA1Writer , finalize_process
30+ from git .util import IndexFileSHA1Writer , finalize_process , patch_env
3031from gitdb .base import IStream
3132from gitdb .typ import str_tree_type
3233
@@ -90,6 +91,10 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None:
9091 env = os .environ .copy ()
9192 env ["GIT_INDEX_FILE" ] = safe_decode (str (index .path ))
9293 env ["GIT_EDITOR" ] = ":"
94+ if os .name == "nt" :
95+ maybe_patch_caller_env = patch_env ("NoDefaultCurrentDirectoryInExePath" , "1" )
96+ else :
97+ maybe_patch_caller_env = contextlib .nullcontext ()
9398 cmd = [hp ]
9499 try :
95100 if os .name == "nt" and not _has_file_extension (hp ):
@@ -98,14 +103,15 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None:
98103 relative_hp = Path (hp ).relative_to (index .repo .working_dir ).as_posix ()
99104 cmd = ["bash.exe" , relative_hp ]
100105
101- process = subprocess .Popen (
102- cmd + list (args ),
103- env = env ,
104- stdout = subprocess .PIPE ,
105- stderr = subprocess .PIPE ,
106- cwd = index .repo .working_dir ,
107- creationflags = PROC_CREATIONFLAGS ,
108- )
106+ with maybe_patch_caller_env :
107+ process = subprocess .Popen (
108+ cmd + list (args ),
109+ env = env ,
110+ stdout = subprocess .PIPE ,
111+ stderr = subprocess .PIPE ,
112+ cwd = index .repo .working_dir ,
113+ creationflags = PROC_CREATIONFLAGS ,
114+ )
109115 except Exception as ex :
110116 raise HookExecutionError (hp , ex ) from ex
111117 else :
0 commit comments