Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0c43ee3

Browse files
author
Ruben DI BATTISTA
committed
fix: Allow adding PathLike object to index
Close#1382
1 parentb30720e commit0c43ee3

File tree

2 files changed

+62
-77
lines changed

2 files changed

+62
-77
lines changed

‎git/index/base.py

Lines changed: 37 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,77 +5,69 @@
55
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
66

77
importglob
8-
fromioimportBytesIO
98
importos
10-
fromstatimportS_ISLNK
9+
importos.pathasosp
1110
importsubprocess
1211
importtempfile
13-
14-
fromgit.compatimport(
15-
force_bytes,
16-
defenc,
17-
)
18-
fromgit.excimport (
19-
GitCommandError,
20-
CheckoutError,
21-
GitError,
22-
InvalidGitRepositoryError
23-
)
24-
fromgit.objectsimport (
25-
Blob,
26-
Submodule,
27-
Tree,
28-
Object,
29-
Commit,
12+
fromioimportBytesIO
13+
fromstatimportS_ISLNK
14+
fromtypingimport (
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,
3029
)
30+
31+
importgit.diffasgit_diff
32+
fromgit.compatimportdefenc,force_bytes
33+
fromgit.excimportCheckoutError,GitCommandError,GitError,InvalidGitRepositoryError
34+
fromgit.objectsimportBlob,Commit,Object,Submodule,Tree
3135
fromgit.objects.utilimportSerializable
36+
fromgit.typesimportCommit_ish,PathLike
3237
fromgit.utilimport (
3338
LazyMixin,
3439
LockedFD,
35-
join_path_native,
3640
file_contents_ro,
41+
join_path_native,
42+
to_bin_sha,
3743
to_native_path_linux,
3844
unbare_repo,
39-
to_bin_sha
4045
)
4146
fromgitdb.baseimportIStream
4247
fromgitdb.dbimportMemoryDB
4348

44-
importgit.diffasgit_diff
45-
importos.pathasosp
46-
4749
from .funimport (
50+
S_IFGITLINK,
51+
aggressive_tree_merge,
4852
entry_key,
49-
write_cache,
5053
read_cache,
51-
aggressive_tree_merge,
52-
write_tree_from_cache,
54+
run_commit_hook,
5355
stat_mode_to_index_mode,
54-
S_IFGITLINK,
55-
run_commit_hook
56-
)
57-
from .typimport (
58-
BaseIndexEntry,
59-
IndexEntry,
60-
)
61-
from .utilimport (
62-
TemporaryFileSwap,
63-
post_clear_cache,
64-
default_index,
65-
git_working_dir
56+
write_cache,
57+
write_tree_from_cache,
6658
)
59+
from .typimportBaseIndexEntry,IndexEntry
60+
from .utilimportTemporaryFileSwap,default_index,git_working_dir,post_clear_cache
6761

6862
# typing -----------------------------------------------------------------------------
6963

70-
fromtypingimport (Any,BinaryIO,Callable,Dict,IO,Iterable,Iterator,List,NoReturn,
71-
Sequence,TYPE_CHECKING,Tuple,Type,Union)
7264

73-
fromgit.typesimportCommit_ish,PathLike
7465

7566
ifTYPE_CHECKING:
7667
fromsubprocessimportPopen
77-
fromgit.repoimportRepo
68+
7869
fromgit.refs.referenceimportReference
70+
fromgit.repoimportRepo
7971
fromgit.utilimportActor
8072

8173

@@ -594,11 +586,11 @@ def _preprocess_add_items(self, items: Sequence[Union[PathLike, Blob, BaseIndexE
594586
paths= []
595587
entries= []
596588
# if it is a string put in list
597-
ifisinstance(items,str):
589+
ifisinstance(items,(str,os.PathLike)):
598590
items= [items]
599591

600592
foriteminitems:
601-
ifisinstance(item,str):
593+
ifisinstance(item,(str,os.PathLike)):
602594
paths.append(self._to_relative_path(item))
603595
elifisinstance(item, (Blob,Submodule)):
604596
entries.append(BaseIndexEntry.from_blob(item))

‎test/test_index.py

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,36 @@
55
# This module is part of GitPython and is released under
66
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
77

8-
fromioimportBytesIO
98
importos
10-
fromstatimport (
11-
S_ISLNK,
12-
ST_MODE
13-
)
9+
importos.pathasosp
10+
importshutil
1411
importtempfile
12+
fromioimportBytesIO
13+
frompathlibimportPath
14+
fromstatimportS_ISLNK,ST_MODE
15+
fromtest.libimportTestBase,fixture,fixture_path,with_rw_directory,with_rw_repo
1516
fromunittestimportskipIf
16-
importshutil
1717

1818
fromgitimport (
19-
IndexFile,
20-
Repo,
2119
BlobFilter,
22-
UnmergedEntriesError,
23-
Tree,
24-
Object,
20+
CheckoutError,
2521
Diff,
2622
GitCommandError,
27-
CheckoutError,
23+
IndexFile,
24+
Object,
25+
Repo,
26+
Tree,
27+
UnmergedEntriesError,
2828
)
29+
fromgit.cmdimportGit
2930
fromgit.compatimportis_win
30-
fromgit.excimport (
31-
HookExecutionError,
32-
InvalidGitRepositoryError
33-
)
31+
fromgit.excimportHookExecutionError,InvalidGitRepositoryError
3432
fromgit.index.funimporthook_path
35-
fromgit.index.typimport (
36-
BaseIndexEntry,
37-
IndexEntry
38-
)
33+
fromgit.index.typimportBaseIndexEntry,IndexEntry
3934
fromgit.objectsimportBlob
40-
fromtest.libimport (
41-
TestBase,
42-
fixture_path,
43-
fixture,
44-
with_rw_repo
45-
)
46-
fromtest.libimportwith_rw_directory
47-
fromgit.utilimportActor,rmtree
48-
fromgit.utilimportHIDE_WINDOWS_KNOWN_ERRORS,hex_to_bin
35+
fromgit.utilimportHIDE_WINDOWS_KNOWN_ERRORS,Actor,hex_to_bin,rmtree
4936
fromgitdb.baseimportIStream
5037

51-
importos.pathasosp
52-
fromgit.cmdimportGit
53-
5438
HOOKS_SHEBANG="#!/usr/bin/env sh\n"
5539

5640
is_win_without_bash=is_winandnotshutil.which('bash.exe')
@@ -937,3 +921,12 @@ def test_commit_msg_hook_fail(self, rw_repo):
937921
assertstr(err)
938922
else:
939923
raiseAssertionError("Should have caught a HookExecutionError")
924+
925+
@with_rw_repo('HEAD')
926+
deftest_index_add_pathlike(self,rw_repo):
927+
git_dir=Path(rw_repo.git_dir)
928+
929+
file=git_dir/"file.txt"
930+
file.touch()
931+
932+
rw_repo.index.add(file)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp