()
| 70 | |
| 71 | @lru_cache(None) |
| 72 | def _get_git_path() -> str: |
| 73 | git_path = which("git") |
| 74 | |
| 75 | if git_path is None: |
| 76 | raise GitExecutableNotFound("unable to find git executable in PATH/PATHEXT") |
| 77 | |
| 78 | # lower()ing these would provide additional coverage on case- |
| 79 | # insensitive filesystems but detection is problematic |
| 80 | git_path = os.path.abspath(git_path) |
| 81 | cwd = os.getcwd() |
| 82 | path_env = [ |
| 83 | os.path.abspath(p) for p in os.environ.get("PATH", "").split(os.pathsep) |
| 84 | ] |
| 85 | |
| 86 | # git was found - ignore git in cwd if cwd not in PATH |
| 87 | if cwd == os.path.dirname(git_path) and cwd not in path_env: |
| 88 | raise GitExecutableNotFound("rejecting git executable in CWD not in PATH") |
| 89 | |
| 90 | logger.debug("Found git at %s", git_path) |
| 91 | return git_path |
| 92 | |
| 93 | |
| 94 | @lru_cache(None) |
no test coverage detected