Skip to content

Commit 8576534

Browse files
authored
Merge pull request #2026 from gcmarx/main
correctly handle `uname-cmd` that doesn't point to an executable file
2 parents bf51609 + f3ab5d3 commit 8576534

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ __pycache__/
1010
# Transient editor files
1111
*.swp
1212
*~
13+
\#*#
14+
.#*#
1315

1416
# Editor configuration
1517
nbproject

AUTHORS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,5 +55,6 @@ Contributors are:
5555
-Eliah Kagan <eliah.kagan _at_ gmail.com>
5656
-Ethan Lin <et.repositories _at_ gmail.com>
5757
-Jonas Scharpf <jonas.scharpf _at_ checkmk.com>
58+
-Gordon Marx
5859

5960
Portions derived from other open source works and are clearly marked.

git/util.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,12 @@ def _is_cygwin_git(git_executable: str) -> bool:
464464

465465
# Just a name given, not a real path.
466466
uname_cmd = osp.join(git_dir, "uname")
467+
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
471+
return is_cygwin
472+
467473
process = subprocess.Popen([uname_cmd], stdout=subprocess.PIPE, universal_newlines=True)
468474
uname_out, _ = process.communicate()
469475
# retcode = process.poll()
@@ -484,7 +490,9 @@ def is_cygwin_git(git_executable: PathLike) -> bool: ...
484490

485491

486492
def is_cygwin_git(git_executable: Union[None, PathLike]) -> bool:
487-
if sys.platform == "win32": # TODO: See if we can use `sys.platform != "cygwin"`.
493+
# TODO: when py3.7 support is dropped, use the new interpolation f"{variable=}"
494+
_logger.debug(f"sys.platform={sys.platform!r}, git_executable={git_executable!r}")
495+
if sys.platform != "cygwin":
488496
return False
489497
elif git_executable is None:
490498
return False

test/test_util.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
LockFile,
3535
cygpath,
3636
decygpath,
37+
is_cygwin_git,
3738
get_user_id,
3839
remove_password_if_present,
3940
rmtree,
@@ -349,6 +350,24 @@ def test_decygpath(self, wpath, cpath):
349350
assert wcpath == wpath.replace("/", "\\"), cpath
350351

351352

353+
class TestIsCygwinGit:
354+
"""Tests for :func:`is_cygwin_git`"""
355+
356+
def test_on_path_executable(self):
357+
# Currently we assume tests run on Cygwin use Cygwin git. See #533 and #1455 for background.
358+
if sys.platform == "cygwin":
359+
assert is_cygwin_git("git")
360+
else:
361+
assert not is_cygwin_git("git")
362+
363+
def test_none_executable(self):
364+
assert not is_cygwin_git(None)
365+
366+
def test_with_missing_uname(self):
367+
"""Test for handling when `uname` isn't in the same directory as `git`"""
368+
assert not is_cygwin_git("/bogus_path/git")
369+
370+
352371
class _Member:
353372
"""A member of an IterableList."""
354373

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy