summaryrefslogtreecommitdiff
path: root/git/index
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2021-07-11 12:30:59 +0800
committerGitHub <noreply@github.com>2021-07-11 12:30:59 +0800
commit9523033fd1ff499ae3d151b23b851b7e2b64bf75 (patch)
treec2f7b467186269926c48c4b2cf02d8364dc39751 /git/index
parent0a6d9d669979cc5a89ca73f8f4843cba47b4486a (diff)
parent94c66525a6e7d5c74a9aee65d14630bb674439f7 (diff)
downloadgitpython-9523033fd1ff499ae3d151b23b851b7e2b64bf75.tar.gz
Merge pull request #1285 from Yobmod/main
Finish initial typing of Index and Submodule
Diffstat (limited to 'git/index')
-rw-r--r--git/index/base.py97
-rw-r--r--git/index/fun.py62
-rw-r--r--git/index/util.py21
3 files changed, 100 insertions, 80 deletions
diff --git a/git/index/base.py b/git/index/base.py
index f4ffba7b..3aa06e38 100644
--- a/git/index/base.py
+++ b/git/index/base.py
@@ -18,6 +18,7 @@ from git.compat import (
from git.exc import (
GitCommandError,
CheckoutError,
+ GitError,
InvalidGitRepositoryError
)
from git.objects import (
@@ -40,7 +41,7 @@ from git.util import (
from gitdb.base import IStream
from gitdb.db import MemoryDB
-import git.diff as diff
+import git.diff as git_diff
import os.path as osp
from .fun import (
@@ -66,10 +67,10 @@ from .util import (
# typing -----------------------------------------------------------------------------
-from typing import (Any, BinaryIO, Callable, Dict, IO, Iterable, Iterator, List,
- Sequence, TYPE_CHECKING, Tuple, Union)
+from typing import (Any, BinaryIO, Callable, Dict, IO, Iterable, Iterator, List, NoReturn,
+ Sequence, TYPE_CHECKING, Tuple, Type, Union)
-from git.types import PathLike, TBD
+from git.types import Commit_ish, PathLike, TBD
if TYPE_CHECKING:
from subprocess import Popen
@@ -87,7 +88,7 @@ Treeish = Union[Tree, Commit, str, bytes]
__all__ = ('IndexFile', 'CheckoutError')
-class IndexFile(LazyMixin, diff.Diffable, Serializable):
+class IndexFile(LazyMixin, git_diff.Diffable, Serializable):
"""
Implements an Index that can be manipulated using a native implementation in
@@ -113,7 +114,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
_VERSION = 2 # latest version we support
S_IFGITLINK = S_IFGITLINK # a submodule
- def __init__(self, repo: 'Repo', file_path: PathLike = None) -> None:
+ def __init__(self, repo: 'Repo', file_path: Union[PathLike, None] = None) -> None:
"""Initialize this Index instance, optionally from the given ``file_path``.
If no file_path is given, we will be created from the current index file.
@@ -372,13 +373,13 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# UTILITIES
@unbare_repo
- def _iter_expand_paths(self, paths: Sequence[PathLike]) -> Iterator[PathLike]:
+ def _iter_expand_paths(self: 'IndexFile', paths: Sequence[PathLike]) -> Iterator[PathLike]:
"""Expand the directories in list of paths to the corresponding paths accordingly,
Note: git will add items multiple times even if a glob overlapped
with manually specified paths or if paths where specified multiple
times - we respect that and do not prune"""
- def raise_exc(e):
+ def raise_exc(e: Exception) -> NoReturn:
raise e
r = str(self.repo.working_tree_dir)
rs = r + os.sep
@@ -410,7 +411,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# whose name contains wildcard characters.
if abs_path not in resolved_paths:
for f in self._iter_expand_paths(glob.glob(abs_path)):
- yield f.replace(rs, '')
+ yield str(f).replace(rs, '')
continue
# END glob handling
try:
@@ -426,7 +427,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# END path exception handling
# END for each path
- def _write_path_to_stdin(self, proc: 'Popen', filepath: PathLike, item, fmakeexc, fprogress,
+ def _write_path_to_stdin(self, proc: 'Popen', filepath: PathLike, item: TBD, fmakeexc: Callable[..., GitError],
+ fprogress: Callable[[PathLike, bool, TBD], None],
read_from_stdout: bool = True) -> Union[None, str]:
"""Write path to proc.stdin and make sure it processes the item, including progress.
@@ -498,7 +500,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
line.sort()
return path_map
- @classmethod
+ @ classmethod
def entry_key(cls, *entry: Union[BaseIndexEntry, PathLike, StageType]) -> Tuple[PathLike, StageType]:
return entry_key(*entry)
@@ -570,11 +572,12 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# note: additional deserialization could be saved if write_tree_from_cache
# would return sorted tree entries
root_tree = Tree(self.repo, binsha, path='')
- root_tree._cache = tree_items # type: ignore
+ root_tree._cache = tree_items # type: ignore # should this be encoded to [bytes, int, str]?
return root_tree
- def _process_diff_args(self, args: List[Union[str, diff.Diffable, object]]
- ) -> List[Union[str, diff.Diffable, object]]:
+ def _process_diff_args(self, # type: ignore[override]
+ args: List[Union[str, 'git_diff.Diffable', Type['git_diff.Diffable.Index']]]
+ ) -> List[Union[str, 'git_diff.Diffable', Type['git_diff.Diffable.Index']]]:
try:
args.pop(args.index(self))
except IndexError:
@@ -593,7 +596,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
raise ValueError("Absolute path %r is not in git repository at %r" % (path, self.repo.working_tree_dir))
return os.path.relpath(path, self.repo.working_tree_dir)
- def _preprocess_add_items(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, Submodule]]
+ def _preprocess_add_items(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, 'Submodule']]
) -> Tuple[List[PathLike], List[BaseIndexEntry]]:
""" Split the items into two lists of path strings and BaseEntries. """
paths = []
@@ -631,11 +634,11 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
return BaseIndexEntry((stat_mode_to_index_mode(st.st_mode),
istream.binsha, 0, to_native_path_linux(filepath)))
- @unbare_repo
- @git_working_dir
+ @ unbare_repo
+ @ git_working_dir
def _entries_for_paths(self, paths: List[str], path_rewriter: Callable, fprogress: Callable,
entries: List[BaseIndexEntry]) -> List[BaseIndexEntry]:
- entries_added = [] # type: List[BaseIndexEntry]
+ entries_added: List[BaseIndexEntry] = []
if path_rewriter:
for path in paths:
if osp.isabs(path):
@@ -664,8 +667,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# END path handling
return entries_added
- def add(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, Submodule]], force: bool = True,
- fprogress: Callable = lambda *args: None, path_rewriter: Callable = None,
+ def add(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, 'Submodule']], force: bool = True,
+ fprogress: Callable = lambda *args: None, path_rewriter: Union[Callable[..., PathLike], None] = None,
write: bool = True, write_extension_data: bool = False) -> List[BaseIndexEntry]:
"""Add files from the working tree, specific blobs or BaseIndexEntries
to the index.
@@ -769,7 +772,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# automatically
# paths can be git-added, for everything else we use git-update-index
paths, entries = self._preprocess_add_items(items)
- entries_added = []
+ entries_added: List[BaseIndexEntry] = []
# This code needs a working tree, therefore we try not to run it unless required.
# That way, we are OK on a bare repository as well.
# If there are no paths, the rewriter has nothing to do either
@@ -788,8 +791,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# create objects if required, otherwise go with the existing shas
null_entries_indices = [i for i, e in enumerate(entries) if e.binsha == Object.NULL_BIN_SHA]
if null_entries_indices:
- @git_working_dir
- def handle_null_entries(self):
+ @ git_working_dir
+ def handle_null_entries(self: 'IndexFile') -> None:
for ei in null_entries_indices:
null_entry = entries[ei]
new_entry = self._store_path(null_entry.path, fprogress)
@@ -833,12 +836,13 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
return entries_added
- def _items_to_rela_paths(self, items):
+ def _items_to_rela_paths(self, items: Union[PathLike, Sequence[Union[PathLike, BaseIndexEntry, Blob, Submodule]]]
+ ) -> List[PathLike]:
"""Returns a list of repo-relative paths from the given items which
may be absolute or relative paths, entries or blobs"""
paths = []
# if string put in list
- if isinstance(items, str):
+ if isinstance(items, (str, os.PathLike)):
items = [items]
for item in items:
@@ -851,9 +855,9 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# END for each item
return paths
- @post_clear_cache
- @default_index
- def remove(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, Submodule]], working_tree: bool = False,
+ @ post_clear_cache
+ @ default_index
+ def remove(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, 'Submodule']], working_tree: bool = False,
**kwargs: Any) -> List[str]:
"""Remove the given items from the index and optionally from
the working tree as well.
@@ -903,9 +907,9 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# rm 'path'
return [p[4:-1] for p in removed_paths]
- @post_clear_cache
- @default_index
- def move(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, Submodule]], skip_errors: bool = False,
+ @ post_clear_cache
+ @ default_index
+ def move(self, items: Sequence[Union[PathLike, Blob, BaseIndexEntry, 'Submodule']], skip_errors: bool = False,
**kwargs: Any) -> List[Tuple[str, str]]:
"""Rename/move the items, whereas the last item is considered the destination of
the move operation. If the destination is a file, the first item ( of two )
@@ -968,8 +972,14 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
return out
- def commit(self, message: str, parent_commits=None, head: bool = True, author: Union[None, 'Actor'] = None,
- committer: Union[None, 'Actor'] = None, author_date: str = None, commit_date: str = None,
+ def commit(self,
+ message: str,
+ parent_commits: Union[Commit_ish, None] = None,
+ head: bool = True,
+ author: Union[None, 'Actor'] = None,
+ committer: Union[None, 'Actor'] = None,
+ author_date: Union[str, None] = None,
+ commit_date: Union[str, None] = None,
skip_hooks: bool = False) -> Commit:
"""Commit the current default index file, creating a commit object.
For more information on the arguments, see tree.commit.
@@ -1023,7 +1033,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
proc.wait()
return stdout
- @default_index
+ @ default_index
def checkout(self, paths: Union[None, Iterable[PathLike]] = None, force: bool = False,
fprogress: Callable = lambda *args: None, **kwargs: Any
) -> Union[None, Iterator[PathLike], Sequence[PathLike]]:
@@ -1192,7 +1202,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
# END paths handling
assert "Should not reach this point"
- @default_index
+ @ default_index
def reset(self, commit: Union[Commit, 'Reference', str] = 'HEAD', working_tree: bool = False,
paths: Union[None, Iterable[PathLike]] = None,
head: bool = False, **kwargs: Any) -> 'IndexFile':
@@ -1262,10 +1272,12 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
return self
- @default_index
- def diff(self, other: Union[diff.Diffable.Index, 'IndexFile.Index', Treeish, None, object] = diff.Diffable.Index,
- paths: Union[str, List[PathLike], Tuple[PathLike, ...]] = None, create_patch: bool = False, **kwargs: Any
- ) -> diff.DiffIndex:
+ # @ default_index, breaks typing for some reason, copied into function
+ def diff(self, # type: ignore[override]
+ other: Union[Type['git_diff.Diffable.Index'], 'Tree', 'Commit', str, None] = git_diff.Diffable.Index,
+ paths: Union[PathLike, List[PathLike], Tuple[PathLike, ...], None] = None,
+ create_patch: bool = False, **kwargs: Any
+ ) -> git_diff.DiffIndex:
"""Diff this index against the working copy or a Tree or Commit object
For a documentation of the parameters and return values, see,
@@ -1275,9 +1287,14 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable):
Will only work with indices that represent the default git index as
they have not been initialized with a stream.
"""
+
+ # only run if we are the default repository index
+ if self._file_path != self._index_path():
+ raise AssertionError(
+ "Cannot call %r on indices that do not represent the default git index" % self.diff())
# index against index is always empty
if other is self.Index:
- return diff.DiffIndex()
+ return git_diff.DiffIndex()
# index against anything but None is a reverse diff with the respective
# item. Handle existing -R flags properly. Transform strings to the object
diff --git a/git/index/fun.py b/git/index/fun.py
index ffd109b1..e5e566a0 100644
--- a/git/index/fun.py
+++ b/git/index/fun.py
@@ -57,6 +57,8 @@ from git.types import PathLike, TypeGuard
if TYPE_CHECKING:
from .base import IndexFile
+ from git.objects.tree import TreeCacheTup
+ # from git.objects.fun import EntryTupOrNone
# ------------------------------------------------------------------------------------
@@ -186,16 +188,15 @@ def entry_key(*entry: Union[BaseIndexEntry, PathLike, int]) -> Tuple[PathLike, i
""":return: Key suitable to be used for the index.entries dictionary
:param entry: One instance of type BaseIndexEntry or the path and the stage"""
- def is_entry_tuple(entry: Tuple) -> TypeGuard[Tuple[PathLike, int]]:
- return isinstance(entry, tuple) and len(entry) == 2
-
+ def is_entry_key_tup(entry_key: Tuple) -> TypeGuard[Tuple[PathLike, int]]:
+ return isinstance(entry_key, tuple) and len(entry_key) == 2
+
if len(entry) == 1:
entry_first = entry[0]
assert isinstance(entry_first, BaseIndexEntry)
return (entry_first.path, entry_first.stage)
else:
- # entry = tuple(entry)
- assert is_entry_tuple(entry)
+ assert is_entry_key_tup(entry)
return entry
# END handle entry
@@ -249,7 +250,7 @@ def read_cache(stream: IO[bytes]) -> Tuple[int, Dict[Tuple[PathLike, int], 'Inde
def write_tree_from_cache(entries: List[IndexEntry], odb, sl: slice, si: int = 0
- ) -> Tuple[bytes, List[Tuple[str, int, str]]]:
+ ) -> Tuple[bytes, List['TreeCacheTup']]:
"""Create a tree from the given sorted list of entries and put the respective
trees into the given object database
@@ -259,8 +260,8 @@ def write_tree_from_cache(entries: List[IndexEntry], odb, sl: slice, si: int = 0
:param sl: slice indicating the range we should process on the entries list
:return: tuple(binsha, list(tree_entry, ...)) a tuple of a sha and a list of
tree entries being a tuple of hexsha, mode, name"""
- tree_items = [] # type: List[Tuple[Union[bytes, str], int, str]]
- tree_items_append = tree_items.append
+ tree_items: List['TreeCacheTup'] = []
+
ci = sl.start
end = sl.stop
while ci < end:
@@ -272,7 +273,7 @@ def write_tree_from_cache(entries: List[IndexEntry], odb, sl: slice, si: int = 0
rbound = entry.path.find('/', si)
if rbound == -1:
# its not a tree
- tree_items_append((entry.binsha, entry.mode, entry.path[si:]))
+ tree_items.append((entry.binsha, entry.mode, entry.path[si:]))
else:
# find common base range
base = entry.path[si:rbound]
@@ -289,7 +290,7 @@ def write_tree_from_cache(entries: List[IndexEntry], odb, sl: slice, si: int = 0
# enter recursion
# ci - 1 as we want to count our current item as well
sha, _tree_entry_list = write_tree_from_cache(entries, odb, slice(ci - 1, xi), rbound + 1)
- tree_items_append((sha, S_IFDIR, base))
+ tree_items.append((sha, S_IFDIR, base))
# skip ahead
ci = xi
@@ -298,15 +299,14 @@ def write_tree_from_cache(entries: List[IndexEntry], odb, sl: slice, si: int = 0
# finally create the tree
sio = BytesIO()
- tree_to_stream(tree_items, sio.write) # converts bytes of each item[0] to str
- tree_items_stringified = cast(List[Tuple[str, int, str]], tree_items)
+ tree_to_stream(tree_items, sio.write) # writes to stream as bytes, but doesnt change tree_items
sio.seek(0)
istream = odb.store(IStream(str_tree_type, len(sio.getvalue()), sio))
- return (istream.binsha, tree_items_stringified)
+ return (istream.binsha, tree_items)
-def _tree_entry_to_baseindexentry(tree_entry: Tuple[str, int, str], stage: int) -> BaseIndexEntry:
+def _tree_entry_to_baseindexentry(tree_entry: 'TreeCacheTup', stage: int) -> BaseIndexEntry:
return BaseIndexEntry((tree_entry[1], tree_entry[0], stage << CE_STAGESHIFT, tree_entry[2]))
@@ -319,14 +319,13 @@ def aggressive_tree_merge(odb, tree_shas: Sequence[bytes]) -> List[BaseIndexEntr
:param tree_shas: 1, 2 or 3 trees as identified by their binary 20 byte shas
If 1 or two, the entries will effectively correspond to the last given tree
If 3 are given, a 3 way merge is performed"""
- out = [] # type: List[BaseIndexEntry]
- out_append = out.append
+ out: List[BaseIndexEntry] = []
# one and two way is the same for us, as we don't have to handle an existing
# index, instrea
if len(tree_shas) in (1, 2):
for entry in traverse_tree_recursive(odb, tree_shas[-1], ''):
- out_append(_tree_entry_to_baseindexentry(entry, 0))
+ out.append(_tree_entry_to_baseindexentry(entry, 0))
# END for each entry
return out
# END handle single tree
@@ -347,23 +346,23 @@ def aggressive_tree_merge(odb, tree_shas: Sequence[bytes]) -> List[BaseIndexEntr
if(base[0] != ours[0] and base[0] != theirs[0] and ours[0] != theirs[0]) or \
(base[1] != ours[1] and base[1] != theirs[1] and ours[1] != theirs[1]):
# changed by both
- out_append(_tree_entry_to_baseindexentry(base, 1))
- out_append(_tree_entry_to_baseindexentry(ours, 2))
- out_append(_tree_entry_to_baseindexentry(theirs, 3))
+ out.append(_tree_entry_to_baseindexentry(base, 1))
+ out.append(_tree_entry_to_baseindexentry(ours, 2))
+ out.append(_tree_entry_to_baseindexentry(theirs, 3))
elif base[0] != ours[0] or base[1] != ours[1]:
# only we changed it
- out_append(_tree_entry_to_baseindexentry(ours, 0))
+ out.append(_tree_entry_to_baseindexentry(ours, 0))
else:
# either nobody changed it, or they did. In either
# case, use theirs
- out_append(_tree_entry_to_baseindexentry(theirs, 0))
+ out.append(_tree_entry_to_baseindexentry(theirs, 0))
# END handle modification
else:
if ours[0] != base[0] or ours[1] != base[1]:
# they deleted it, we changed it, conflict
- out_append(_tree_entry_to_baseindexentry(base, 1))
- out_append(_tree_entry_to_baseindexentry(ours, 2))
+ out.append(_tree_entry_to_baseindexentry(base, 1))
+ out.append(_tree_entry_to_baseindexentry(ours, 2))
# else:
# we didn't change it, ignore
# pass
@@ -376,8 +375,8 @@ def aggressive_tree_merge(odb, tree_shas: Sequence[bytes]) -> List[BaseIndexEntr
else:
if theirs[0] != base[0] or theirs[1] != base[1]:
# deleted in ours, changed theirs, conflict
- out_append(_tree_entry_to_baseindexentry(base, 1))
- out_append(_tree_entry_to_baseindexentry(theirs, 3))
+ out.append(_tree_entry_to_baseindexentry(base, 1))
+ out.append(_tree_entry_to_baseindexentry(theirs, 3))
# END theirs changed
# else:
# theirs didn't change
@@ -388,18 +387,19 @@ def aggressive_tree_merge(odb, tree_shas: Sequence[bytes]) -> List[BaseIndexEntr
# all three can't be None
if ours is None:
# added in their branch
- out_append(_tree_entry_to_baseindexentry(theirs, 0))
+ assert theirs is not None
+ out.append(_tree_entry_to_baseindexentry(theirs, 0))
elif theirs is None:
# added in our branch
- out_append(_tree_entry_to_baseindexentry(ours, 0))
+ out.append(_tree_entry_to_baseindexentry(ours, 0))
else:
# both have it, except for the base, see whether it changed
if ours[0] != theirs[0] or ours[1] != theirs[1]:
- out_append(_tree_entry_to_baseindexentry(ours, 2))
- out_append(_tree_entry_to_baseindexentry(theirs, 3))
+ out.append(_tree_entry_to_baseindexentry(ours, 2))
+ out.append(_tree_entry_to_baseindexentry(theirs, 3))
else:
# it was added the same in both
- out_append(_tree_entry_to_baseindexentry(ours, 0))
+ out.append(_tree_entry_to_baseindexentry(ours, 0))
# END handle two items
# END handle heads
# END handle base exists
diff --git a/git/index/util.py b/git/index/util.py
index 471e9262..4f8af553 100644
--- a/git/index/util.py
+++ b/git/index/util.py
@@ -11,9 +11,12 @@ import os.path as osp
# typing ----------------------------------------------------------------------
-from typing import (Any, Callable)
+from typing import (Any, Callable, TYPE_CHECKING)
-from git.types import PathLike
+from git.types import PathLike, _T
+
+if TYPE_CHECKING:
+ from git.index import IndexFile
# ---------------------------------------------------------------------------------
@@ -52,7 +55,7 @@ class TemporaryFileSwap(object):
#{ Decorators
-def post_clear_cache(func: Callable[..., Any]) -> Callable[..., Any]:
+def post_clear_cache(func: Callable[..., _T]) -> Callable[..., _T]:
"""Decorator for functions that alter the index using the git command. This would
invalidate our possibly existing entries dictionary which is why it must be
deleted to allow it to be lazily reread later.
@@ -63,7 +66,7 @@ def post_clear_cache(func: Callable[..., Any]) -> Callable[..., Any]:
"""
@wraps(func)
- def post_clear_cache_if_not_raised(self, *args: Any, **kwargs: Any) -> Any:
+ def post_clear_cache_if_not_raised(self: 'IndexFile', *args: Any, **kwargs: Any) -> _T:
rval = func(self, *args, **kwargs)
self._delete_entries_cache()
return rval
@@ -72,13 +75,13 @@ def post_clear_cache(func: Callable[..., Any]) -> Callable[..., Any]:
return post_clear_cache_if_not_raised
-def default_index(func: Callable[..., Any]) -> Callable[..., Any]:
+def default_index(func: Callable[..., _T]) -> Callable[..., _T]:
"""Decorator assuring the wrapped method may only run if we are the default
repository index. This is as we rely on git commands that operate
on that index only. """
@wraps(func)
- def check_default_index(self, *args: Any, **kwargs: Any) -> Any:
+ def check_default_index(self: 'IndexFile', *args: Any, **kwargs: Any) -> _T:
if self._file_path != self._index_path():
raise AssertionError(
"Cannot call %r on indices that do not represent the default git index" % func.__name__)
@@ -88,14 +91,14 @@ def default_index(func: Callable[..., Any]) -> Callable[..., Any]:
return check_default_index
-def git_working_dir(func: Callable[..., Any]) -> Callable[..., None]:
+def git_working_dir(func: Callable[..., _T]) -> Callable[..., _T]:
"""Decorator which changes the current working dir to the one of the git
repository in order to assure relative paths are handled correctly"""
@wraps(func)
- def set_git_working_dir(self, *args: Any, **kwargs: Any) -> None:
+ def set_git_working_dir(self: 'IndexFile', *args: Any, **kwargs: Any) -> _T:
cur_wd = os.getcwd()
- os.chdir(self.repo.working_tree_dir)
+ os.chdir(str(self.repo.working_tree_dir))
try:
return func(self, *args, **kwargs)
finally: