diff options
-rw-r--r-- | doc/source/changes.rst | 7 | ||||
-rw-r--r-- | git/index/base.py | 8 | ||||
-rw-r--r-- | git/objects/submodule/base.py | 4 | ||||
-rw-r--r-- | git/objects/submodule/util.py | 16 | ||||
-rw-r--r-- | git/test/test_index.py | 12 | ||||
-rw-r--r-- | git/util.py | 22 |
6 files changed, 44 insertions, 25 deletions
diff --git a/doc/source/changes.rst b/doc/source/changes.rst index 4f67c1bb..2da3dad2 100644 --- a/doc/source/changes.rst +++ b/doc/source/changes.rst @@ -10,7 +10,12 @@ Changelog * DOCS: special members like `__init__` are now listed in the API documentation * DOCS: tutorial section was revised entirely * Added `Submodule.rename()` -* **POSSIBLY BREAKING CHANGE**: As `rev_parse` will now throw `BadName` as well as `BadObject`, client code will have to catch both exception types. +* **POSSIBLY BREAKING CHANGES** + + * As `rev_parse` will now throw `BadName` as well as `BadObject`, client code will have to catch both exception types. + * Repo.working_tree_dir now returns None if it is bare. Previously it raised AssertionError. + * IndexFile.add() previously raised AssertionError when paths where used with bare repository, now it raises InvalidGitRepositoryError + * A list of all issues can be found here: https://github.com/gitpython-developers/GitPython/issues?q=milestone%3A%22v0.3.6+-+Features%22+ 0.3.5 - Bugfixes diff --git a/git/index/base.py b/git/index/base.py index 7002385c..b73edd6f 100644 --- a/git/index/base.py +++ b/git/index/base.py @@ -27,7 +27,8 @@ from .util import ( import git.diff as diff from git.exc import ( GitCommandError, - CheckoutError + CheckoutError, + InvalidGitRepositoryError ) from git.objects import ( @@ -54,6 +55,7 @@ from git.util import ( join_path_native, file_contents_ro, to_native_path_linux, + unbare_repo ) from .fun import ( @@ -346,6 +348,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): return index # UTILITIES + @unbare_repo def _iter_expand_paths(self, paths): """Expand the directories in list of paths to the corresponding paths accordingly, @@ -536,6 +539,8 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): if it is not within our git direcotory""" if not os.path.isabs(path): return path + if self.repo.bare: + raise InvalidGitRepositoryError("require non-bare repository") relative_path = path.replace(self.repo.working_tree_dir + os.sep, "") if relative_path == path: raise ValueError("Absolute path %r is not in git repository at %r" % (path, self.repo.working_tree_dir)) @@ -575,6 +580,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): return BaseIndexEntry((stat_mode_to_index_mode(st.st_mode), istream.binsha, 0, to_native_path_linux(filepath))) + @unbare_repo @git_working_dir def _entries_for_paths(self, paths, path_rewriter, fprogress, entries): entries_added = list() diff --git a/git/objects/submodule/base.py b/git/objects/submodule/base.py index cd7d4ec4..94322a55 100644 --- a/git/objects/submodule/base.py +++ b/git/objects/submodule/base.py @@ -3,7 +3,6 @@ from .util import ( mkhead, sm_name, sm_section, - unbare_repo, SubmoduleConfigParser, find_first_remote_branch ) @@ -14,7 +13,8 @@ from git.util import ( join_path_native, to_native_path_linux, RemoteProgress, - rmtree + rmtree, + unbare_repo ) from git.config import ( diff --git a/git/objects/submodule/util.py b/git/objects/submodule/util.py index 8b9873fc..0b4ce3c5 100644 --- a/git/objects/submodule/util.py +++ b/git/objects/submodule/util.py @@ -4,7 +4,7 @@ from git.config import GitConfigParser from io import BytesIO import weakref -__all__ = ('sm_section', 'sm_name', 'mkhead', 'unbare_repo', 'find_first_remote_branch', +__all__ = ('sm_section', 'sm_name', 'mkhead', 'find_first_remote_branch', 'SubmoduleConfigParser') #{ Utilities @@ -26,20 +26,6 @@ def mkhead(repo, path): return git.Head(repo, git.Head.to_full_path(path)) -def unbare_repo(func): - """Methods with this decorator raise InvalidGitRepositoryError if they - encounter a bare repository""" - - def wrapper(self, *args, **kwargs): - if self.repo.bare: - raise InvalidGitRepositoryError("Method '%s' cannot operate on bare repositories" % func.__name__) - # END bare method - return func(self, *args, **kwargs) - # END wrapper - wrapper.__name__ = func.__name__ - return wrapper - - def find_first_remote_branch(remotes, branch_name): """Find the remote branch matching the name of the given branch or raise InvalidGitRepositoryError""" for remote in remotes: diff --git a/git/test/test_index.py b/git/test/test_index.py index 0569f40f..63f99f10 100644 --- a/git/test/test_index.py +++ b/git/test/test_index.py @@ -12,7 +12,10 @@ from git.test.lib import ( with_rw_repo ) from git.util import Actor -from git.exc import HookExecutionError +from git.exc import ( + HookExecutionError, + InvalidGitRepositoryError +) from git import ( IndexFile, BlobFilter, @@ -740,7 +743,8 @@ class TestIndex(TestBase): # property rw_bare_repo.working_tree_dir will return '/tmp' # instead of throwing the Exception we are expecting. This is # a quick hack to make this test fail when expected. - rw_bare_repo._working_tree_dir = None + assert rw_bare_repo.working_tree_dir is None + assert rw_bare_repo.bare contents = b'This is a BytesIO file' filesize = len(contents) fileobj = BytesIO(contents) @@ -758,6 +762,6 @@ class TestIndex(TestBase): path = os.path.join('git', 'test', 'test_index.py') try: rw_bare_repo.index.add([path]) - except Exception as e: - asserted = "does not have a working tree" in str(e) + except InvalidGitRepositoryError: + asserted = True assert asserted, "Adding using a filename is not correctly asserted." diff --git a/git/util.py b/git/util.py index 06fefcc3..02c54bc3 100644 --- a/git/util.py +++ b/git/util.py @@ -16,7 +16,11 @@ import threading # NOTE: Some of the unused imports might be used/imported by others. # Handle once test-cases are back up and running. -from .exc import GitCommandError +from .exc import ( + GitCommandError, + InvalidGitRepositoryError +) + from .compat import ( MAXSIZE, defenc, @@ -37,11 +41,25 @@ from gitdb.util import ( # NOQA __all__ = ("stream_copy", "join_path", "to_native_path_windows", "to_native_path_linux", "join_path_native", "Stats", "IndexFileSHA1Writer", "Iterable", "IterableList", "BlockingLockFile", "LockFile", 'Actor', 'get_user_id', 'assure_directory_exists', - 'RemoteProgress', 'rmtree', 'WaitGroup') + 'RemoteProgress', 'rmtree', 'WaitGroup', 'unbare_repo') #{ Utility Methods +def unbare_repo(func): + """Methods with this decorator raise InvalidGitRepositoryError if they + encounter a bare repository""" + + def wrapper(self, *args, **kwargs): + if self.repo.bare: + raise InvalidGitRepositoryError("Method '%s' cannot operate on bare repositories" % func.__name__) + # END bare method + return func(self, *args, **kwargs) + # END wrapper + wrapper.__name__ = func.__name__ + return wrapper + + def rmtree(path): """Remove the given recursively. |