Skip to content

Commit 3801505

Browse files
committed
Convert paths in constructors and large function calls
1 parent 0414bf7 commit 3801505

File tree

7 files changed

+11
-6
lines changed

7 files changed

+11
-6
lines changed

git/index/base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -652,14 +652,15 @@ def _to_relative_path(self, path: PathLike) -> PathLike:
652652
653653
:raise ValueError:
654654
"""
655+
path = os.fspath(path)
655656
if not osp.isabs(path):
656657
return path
657658
if self.repo.bare:
658659
raise InvalidGitRepositoryError("require non-bare repository")
659-
if not osp.normpath(os.fspath(path)).startswith(os.fspath(self.repo.working_tree_dir)):
660+
if not osp.normpath(path).startswith(os.fspath(self.repo.working_tree_dir)):
660661
raise ValueError("Absolute path %r is not in git repository at %r" % (path, self.repo.working_tree_dir))
661662
result = os.path.relpath(path, self.repo.working_tree_dir)
662-
if os.fspath(path).endswith(os.sep) and not result.endswith(os.sep):
663+
if path.endswith(os.sep) and not result.endswith(os.sep):
663664
result += os.sep
664665
return result
665666

git/index/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class TemporaryFileSwap:
3737
__slots__ = ("file_path", "tmp_file_path")
3838

3939
def __init__(self, file_path: PathLike) -> None:
40-
self.file_path = file_path
40+
self.file_path = os.fspath(file_path)
4141
dirname, basename = osp.split(file_path)
4242
fd, self.tmp_file_path = tempfile.mkstemp(prefix=basename, dir=dirname)
4343
os.close(fd)

git/refs/head.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
__all__ = ["HEAD", "Head"]
1010

11+
import os
1112
from git.config import GitConfigParser, SectionConstraint
1213
from git.exc import GitCommandError
1314
from git.util import join_path
@@ -48,6 +49,7 @@ class HEAD(SymbolicReference):
4849
commit: "Commit"
4950

5051
def __init__(self, repo: "Repo", path: PathLike = _HEAD_NAME) -> None:
52+
path = os.fspath(path)
5153
if path != self._HEAD_NAME:
5254
raise ValueError("HEAD instance must point to %r, got %r" % (self._HEAD_NAME, path))
5355
super().__init__(repo, path)

git/refs/log.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
__all__ = ["RefLog", "RefLogEntry"]
55

66
from mmap import mmap
7+
import os
78
import os.path as osp
89
import re
910
import time as _time
@@ -167,7 +168,7 @@ def __init__(self, filepath: Union[PathLike, None] = None) -> None:
167168
"""Initialize this instance with an optional filepath, from which we will
168169
initialize our data. The path is also used to write changes back using the
169170
:meth:`write` method."""
170-
self._path = filepath
171+
self._path = os.fspath(filepath)
171172
if filepath is not None:
172173
self._read_from_file()
173174
# END handle filepath

git/refs/symbolic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ class SymbolicReference:
7676

7777
def __init__(self, repo: "Repo", path: PathLike, check_path: bool = False) -> None:
7878
self.repo = repo
79-
self.path = path
79+
self.path = os.fspath(path)
8080

8181
def __str__(self) -> str:
8282
return os.fspath(self.path)

git/repo/fun.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def is_git_dir(d: PathLike) -> bool:
6262
clearly indicates that we don't support it. There is the unlikely danger to
6363
throw if we see directories which just look like a worktree dir, but are none.
6464
"""
65+
d = os.fspath(d)
6566
if osp.isdir(d):
6667
if (osp.isdir(osp.join(d, "objects")) or "GIT_OBJECT_DIRECTORY" in os.environ) and osp.isdir(
6768
osp.join(d, "refs")

git/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ class LockFile:
10111011
__slots__ = ("_file_path", "_owns_lock")
10121012

10131013
def __init__(self, file_path: PathLike) -> None:
1014-
self._file_path = file_path
1014+
self._file_path = os.fspath(file_path)
10151015
self._owns_lock = False
10161016

10171017
def __del__(self) -> None:

0 commit comments

Comments
 (0)