Skip to content

Commit c441316

Browse files
committed
use strings instead of uname to detect cygwin
1 parent 36a893b commit c441316

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

git/util.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -457,23 +457,24 @@ def _is_cygwin_git(git_executable: str) -> bool:
457457
if is_cygwin is None:
458458
is_cygwin = False
459459
try:
460-
git_dir = osp.dirname(git_executable)
460+
git_cmd = pathlib.Path(git_executable)
461+
git_dir = git_cmd.parent
462+
461463
if not git_dir:
462464
res = py_where(git_executable)
463-
git_dir = osp.dirname(res[0]) if res else ""
465+
git_dir = pathlib.Path(res[0]).parent if res else ""
464466

465-
# Just a name given, not a real path.
466-
uname_cmd = osp.join(git_dir, "uname")
467+
# If it's a cygwin git, it'll have cygwin in the output of `strings git`
468+
strings_cmd = pathlib.Path(git_dir, "strings")
467469

468-
if not (pathlib.Path(uname_cmd).is_file() and os.access(uname_cmd, os.X_OK)):
469-
_logger.debug(f"Failed checking if running in CYGWIN: {uname_cmd} is not an executable")
470-
_is_cygwin_cache[git_executable] = is_cygwin
470+
if not (pathlib.Path(strings_cmd).is_file() and os.access(strings_cmd, os.X_OK)):
471+
_logger.debug(f"Failed checking if running in CYGWIN: {strings_cmd} is not an executable")
472+
_is_cygwin_cache[git_executable] = False
471473
return is_cygwin
472474

473-
process = subprocess.Popen([uname_cmd], stdout=subprocess.PIPE, universal_newlines=True)
474-
uname_out, _ = process.communicate()
475-
# retcode = process.poll()
476-
is_cygwin = "CYGWIN" in uname_out
475+
process = subprocess.Popen([strings_cmd, git_cmd], stdout=subprocess.PIPE, text=True)
476+
strings_output, _ = process.communicate()
477+
is_cygwin = any(x for x in strings_output if "cygwin" in x.lower())
477478
except Exception as ex:
478479
_logger.debug("Failed checking if running in CYGWIN due to: %r", ex)
479480
_is_cygwin_cache[git_executable] = is_cygwin

0 commit comments

Comments
 (0)