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

Commitd565a87

Browse files
committed
Fixed regression in test-suite for IndexFile
Previously, it checked for AssertionErrors, now we have to implementneed-unbare-repo check ourselves.
1 parente4d3809 commitd565a87

File tree

6 files changed

+44
-25
lines changed

6 files changed

+44
-25
lines changed

‎doc/source/changes.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@ Changelog
1010
* DOCS: special members like `__init__` are now listed in the API documentation
1111
* DOCS: tutorial section was revised entirely
1212
* Added `Submodule.rename()`
13-
* **POSSIBLY BREAKING CHANGE**: As `rev_parse` will now throw `BadName` as well as `BadObject`, client code will have to catch both exception types.
13+
* **POSSIBLY BREAKING CHANGES**
14+
15+
* As `rev_parse` will now throw `BadName` as well as `BadObject`, client code will have to catch both exception types.
16+
* Repo.working_tree_dir now returns None if it is bare. Previously it raised AssertionError.
17+
* IndexFile.add() previously raised AssertionError when paths where used with bare repository, now it raises InvalidGitRepositoryError
18+
1419
* A list of all issues can be found here: https://github.com/gitpython-developers/GitPython/issues?q=milestone%3A%22v0.3.6+-+Features%22+
1520

1621
0.3.5 - Bugfixes

‎git/index/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
importgit.diffasdiff
2828
fromgit.excimport (
2929
GitCommandError,
30-
CheckoutError
30+
CheckoutError,
31+
InvalidGitRepositoryError
3132
)
3233

3334
fromgit.objectsimport (
@@ -54,6 +55,7 @@
5455
join_path_native,
5556
file_contents_ro,
5657
to_native_path_linux,
58+
unbare_repo
5759
)
5860

5961
from .funimport (
@@ -346,6 +348,7 @@ def from_tree(cls, repo, *treeish, **kwargs):
346348
returnindex
347349

348350
# UTILITIES
351+
@unbare_repo
349352
def_iter_expand_paths(self,paths):
350353
"""Expand the directories in list of paths to the corresponding paths accordingly,
351354
@@ -536,6 +539,8 @@ def _to_relative_path(self, path):
536539
if it is not within our git direcotory"""
537540
ifnotos.path.isabs(path):
538541
returnpath
542+
ifself.repo.bare:
543+
raiseInvalidGitRepositoryError("require non-bare repository")
539544
relative_path=path.replace(self.repo.working_tree_dir+os.sep,"")
540545
ifrelative_path==path:
541546
raiseValueError("Absolute path %r is not in git repository at %r"% (path,self.repo.working_tree_dir))
@@ -575,6 +580,7 @@ def _store_path(self, filepath, fprogress):
575580
returnBaseIndexEntry((stat_mode_to_index_mode(st.st_mode),
576581
istream.binsha,0,to_native_path_linux(filepath)))
577582

583+
@unbare_repo
578584
@git_working_dir
579585
def_entries_for_paths(self,paths,path_rewriter,fprogress,entries):
580586
entries_added=list()

‎git/objects/submodule/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
mkhead,
44
sm_name,
55
sm_section,
6-
unbare_repo,
76
SubmoduleConfigParser,
87
find_first_remote_branch
98
)
@@ -14,7 +13,8 @@
1413
join_path_native,
1514
to_native_path_linux,
1615
RemoteProgress,
17-
rmtree
16+
rmtree,
17+
unbare_repo
1818
)
1919

2020
fromgit.configimport (

‎git/objects/submodule/util.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
fromioimportBytesIO
55
importweakref
66

7-
__all__= ('sm_section','sm_name','mkhead','unbare_repo','find_first_remote_branch',
7+
__all__= ('sm_section','sm_name','mkhead','find_first_remote_branch',
88
'SubmoduleConfigParser')
99

1010
#{ Utilities
@@ -26,20 +26,6 @@ def mkhead(repo, path):
2626
returngit.Head(repo,git.Head.to_full_path(path))
2727

2828

29-
defunbare_repo(func):
30-
"""Methods with this decorator raise InvalidGitRepositoryError if they
31-
encounter a bare repository"""
32-
33-
defwrapper(self,*args,**kwargs):
34-
ifself.repo.bare:
35-
raiseInvalidGitRepositoryError("Method '%s' cannot operate on bare repositories"%func.__name__)
36-
# END bare method
37-
returnfunc(self,*args,**kwargs)
38-
# END wrapper
39-
wrapper.__name__=func.__name__
40-
returnwrapper
41-
42-
4329
deffind_first_remote_branch(remotes,branch_name):
4430
"""Find the remote branch matching the name of the given branch or raise InvalidGitRepositoryError"""
4531
forremoteinremotes:

‎git/test/test_index.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
with_rw_repo
1313
)
1414
fromgit.utilimportActor
15-
fromgit.excimportHookExecutionError
15+
fromgit.excimport (
16+
HookExecutionError,
17+
InvalidGitRepositoryError
18+
)
1619
fromgitimport (
1720
IndexFile,
1821
BlobFilter,
@@ -740,7 +743,8 @@ def test_index_bare_add(self, rw_bare_repo):
740743
# property rw_bare_repo.working_tree_dir will return '/tmp'
741744
# instead of throwing the Exception we are expecting. This is
742745
# a quick hack to make this test fail when expected.
743-
rw_bare_repo._working_tree_dir=None
746+
assertrw_bare_repo.working_tree_dirisNone
747+
assertrw_bare_repo.bare
744748
contents=b'This is a BytesIO file'
745749
filesize=len(contents)
746750
fileobj=BytesIO(contents)
@@ -758,6 +762,6 @@ def test_index_bare_add(self, rw_bare_repo):
758762
path=os.path.join('git','test','test_index.py')
759763
try:
760764
rw_bare_repo.index.add([path])
761-
exceptExceptionase:
762-
asserted="does not have a working tree"instr(e)
765+
exceptInvalidGitRepositoryError:
766+
asserted=True
763767
assertasserted,"Adding using a filename is not correctly asserted."

‎git/util.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616

1717
# NOTE: Some of the unused imports might be used/imported by others.
1818
# Handle once test-cases are back up and running.
19-
from .excimportGitCommandError
19+
from .excimport (
20+
GitCommandError,
21+
InvalidGitRepositoryError
22+
)
23+
2024
from .compatimport (
2125
MAXSIZE,
2226
defenc,
@@ -37,11 +41,25 @@
3741
__all__= ("stream_copy","join_path","to_native_path_windows","to_native_path_linux",
3842
"join_path_native","Stats","IndexFileSHA1Writer","Iterable","IterableList",
3943
"BlockingLockFile","LockFile",'Actor','get_user_id','assure_directory_exists',
40-
'RemoteProgress','rmtree','WaitGroup')
44+
'RemoteProgress','rmtree','WaitGroup','unbare_repo')
4145

4246
#{ Utility Methods
4347

4448

49+
defunbare_repo(func):
50+
"""Methods with this decorator raise InvalidGitRepositoryError if they
51+
encounter a bare repository"""
52+
53+
defwrapper(self,*args,**kwargs):
54+
ifself.repo.bare:
55+
raiseInvalidGitRepositoryError("Method '%s' cannot operate on bare repositories"%func.__name__)
56+
# END bare method
57+
returnfunc(self,*args,**kwargs)
58+
# END wrapper
59+
wrapper.__name__=func.__name__
60+
returnwrapper
61+
62+
4563
defrmtree(path):
4664
"""Remove the given recursively.
4765

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp