Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Failing Path Tests#2088

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
20 commits
Select commitHold shift + click to select a range
e3f38ff
Move clone tests into dedicated file
George-OgdenNov 27, 2025
24abf10
Allow Pathlike urls and destinations when cloning
George-OgdenNov 27, 2025
ad1ae5f
Simplify logic with direct path conversion
George-OgdenNov 27, 2025
5d26325
Allow Pathlike paths when creating a git repo
George-OgdenNov 27, 2025
59c3c80
Fix missing path conversion
George-OgdenNov 27, 2025
91d4cc5
Use os.fspath instead of __fspath__ for reading paths
George-OgdenNov 28, 2025
0414bf7
Replace extra occurrences of str with fspath
George-OgdenNov 28, 2025
3801505
Convert paths in constructors and large function calls
George-OgdenNov 28, 2025
086e832
Fix union type conversion to path
George-OgdenNov 28, 2025
b3908ed
Use converted file path
George-OgdenNov 29, 2025
50aea99
Remove redundant `fspath`
George-OgdenNov 29, 2025
57a3af1
Remove redundant `fspath`
George-OgdenNov 29, 2025
df8087a
Remove a large number of redundant fspaths
George-OgdenNov 29, 2025
1722561
Remove redundant str call
George-OgdenNov 29, 2025
921ca8a
Limit mypy version due to Cygwin errors
George-OgdenNov 29, 2025
b5abe0f
Merge branch 'main' into true-pathlike
George-OgdenNov 29, 2025
12e15ba
Validate every fspath with tests
George-OgdenNov 29, 2025
8434967
Fix type hints
George-OgdenNov 29, 2025
1710626
Add tests with non-ascii characters
George-OgdenDec 1, 2025
02aea12
Revert all non-test files
George-OgdenDec 2, 2025
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
11 changes: 11 additions & 0 deletionstest/lib/helper.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,6 +10,7 @@
"with_rw_directory",
"with_rw_repo",
"with_rw_and_rw_remote_repo",
"PathLikeMock",
"TestBase",
"VirtualEnvironment",
"TestCase",
Expand All@@ -20,6 +21,7 @@
]

import contextlib
from dataclasses import dataclass
from functools import wraps
import gc
import io
Expand DownExpand Up@@ -49,6 +51,15 @@

_logger = logging.getLogger(__name__)


@dataclass
class PathLikeMock:
path: str

def __fspath__(self) -> str:
return self.path


# { Routines


Expand Down
306 changes: 304 additions & 2 deletionstest/test_clone.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
# This module is part of GitPython and is released under the
# 3-Clause BSD License: https://opensource.org/license/bsd-3-clause/

import os
import os.path as osp
import pathlib
import sys
import tempfile
from unittest import skip

from git import GitCommandError, Repo
from git.exc import UnsafeOptionError, UnsafeProtocolError

from test.lib import TestBase, with_rw_directory, with_rw_repo, PathLikeMock

from pathlib import Path
import re

import git

from test.lib import TestBase, with_rw_directory
import pytest


class TestClone(TestBase):
Expand All@@ -29,3 +40,294 @@ def test_checkout_in_non_empty_dir(self, rw_dir):
)
else:
self.fail("GitCommandError not raised")

@with_rw_directory
def test_clone_from_pathlib(self, rw_dir):
original_repo = Repo.init(osp.join(rw_dir, "repo"))

Repo.clone_from(pathlib.Path(original_repo.git_dir), pathlib.Path(rw_dir) / "clone_pathlib")

@with_rw_directory
def test_clone_from_pathlike(self, rw_dir):
original_repo = Repo.init(osp.join(rw_dir, "repo"))
Repo.clone_from(PathLikeMock(original_repo.git_dir), PathLikeMock(os.path.join(rw_dir, "clone_pathlike")))

@with_rw_directory
def test_clone_from_pathlike_unicode_repr(self, rw_dir):
original_repo = Repo.init(osp.join(rw_dir, "repo-áēñöưḩ̣"))
Repo.clone_from(
PathLikeMock(original_repo.git_dir), PathLikeMock(os.path.join(rw_dir, "clone_pathlike-áēñöưḩ̣"))
)

@with_rw_directory
def test_clone_from_pathlib_withConfig(self, rw_dir):
original_repo = Repo.init(osp.join(rw_dir, "repo"))

cloned = Repo.clone_from(
original_repo.git_dir,
pathlib.Path(rw_dir) / "clone_pathlib_withConfig",
multi_options=[
"--recurse-submodules=repo",
"--config core.filemode=false",
"--config submodule.repo.update=checkout",
"--config filter.lfs.clean='git-lfs clean -- %f'",
],
allow_unsafe_options=True,
)

