Skip to content

Commit

Permalink
Merge pull request #1778 from stegm/fix_index_with_pathlike
Browse files Browse the repository at this point in the history
Fix if items of Index is of type PathLike
  • Loading branch information
Byron committed Dec 22, 2023
2 parents c398d79 + 6e4cee4 commit d986a59
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion git/index/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ def _items_to_rela_paths(
for item in items:
if isinstance(item, (BaseIndexEntry, (Blob, Submodule))):
paths.append(self._to_relative_path(item.path))
elif isinstance(item, str):
elif isinstance(item, (str, os.PathLike)):
paths.append(self._to_relative_path(item))
else:
raise TypeError("Invalid item type: %r" % item)
Expand Down
12 changes: 7 additions & 5 deletions test/test_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -558,14 +558,16 @@ def test_index_mutation(self, rw_repo):
def mixed_iterator():
count = 0
for entry in index.entries.values():
type_id = count % 4
if type_id == 0: # path
type_id = count % 5
if type_id == 0: # path (str)
yield entry.path
elif type_id == 1: # blob
elif type_id == 1: # path (PathLike)
yield Path(entry.path)
elif type_id == 2: # blob
yield Blob(rw_repo, entry.binsha, entry.mode, entry.path)
elif type_id == 2: # BaseIndexEntry
elif type_id == 3: # BaseIndexEntry
yield BaseIndexEntry(entry[:4])
elif type_id == 3: # IndexEntry
elif type_id == 4: # IndexEntry
yield entry
else:
raise AssertionError("Invalid Type")
Expand Down

0 comments on commit d986a59

Please sign in to comment.