@@ -3,6 +3,7 @@
|
3 | 3 | |
4 | 4 | """Standalone functions to accompany the index implementation and make it more versatile.""" |
5 | 5 | |
| 6 | +import contextlib |
6 | 7 | from io import BytesIO |
7 | 8 | import os |
8 | 9 | import os.path as osp |
@@ -26,7 +27,7 @@
|
26 | 27 | traverse_trees_recursive, |
27 | 28 | tree_to_stream, |
28 | 29 | ) |
29 | | -from git.util import IndexFileSHA1Writer, finalize_process |
| 30 | +from git.util import IndexFileSHA1Writer, finalize_process, patch_env |
30 | 31 | from gitdb.base import IStream |
31 | 32 | from gitdb.typ import str_tree_type |
32 | 33 | |
@@ -90,6 +91,10 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None:
|
90 | 91 | env = os.environ.copy() |
91 | 92 | env["GIT_INDEX_FILE"] = safe_decode(str(index.path)) |
92 | 93 | 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() |
93 | 98 | cmd = [hp] |
94 | 99 | try: |
95 | 100 | 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:
|
98 | 103 | relative_hp = Path(hp).relative_to(index.repo.working_dir).as_posix() |
99 | 104 | cmd = ["bash.exe", relative_hp] |
100 | 105 | |
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 | + ) |
109 | 115 | except Exception as ex: |
110 | 116 | raise HookExecutionError(hp, ex) from ex |
111 | 117 | else: |
|