self.assertEqual(cloned.config_reader().get_value("submodule", "active"), "repo")
self.assertEqual(cloned.config_reader().get_value("core", "filemode"), False)
self.assertEqual(cloned.config_reader().get_value('submodule "repo"', "update"), "checkout")
self.assertEqual(
cloned.config_reader().get_value('filter "lfs"', "clean"),
"git-lfs clean -- %f",
)

def test_clone_from_with_path_contains_unicode(self):
with tempfile.TemporaryDirectory() as tmpdir:
unicode_dir_name = "\u0394"
path_with_unicode = os.path.join(tmpdir, unicode_dir_name)
os.makedirs(path_with_unicode)

try:
Repo.clone_from(
url=self._small_repo_url(),
to_path=path_with_unicode,
)
except UnicodeEncodeError:
self.fail("Raised UnicodeEncodeError")

@with_rw_directory
@skip(
"""The referenced repository was removed, and one needs to set up a new
password controlled repo under the org's control."""
)
def test_leaking_password_in_clone_logs(self, rw_dir):
password = "fakepassword1234"
try:
Repo.clone_from(
url="https://fakeuser:{}@fakerepo.example.com/testrepo".format(password),
to_path=rw_dir,
)
except GitCommandError as err:
assert password not in str(err), "The error message '%s' should not contain the password" % err
# Working example from a blank private project.
Repo.clone_from(
url="https://gitlab+deploy-token-392045:mLWhVus7bjLsy8xj8q2V@gitlab.com/mercierm/test_git_python",
to_path=rw_dir,
)

@with_rw_repo("HEAD")
def test_clone_unsafe_options(self, rw_repo):
with tempfile.TemporaryDirectory() as tdir:
tmp_dir = pathlib.Path(tdir)
tmp_file = tmp_dir / "pwn"
unsafe_options = [
f"--upload-pack='touch {tmp_file}'",
f"-u 'touch {tmp_file}'",
"--config=protocol.ext.allow=always",
"-c protocol.ext.allow=always",
]
for unsafe_option in unsafe_options:
with self.assertRaises(UnsafeOptionError):
rw_repo.clone(tmp_dir, multi_options=[unsafe_option])
assert not tmp_file.exists()

unsafe_options = [
{"upload-pack": f"touch {tmp_file}"},
{"u": f"touch {tmp_file}"},
{"config": "protocol.ext.allow=always"},
{"c": "protocol.ext.allow=always"},
]
for unsafe_option in unsafe_options:
with self.assertRaises(UnsafeOptionError):
rw_repo.clone(tmp_dir, **unsafe_option)
assert not tmp_file.exists()

@pytest.mark.xfail(
sys.platform == "win32",
reason=(
"File not created. A separate Windows command may be needed. This and the "
"currently passing test test_clone_unsafe_options must be adjusted in the "
"same way. Until then, test_clone_unsafe_options is unreliable on Windows."
),
raises=AssertionError,
)
@with_rw_repo("HEAD")
def test_clone_unsafe_options_allowed(self, rw_repo):
with tempfile.TemporaryDirectory() as tdir:
tmp_dir = pathlib.Path(tdir)
tmp_file = tmp_dir / "pwn"
unsafe_options = [
f"--upload-pack='touch {tmp_file}'",
f"-u 'touch {tmp_file}'",
]
for i, unsafe_option in enumerate(unsafe_options):
destination = tmp_dir / str(i)
assert not tmp_file.exists()
# The options will be allowed, but the command will fail.
with self.assertRaises(GitCommandError):
rw_repo.clone(destination, multi_options=[unsafe_option], allow_unsafe_options=True)
assert tmp_file.exists()
tmp_file.unlink()

unsafe_options = [
"--config=protocol.ext.allow=always",
"-c protocol.ext.allow=always",
]
for i, unsafe_option in enumerate(unsafe_options):
destination = tmp_dir / str(i)
assert not destination.exists()
rw_repo.clone(destination, multi_options=[unsafe_option], allow_unsafe_options=True)
assert destination.exists()

@with_rw_repo("HEAD")
def test_clone_safe_options(self, rw_repo):
with tempfile.TemporaryDirectory() as tdir:
tmp_dir = pathlib.Path(tdir)
options = [
"--depth=1",
"--single-branch",
"-q",
]
for option in options:
destination = tmp_dir / option
assert not destination.exists()
rw_repo.clone(destination, multi_options=[option])
assert destination.exists()

