Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix if items of Index is of type PathLike #1778

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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