Skip to content

Commit 57a2232

Browse files
committed
test: use the shared guard instead of local copies
test_index had a private probe and test_refs repeated the same check inline.
1 parent 9ef6b23 commit 57a2232

2 files changed

Lines changed: 5 additions & 20 deletions

File tree

test/test_index.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
from git.util import Actor, cwd, hex_to_bin, rmtree
4141

4242
from test.lib import TestBase, VirtualEnvironment, fixture, fixture_path, with_rw_directory, with_rw_repo, PathLikeMock
43-
from test.lib.helper import xfail_if_raises
43+
from test.lib.helper import symlinks_supported, xfail_if_raises
4444

4545
HOOKS_SHEBANG = "#!/usr/bin/env sh\n"
4646

@@ -175,19 +175,6 @@ def _decode(stdout):
175175
_win_bash_status = WinBashStatus.check()
176176

177177

178-
def _windows_supports_symlinks():
179-
if sys.platform != "win32":
180-
return False
181-
182-
with tempfile.TemporaryDirectory(prefix="gitpython-symlink-check-") as temp_dir:
183-
link_path = osp.join(temp_dir, "link")
184-
try:
185-
os.symlink("missing-target", link_path)
186-
except (NotImplementedError, OSError):
187-
return False
188-
return S_ISLNK(os.lstat(link_path)[ST_MODE])
189-
190-
191178
def _make_hook(git_dir, name, content, make_exec=True):
192179
"""A helper to create a hook"""
193180
hp = hook_path(name, git_dir)
@@ -613,7 +600,7 @@ def _count_existing(self, repo, files):
613600
@with_rw_repo("0.1.6")
614601
def test_index_mutation(self, rw_repo):
615602
with xfail_if_raises(
616-
sys.platform == "win32" and (Git().config("core.symlinks") == "true" or _windows_supports_symlinks()),
603+
sys.platform == "win32" and (Git().config("core.symlinks") == "true" or symlinks_supported()),
617604
raises=(FileNotFoundError, GitCommandError),
618605
reason="Assumes symlinks are not created on Windows and opens a symlink to a nonexistent target.",
619606
):

test/test_refs.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import git.refs as refs
2929
from git.util import Actor
3030

31-
from test.lib import TestBase, with_rw_repo, PathLikeMock
31+
from test.lib import TestBase, requires_symlinks, with_rw_repo, PathLikeMock
3232

3333

3434
class TestRefs(TestBase):
@@ -735,6 +735,7 @@ def test_symbolic_reference_log_append_rejects_path_traversal(self):
735735
)
736736
assert not outside_path.exists()
737737

738+
@requires_symlinks
738739
def test_symbolic_reference_set_reference_rejects_symlink_escape(self):
739740
with tempfile.TemporaryDirectory() as tmp_dir:
740741
base_dir = Path(tmp_dir)
@@ -746,10 +747,7 @@ def test_symbolic_reference_set_reference_rejects_symlink_escape(self):
746747
refs_heads_dir = Path(repo.common_dir) / "refs" / "heads"
747748
refs_heads_dir.mkdir(parents=True, exist_ok=True)
748749
symlink_path = refs_heads_dir / "link_out"
749-
try:
750-
symlink_path.symlink_to(outside_dir, target_is_directory=True)
751-
except (OSError, NotImplementedError) as ex:
752-
self.skipTest("symlinks unavailable on this platform: %s" % ex)
750+
symlink_path.symlink_to(outside_dir, target_is_directory=True)
753751
if osp.realpath(symlink_path / "escaped") == osp.abspath(symlink_path / "escaped"):
754752
self.skipTest("realpath does not resolve directory symlinks on this platform")
755753

0 commit comments

Comments
 (0)