@with_rw_repo("HEAD")
def test_clone_from_unsafe_options(self, rw_repo):
with tempfile.TemporaryDirectory() as tdir:
tmp_dir = pathlib.Path(tdir)
tmp_file = tmp_dir / "pwn"
unsafe_options = [
f"--upload-pack='touch {tmp_file}'",
f"-u 'touch {tmp_file}'",
"--config=protocol.ext.allow=always",
"-c protocol.ext.allow=always",
]
for unsafe_option in unsafe_options:
with self.assertRaises(UnsafeOptionError):
Repo.clone_from(rw_repo.working_dir, tmp_dir, multi_options=[unsafe_option])
assert not tmp_file.exists()

unsafe_options = [
{"upload-pack": f"touch {tmp_file}"},
{"u": f"touch {tmp_file}"},
{"config": "protocol.ext.allow=always"},
{"c": "protocol.ext.allow=always"},
]
for unsafe_option in unsafe_options:
with self.assertRaises(UnsafeOptionError):
Repo.clone_from(rw_repo.working_dir, tmp_dir, **unsafe_option)
assert not tmp_file.exists()

@pytest.mark.xfail(
sys.platform == "win32",
reason=(
"File not created. A separate Windows command may be needed. This and the "
"currently passing test test_clone_from_unsafe_options must be adjusted in the "
"same way. Until then, test_clone_from_unsafe_options is unreliable on Windows."
),
raises=AssertionError,
)
@with_rw_repo("HEAD")
def test_clone_from_unsafe_options_allowed(self, rw_repo):
with tempfile.TemporaryDirectory() as tdir:
tmp_dir = pathlib.Path(tdir)
tmp_file = tmp_dir / "pwn"
unsafe_options = [
f"--upload-pack='touch {tmp_file}'",
f"-u 'touch {tmp_file}'",
]
for i, unsafe_option in enumerate(unsafe_options):
destination = tmp_dir / str(i)
assert not tmp_file.exists()
# The options will be allowed, but the command will fail.
with self.assertRaises(GitCommandError):
Repo.clone_from(
rw_repo.working_dir, destination, multi_options=[unsafe_option], allow_unsafe_options=True
)
assert tmp_file.exists()
tmp_file.unlink()

unsafe_options = [
"--config=protocol.ext.allow=always",
"-c protocol.ext.allow=always",
]
for i, unsafe_option in enumerate(unsafe_options):
destination = tmp_dir / str(i)
assert not destination.exists()
Repo.clone_from(
rw_repo.working_dir, destination, multi_options=[unsafe_option], allow_unsafe_options=True
)
assert destination.exists()

@with_rw_repo("HEAD")
def test_clone_from_safe_options(self, rw_repo):
with tempfile.TemporaryDirectory() as tdir:
tmp_dir = pathlib.Path(tdir)
options = [
"--depth=1",
"--single-branch",
"-q",
]
for option in options:
destination = tmp_dir / option
assert not destination.exists()
Repo.clone_from(rw_repo.common_dir, destination, multi_options=[option])
assert destination.exists()

def test_clone_from_unsafe_protocol(self):
with tempfile.TemporaryDirectory() as tdir:
tmp_dir = pathlib.Path(tdir)
tmp_file = tmp_dir / "pwn"
urls = [
f"ext::sh -c touch% {tmp_file}",
"fd::17/foo",
]
for url in urls:
with self.assertRaises(UnsafeProtocolError):
Repo.clone_from(url, tmp_dir / "repo")
assert not tmp_file.exists()

def test_clone_from_unsafe_protocol_allowed(self):
with tempfile.TemporaryDirectory() as tdir:
tmp_dir = pathlib.Path(tdir)
tmp_file = tmp_dir / "pwn"
urls = [
f"ext::sh -c touch% {tmp_file}",
"fd::/foo",
]
for url in urls:
# The URL will be allowed into the command, but the command will
# fail since we don't have that protocol enabled in the Git config file.
with self.assertRaises(GitCommandError):
Repo.clone_from(url, tmp_dir / "repo", allow_unsafe_protocols=True)
assert not tmp_file.exists()

def test_clone_from_unsafe_protocol_allowed_and_enabled(self):
with tempfile.TemporaryDirectory() as tdir:
tmp_dir = pathlib.Path(tdir)
tmp_file = tmp_dir / "pwn"
urls = [
f"ext::sh -c touch% {tmp_file}",
]
allow_ext = [
"--config=protocol.ext.allow=always",
]
for url in urls:
# The URL will be allowed into the command, and the protocol is enabled,
# but the command will fail since it can't read from the remote repo.
assert not tmp_file.exists()
with self.assertRaises(GitCommandError):
Repo.clone_from(
url,
tmp_dir / "repo",
multi_options=allow_ext,
allow_unsafe_protocols=True,
allow_unsafe_options=True,
)
assert tmp_file.exists()
tmp_file.unlink()
Loading
Loading

[8]ページ先頭

©2009-2026 Movatter.jp