| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -79,21 +79,6 @@ def _has_file_extension(path: str) -> str: | |||
| 79 | 79 | return osp.splitext(path)[1] | |
| 80 | 80 | ||
| 81 | 81 | ||
| 82 | - def _which_from_path(command: str) -> Union[str, None]: | ||
| 83 | - """Resolve an executable 'command' from PATH without considering the current directory.""" | ||
| 84 | - cwd = osp.normcase(osp.abspath(os.curdir)) | ||
| 85 | - for directory in os.get_exec_path(): | ||
| 86 | - if not directory: | ||
| 87 | - continue | ||
| 88 | - directory = osp.abspath(directory) | ||
| 89 | - if osp.normcase(directory) == cwd: | ||
| 90 | - continue | ||
| 91 | - candidate = osp.join(directory, command) | ||
| 92 | - if osp.isfile(candidate) and os.access(candidate, os.X_OK): | ||
| 93 | - return candidate | ||
| 94 | - return None | ||
| 95 | - | ||
| 96 | - | ||
| 97 | 82 | def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None: | |
| 98 | 83 | """Run the commit hook of the given name. Silently ignore hooks that do not exist. | |
| 99 | 84 | ||
@@ -127,11 +112,7 @@ def run_commit_hook(name: str, index: "IndexFile", *args: str) -> None: | |||
| 127 | 112 | # an absolute path in this form, although a relative path is preferable | |
| 128 | 113 | # because it also works with the Windows Subsystem for Linux wrapper. | |
| 129 | 114 | bash_hp = hp | |
| 130 | - # Resolve through PATH before spawning. On Windows, CreateProcess searches | ||
| 131 | - # the current and system directories before PATH for a bare executable name, | ||
| 132 | - # which can otherwise select an impostor or the WSL launcher instead of Git | ||
| 133 | - # for Windows' Bash. | ||
| 134 | - cmd = [_which_from_path("bash.exe") or "bash.exe", Path(bash_hp).as_posix()] | ||
| 115 | + cmd = ["bash.exe", Path(bash_hp).as_posix()] | ||
| 135 | 116 | ||
| 136 | 117 | process = safer_popen( | |
| 137 | 118 | cmd + list(args), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1128,20 +1128,16 @@ def test_run_commit_hook_outside_worktree_on_windows(self, rw_dir): | |||
| 1128 | 1128 | repo = Repo.init(root / "repo") | |
| 1129 | 1129 | hooks_dir = root / "hooks" | |
| 1130 | 1130 | _make_hook(root, "fake-hook", "exit 0") | |
| 1131 | - bash = root / "git" / "bin" / "bash.exe" | ||
| 1132 | 1131 | with repo.config_writer() as writer: | |
| 1133 | 1132 | writer.set_value("core", "hooksPath", str(hooks_dir)) | |
| 1134 | 1133 | ||
| 1135 | - with mock.patch("git.index.fun.sys.platform", "win32"), mock.patch( | ||
| 1136 | - "git.index.fun._which_from_path", return_value=str(bash) | ||
| 1137 | - ) as which: | ||
| 1134 | + with mock.patch("git.index.fun.sys.platform", "win32"): | ||
| 1138 | 1135 | with mock.patch("git.index.fun.safer_popen") as popen, mock.patch("git.index.fun.handle_process_output"): | |
| 1139 | 1136 | popen.return_value.returncode = 0 | |
| 1140 | 1137 | run_commit_hook("fake-hook", repo.index) | |
| 1141 | 1138 | ||
| 1142 | - which.assert_called_once_with("bash.exe") | ||
| 1143 | 1139 | command = popen.call_args[0][0] | |
| 1144 | - self.assertEqual(command, [str(bash), "../hooks/fake-hook"]) | ||
| 1140 | + self.assertEqual(command, ["bash.exe", "../hooks/fake-hook"]) | ||
| 1145 | 1141 | ||
| 1146 | 1142 | @ddt.data((False,), (True,)) | |
| 1147 | 1143 | @with_rw_directory | |
| Back | FazBrowse Home | New Git URL |
0 commit comments