| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,7 +10,12 @@ Changelog | |||
| 10 | 10 | * DOCS: special members like `__init__` are now listed in the API documentation | |
| 11 | 11 | * DOCS: tutorial section was revised entirely | |
| 12 | 12 | * 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 | + | ||
| 14 | 19 | * A list of all issues can be found here: https://github.com/gitpython-developers/GitPython/issues?q=milestone%3A%22v0.3.6+-+Features%22+ | |
| 15 | 20 | ||
| 16 | 21 | 0.3.5 - Bugfixes | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -27,7 +27,8 @@ | |||
| 27 | 27 | import git.diff as diff | |
| 28 | 28 | from git.exc import ( | |
| 29 | 29 | GitCommandError, | |
| 30 | - CheckoutError | ||
| 30 | + CheckoutError, | ||
| 31 | + InvalidGitRepositoryError | ||
| 31 | 32 | ) | |
| 32 | 33 | ||
| 33 | 34 | from git.objects import ( | |
@@ -54,6 +55,7 @@ | |||
| 54 | 55 | join_path_native, | |
| 55 | 56 | file_contents_ro, | |
| 56 | 57 | to_native_path_linux, | |
| 58 | + unbare_repo | ||
| 57 | 59 | ) | |
| 58 | 60 | ||
| 59 | 61 | from .fun import ( | |
@@ -346,6 +348,7 @@ def from_tree(cls, repo, *treeish, **kwargs): | |||
| 346 | 348 | return index | |
| 347 | 349 | ||
| 348 | 350 | # UTILITIES | |
| 351 | + @unbare_repo | ||
| 349 | 352 | def _iter_expand_paths(self, paths): | |
| 350 | 353 | """Expand the directories in list of paths to the corresponding paths accordingly, | |
| 351 | 354 | ||
@@ -536,6 +539,8 @@ def _to_relative_path(self, path): | |||
| 536 | 539 | if it is not within our git direcotory""" | |
| 537 | 540 | if not os.path.isabs(path): | |
| 538 | 541 | return path | |
| 542 | + if self.repo.bare: | ||
| 543 | + raise InvalidGitRepositoryError("require non-bare repository") | ||
| 539 | 544 | relative_path = path.replace(self.repo.working_tree_dir + os.sep, "") | |
| 540 | 545 | if relative_path == path: | |
| 541 | 546 | 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): | |||
| 575 | 580 | return BaseIndexEntry((stat_mode_to_index_mode(st.st_mode), | |
| 576 | 581 | istream.binsha, 0, to_native_path_linux(filepath))) | |
| 577 | 582 | ||
| 583 | + @unbare_repo | ||
| 578 | 584 | @git_working_dir | |
| 579 | 585 | def _entries_for_paths(self, paths, path_rewriter, fprogress, entries): | |
| 580 | 586 | entries_added = list() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,7 +3,6 @@ | |||
| 3 | 3 | mkhead, | |
| 4 | 4 | sm_name, | |
| 5 | 5 | sm_section, | |
| 6 | - unbare_repo, | ||
| 7 | 6 | SubmoduleConfigParser, | |
| 8 | 7 | find_first_remote_branch | |
| 9 | 8 | ) | |
@@ -14,7 +13,8 @@ | |||
| 14 | 13 | join_path_native, | |
| 15 | 14 | to_native_path_linux, | |
| 16 | 15 | RemoteProgress, | |
| 17 | - rmtree | ||
| 16 | + rmtree, | ||
| 17 | + unbare_repo | ||
| 18 | 18 | ) | |
| 19 | 19 | ||
| 20 | 20 | from git.config import ( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,7 +4,7 @@ | |||
| 4 | 4 | from io import BytesIO | |
| 5 | 5 | import weakref | |
| 6 | 6 | ||
| 7 | - __all__ = ('sm_section', 'sm_name', 'mkhead', 'unbare_repo', 'find_first_remote_branch', | ||
| 7 | + __all__ = ('sm_section', 'sm_name', 'mkhead', 'find_first_remote_branch', | ||
| 8 | 8 | 'SubmoduleConfigParser') | |
| 9 | 9 | ||
| 10 | 10 | #{ Utilities | |
@@ -26,20 +26,6 @@ def mkhead(repo, path): | |||
| 26 | 26 | return git.Head(repo, git.Head.to_full_path(path)) | |
| 27 | 27 | ||
| 28 | 28 | ||
| 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 | - | ||
| 43 | 29 | def find_first_remote_branch(remotes, branch_name): | |
| 44 | 30 | """Find the remote branch matching the name of the given branch or raise InvalidGitRepositoryError""" | |
| 45 | 31 | for remote in remotes: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,7 +12,10 @@ | |||
| 12 | 12 | with_rw_repo | |
| 13 | 13 | ) | |
| 14 | 14 | from git.util import Actor | |
| 15 | - from git.exc import HookExecutionError | ||
| 15 | + from git.exc import ( | ||
| 16 | + HookExecutionError, | ||
| 17 | + InvalidGitRepositoryError | ||
| 18 | + ) | ||
| 16 | 19 | from git import ( | |
| 17 | 20 | IndexFile, | |
| 18 | 21 | BlobFilter, | |
@@ -740,7 +743,8 @@ def test_index_bare_add(self, rw_bare_repo): | |||
| 740 | 743 | # property rw_bare_repo.working_tree_dir will return '/tmp' | |
| 741 | 744 | # instead of throwing the Exception we are expecting. This is | |
| 742 | 745 | # 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 | ||
| 744 | 748 | contents = b'This is a BytesIO file' | |
| 745 | 749 | filesize = len(contents) | |
| 746 | 750 | fileobj = BytesIO(contents) | |
@@ -758,6 +762,6 @@ def test_index_bare_add(self, rw_bare_repo): | |||
| 758 | 762 | path = os.path.join('git', 'test', 'test_index.py') | |
| 759 | 763 | try: | |
| 760 | 764 | 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 | ||
| 763 | 767 | assert asserted, "Adding using a filename is not correctly asserted." | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,11 @@ | |||
| 16 | 16 | ||
| 17 | 17 | # NOTE: Some of the unused imports might be used/imported by others. | |
| 18 | 18 | # Handle once test-cases are back up and running. | |
| 19 | - from .exc import GitCommandError | ||
| 19 | + from .exc import ( | ||
| 20 | + GitCommandError, | ||
| 21 | + InvalidGitRepositoryError | ||
| 22 | + ) | ||
| 23 | + | ||
| 20 | 24 | from .compat import ( | |
| 21 | 25 | MAXSIZE, | |
| 22 | 26 | defenc, | |
@@ -37,11 +41,25 @@ | |||
| 37 | 41 | __all__ = ("stream_copy", "join_path", "to_native_path_windows", "to_native_path_linux", | |
| 38 | 42 | "join_path_native", "Stats", "IndexFileSHA1Writer", "Iterable", "IterableList", | |
| 39 | 43 | "BlockingLockFile", "LockFile", 'Actor', 'get_user_id', 'assure_directory_exists', | |
| 40 | - 'RemoteProgress', 'rmtree', 'WaitGroup') | ||
| 44 | + 'RemoteProgress', 'rmtree', 'WaitGroup', 'unbare_repo') | ||
| 41 | 45 | ||
| 42 | 46 | #{ Utility Methods | |
| 43 | 47 | ||
| 44 | 48 | ||
| 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 | + | ||
| 45 | 63 | def rmtree(path): | |
| 46 | 64 | """Remove the given recursively. | |
| 47 | 65 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments