Repository: gitpython-developers/GitPython

Issue:
repo.index.add() first argument type accepts os.PathLike but code raises TypeError
In the docs and in the code types, the first argument for `repo.index.add()` is `Sequence[Union[str, os.PathLike, git.objects.blob.Blob, git.index.typ.BaseIndexEntry, Submodule]]`.
However, actually trying to submit a list of Paths to this argument results in a TypeError, as it seems the code inside `_preprocess_add_items` does not handle Paths.

I think this could be fixed by changing line 611 inside of `_preprocess_add_items` in `base.py` to:
```
 if isinstance(item, str) or isinstance(item, os.PathLike):
```
https://github.com/gitpython-developers/GitPython/blob/fe54118ec07a68d5dc6f6108510cffc55dfca643/git/index/base.py#L611
Since `_to_relative_path()` already accepts pathlike arguments.

Discussion:
Byron: May I ask to resubmit without the code formatting? I am happy to run it through `black` to unify the style and if it doesn't make it (too much) worse, but that should be a separate step.

All these changes are like noise to the signal making a review harder than it has to be. Thanks.
rdbisme: Not sure why this is failing.

Patch:
diff --git a/git/index/base.py b/git/index/base.py
index edc64875..1c56a219 100644
--- a/git/index/base.py
+++ b/git/index/base.py
@@ -617,11 +617,11 @@ class IndexFile(LazyMixin, git_diff.Diffable, Serializable):
         paths = []
         entries = []
         # if it is a string put in list
-        if isinstance(items, str):
+        if isinstance(items, (str, os.PathLike)):
             items = [items]
 
         for item in items:
-            if isinstance(item, str):
+            if isinstance(item, (str, os.PathLike)):
                 paths.append(self._to_relative_path(item))
             elif isinstance(item, (Blob, Submodule)):
                 entries.append(BaseIndexEntry.from_blob(item))


Test patch:
diff --git a/test/test_index.py b/test/test_index.py
index d6e0fb81..3bebb382 100644
--- a/test/test_index.py
+++ b/test/test_index.py
@@ -37,6 +37,8 @@ from gitdb.base import IStream
 import os.path as osp
 from git.cmd import Git
 
+from pathlib import Path
+
 HOOKS_SHEBANG = "#!/usr/bin/env sh\n"
 
 is_win_without_bash = is_win and not shutil.which("bash.exe")
@@ -943,3 +945,12 @@ class TestIndex(TestBase):
                 assert str(err)
         else:
             raise AssertionError("Should have caught a HookExecutionError")
+
+    @with_rw_repo('HEAD')
+    def test_index_add_pathlike(self, rw_repo):
+        git_dir = Path(rw_repo.git_dir)
+
+        file = git_dir / "file.txt"
+        file.touch()
+
+        rw_repo.index.add(file)
\ No newline at end of file