Skip to content

Commit d565a87

Browse files
committed
Fixed regression in test-suite for IndexFile
Previously, it checked for AssertionErrors, now we have to implement need-unbare-repo check ourselves.
1 parent e4d3809 commit d565a87

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
import git.diff as diff
2828
from git.exc import (
2929
GitCommandError,
30-
CheckoutError
30+
CheckoutError,
31+
InvalidGitRepositoryError
3132
)
3233

3334
from git.objects import (
@@ -54,6 +55,7 @@
5455
join_path_native,
5556
file_contents_ro,
5657
to_native_path_linux,
58+
unbare_repo
5759
)
5860

5961
from .fun import (
@@ -346,6 +348,7 @@ def from_tree(cls, repo, *treeish, **kwargs):
346348
return index
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
if not os.path.isabs(path):
538541
return path
542+
if self.repo.bare:
543+
raise InvalidGitRepositoryError("require non-bare repository")
539544
relative_path = path.replace(self.repo.working_tree_dir + os.sep, "")
540545
if relative_path == path:
541546
raise ValueError("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
return BaseIndexEntry((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
from git.config import (

git/objects/submodule/util.py

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from io import BytesIO
55
import weakref
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
return git.Head(repo, git.Head.to_full_path(path))
2727

2828

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

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
from git.util import Actor
15-
from git.exc import HookExecutionError
15+
from git.exc import (
16+
HookExecutionError,
17+
InvalidGitRepositoryError
18+
)
1619
from git import (
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+
assert rw_bare_repo.working_tree_dir is None
747+
assert rw_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-
except Exception as e:
762-
asserted = "does not have a working tree" in str(e)
765+
except InvalidGitRepositoryError:
766+
asserted = True
763767
assert asserted, "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 .exc import GitCommandError
19+
from .exc import (
20+
GitCommandError,
21+
InvalidGitRepositoryError
22+
)
23+
2024
from .compat import (
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+
def unbare_repo(func):
50+
"""Methods with this decorator raise InvalidGitRepositoryError if they
51+
encounter a bare repository"""
52+
53+
def wrapper(self, *args, **kwargs):
54+
if self.repo.bare:
55+
raise InvalidGitRepositoryError("Method '%s' cannot operate on bare repositories" % func.__name__)
56+
# END bare method
57+
return func(self, *args, **kwargs)
58+
# END wrapper
59+
wrapper.__name__ = func.__name__
60+
return wrapper
61+
62+
4563
def rmtree(path):
4664
"""Remove the given recursively.
4765

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy