Skip to content

correctly handle uname-cmd that doesn't point to an executable file #2026

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
May 28, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use strings instead of uname to detect cygwin
  • Loading branch information
gcmarx committed May 27, 2025
commit c441316b7714207eaf2c13be5104d15ec69943bd
23 changes: 12 additions & 11 deletions git/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,23 +457,24 @@ def _is_cygwin_git(git_executable: str) -> bool:
if is_cygwin is None:
is_cygwin = False
try:
git_dir = osp.dirname(git_executable)
git_cmd = pathlib.Path(git_executable)
git_dir = git_cmd.parent

if not git_dir:
res = py_where(git_executable)
git_dir = osp.dirname(res[0]) if res else ""
git_dir = pathlib.Path(res[0]).parent if res else ""

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

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

process = subprocess.Popen([uname_cmd], stdout=subprocess.PIPE, universal_newlines=True)
uname_out, _ = process.communicate()
# retcode = process.poll()
is_cygwin = "CYGWIN" in uname_out
process = subprocess.Popen([strings_cmd, git_cmd], stdout=subprocess.PIPE, text=True)
strings_output, _ = process.communicate()
is_cygwin = any(x for x in strings_output if "cygwin" in x.lower())
except Exception as ex:
_logger.debug("Failed checking if running in CYGWIN due to: %r", ex)
_is_cygwin_cache[git_executable] = is_cygwin
Expand Down
Loading