diff options
author | Sebastian Thiel <sebastian.thiel@icloud.com> | 2022-05-19 07:56:34 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-19 07:56:34 +0800 |
commit | d96f671b9be24ec46f0fcd078b51e322bb8b8146 (patch) | |
tree | 833dfce594c5606e78fb536bc383580ab33d09c2 | |
parent | 38e9a18b976b2b7e3b3cd0fcd5b037573823d7c2 (diff) | |
parent | 8232b170a28f946f5a04472912b3e73777c44465 (diff) | |
download | gitpython-d96f671b9be24ec46f0fcd078b51e322bb8b8146.tar.gz |
Merge pull request #1440 from rdbisme/index-pathlike
fix: Allow adding PathLike object to index
-rw-r--r-- | git/index/base.py | 4 | ||||
-rw-r--r-- | test/test_index.py | 11 |
2 files changed, 13 insertions, 2 deletions
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)) 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 |