Skip to content
Open
Show file tree
Hide file tree
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 os.fspath instead of __fspath__ for reading paths
  • Loading branch information
George-Ogden committed Nov 28, 2025
commit 91d4cc5ea05df04c82fcfd3e35a6af2e903cc554
2 changes: 1 addition & 1 deletion git/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ def read(self) -> None: # type: ignore[override]
self._read(file_path, file_path.name)
else:
# Assume a path if it is not a file-object.
file_path = cast(PathLike, file_path)
file_path = os.fspath(file_path)
try:
with open(file_path, "rb") as fp:
file_ok = True
Expand Down
13 changes: 4 additions & 9 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,9 @@ def __init__(
# Given how the tests are written, this seems more likely to catch Cygwin
# git used from Windows than Windows git used from Cygwin. Therefore
# changing to Cygwin-style paths is the relevant operation.
epath = cygpath(epath if isinstance(epath, str) else epath.__fspath__())
epath = cygpath(os.fspath(epath))

epath = epath or path or os.getcwd()
if not isinstance(epath, str):
epath = epath.__fspath__()
epath = os.fspath(epath)
if expand_vars and re.search(self.re_envvars, epath):
warnings.warn(
"The use of environment variables in paths is deprecated"
Expand Down Expand Up @@ -1361,11 +1359,8 @@ def _clone(
) -> "Repo":
odbt = kwargs.pop("odbt", odb_default_type)

# When pathlib.Path or other class-based path is passed
if not isinstance(url, str):
url = url.__fspath__()
if not isinstance(path, str):
path = path.__fspath__()
url = os.fspath(url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URL is not a path though.

Copy link
Contributor Author

@George-Ogden George-Ogden Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, url can be a path if you're cloning a local repo, and if it's not os.fspath will leave strings alone.

path = os.fspath(path)

## A bug win cygwin's Git, when `--bare` or `--separate-git-dir`
# it prepends the cwd or(?) the `url` into the `path, so::
Expand Down
Loading