|
5 | 5 | # the BSD License: http://www.opensource.org/licenses/bsd-license.php
|
6 | 6 |
|
7 | 7 | import glob
|
8 |
| -from io import BytesIO |
9 | 8 | import os
|
10 |
| -from stat import S_ISLNK |
| 9 | +import os.path as osp |
11 | 10 | import subprocess
|
12 | 11 | import tempfile
|
13 |
| - |
14 |
| -from git.compat import ( |
15 |
| - force_bytes, |
16 |
| - defenc, |
17 |
| -) |
18 |
| -from git.exc import ( |
19 |
| - GitCommandError, |
20 |
| - CheckoutError, |
21 |
| - GitError, |
22 |
| - InvalidGitRepositoryError |
23 |
| -) |
24 |
| -from git.objects import ( |
25 |
| - Blob, |
26 |
| - Submodule, |
27 |
| - Tree, |
28 |
| - Object, |
29 |
| - Commit, |
| 12 | +from io import BytesIO |
| 13 | +from stat import S_ISLNK |
| 14 | +from typing import ( |
| 15 | + IO, |
| 16 | + TYPE_CHECKING, |
| 17 | + Any, |
| 18 | + BinaryIO, |
| 19 | + Callable, |
| 20 | + Dict, |
| 21 | + Iterable, |
| 22 | + Iterator, |
| 23 | + List, |
| 24 | + NoReturn, |
| 25 | + Sequence, |
| 26 | + Tuple, |
| 27 | + Type, |
| 28 | + Union, |
30 | 29 | )
|
| 30 | + |
| 31 | +import git.diff as git_diff |
| 32 | +from git.compat import defenc, force_bytes |
| 33 | +from git.exc import CheckoutError, GitCommandError, GitError, InvalidGitRepositoryError |
| 34 | +from git.objects import Blob, Commit, Object, Submodule, Tree |
31 | 35 | from git.objects.util import Serializable
|
| 36 | +from git.types import Commit_ish, PathLike |
32 | 37 | from git.util import (
|
33 | 38 | LazyMixin,
|
34 | 39 | LockedFD,
|
35 |
| - join_path_native, |
36 | 40 | file_contents_ro,
|
| 41 | + join_path_native, |
| 42 | + to_bin_sha, |
37 | 43 | to_native_path_linux,
|
38 | 44 | unbare_repo,
|
39 |
| - to_bin_sha |
40 | 45 | )
|
41 | 46 | from gitdb.base import IStream
|
42 | 47 | from gitdb.db import MemoryDB
|
43 | 48 |
|
44 |
| -import git.diff as git_diff |
45 |
| -import os.path as osp |
46 |
| - |
47 | 49 | from .fun import (
|
| 50 | + S_IFGITLINK, |
| 51 | + aggressive_tree_merge, |
48 | 52 | entry_key,
|
49 |
| - write_cache, |
50 | 53 | read_cache,
|
51 |
| - aggressive_tree_merge, |
52 |
| - write_tree_from_cache, |
| 54 | + run_commit_hook, |
53 | 55 | stat_mode_to_index_mode,
|
54 |
| - S_IFGITLINK, |
55 |
| - run_commit_hook |
56 |
| -) |
57 |
| -from .typ import ( |
58 |
| - BaseIndexEntry, |
59 |
| - IndexEntry, |
60 |
| -) |
61 |
| -from .util import ( |
62 |
| - TemporaryFileSwap, |
63 |
| - post_clear_cache, |
64 |
| - default_index, |
65 |
| - git_working_dir |
| 56 | + write_cache, |
| 57 | + write_tree_from_cache, |
66 | 58 | )
|
| 59 | +from .typ import BaseIndexEntry, IndexEntry |
| 60 | +from .util import TemporaryFileSwap, default_index, git_working_dir, post_clear_cache |
67 | 61 |
|
68 | 62 | # typing -----------------------------------------------------------------------------
|
69 | 63 |
|
70 |
| -from typing import (Any, BinaryIO, Callable, Dict, IO, Iterable, Iterator, List, NoReturn, |
71 |
| - Sequence, TYPE_CHECKING, Tuple, Type, Union) |
72 | 64 |
|
73 |
| -from git.types import Commit_ish, PathLike |
74 | 65 |
|
75 | 66 | if TYPE_CHECKING:
|
76 | 67 | from subprocess import Popen
|
77 |
| - from git.repo import Repo |
| 68 | + |
78 | 69 | from git.refs.reference import Reference
|
| 70 | + from git.repo import Repo |
79 | 71 | from git.util import Actor
|
80 | 72 |
|
81 | 73 |
|
@@ -594,11 +586,11 @@ def _preprocess_add_items(self, items: Sequence[Union[PathLike, Blob, BaseIndexE
|
594 | 586 | paths = []
|
595 | 587 | entries = []
|
596 | 588 | # if it is a string put in list
|
597 |
| - if isinstance(items, str): |
| 589 | + if isinstance(items, (str, os.PathLike)): |
598 | 590 | items = [items]
|
599 | 591 |
|
600 | 592 | for item in items:
|
601 |
| - if isinstance(item, str): |
| 593 | + if isinstance(item, (str, os.PathLike)): |
602 | 594 | paths.append(self._to_relative_path(item))
|
603 | 595 | elif isinstance(item, (Blob, Submodule)):
|
604 | 596 | entries.append(BaseIndexEntry.from_blob(item))
|
|
0 commit comments