| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9fbae71 commit 80701fc
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -98,8 +98,7 @@ def __init__(self, repo, binsha, mode=None, path=None, name=None, parent_commit= | |||
| 98 | 98 | :param branch_path: full (relative) path to ref to checkout when cloning the remote repository""" | |
| 99 | 99 | super(Submodule, self).__init__(repo, binsha, mode, path) | |
| 100 | 100 | self.size = 0 | |
| 101 | - if parent_commit is not None: | ||
| 102 | - self._parent_commit = parent_commit | ||
| 101 | + self._parent_commit = parent_commit | ||
| 103 | 102 | if url is not None: | |
| 104 | 103 | self._url = url | |
| 105 | 104 | if branch_path is not None: | |
@@ -109,18 +108,15 @@ def __init__(self, repo, binsha, mode=None, path=None, name=None, parent_commit= | |||
| 109 | 108 | self._name = name | |
| 110 | 109 | ||
| 111 | 110 | def _set_cache_(self, attr): | |
| 112 | - if attr == '_parent_commit': | ||
| 113 | - # set a default value, which is the root tree of the current head | ||
| 114 | - try: | ||
| 115 | - self._parent_commit = self.repo.commit() | ||
| 116 | - except ValueError: | ||
| 117 | - # This fails in an empty repository. | ||
| 118 | - self._parent_commit = None | ||
| 119 | - # end exception handling | ||
| 120 | - elif attr in ('path', '_url', '_branch_path'): | ||
| 111 | + if attr in ('path', '_url', '_branch_path'): | ||
| 121 | 112 | reader = self.config_reader() | |
| 122 | 113 | # default submodule values | |
| 123 | - self.path = reader.get_value('path') | ||
| 114 | + try: | ||
| 115 | + self.path = reader.get_value('path') | ||
| 116 | + except cp.NoSectionError: | ||
| 117 | + raise ValueError("This submodule instance does not exist anymore in '%s' file" | ||
| 118 | + % os.path.join(self.repo.working_tree_dir, '.gitmodules')) | ||
| 119 | + # end | ||
| 124 | 120 | self._url = reader.get_value('url') | |
| 125 | 121 | # git-python extension values - optional | |
| 126 | 122 | self._branch_path = reader.get_value(self.k_head_option, git.Head.to_full_path(self.k_head_default)) | |
@@ -170,16 +166,19 @@ def _config_parser(cls, repo, parent_commit, read_only): | |||
| 170 | 166 | :raise IOError: If the .gitmodules file cannot be found, either locally or in the repository | |
| 171 | 167 | at the given parent commit. Otherwise the exception would be delayed until the first | |
| 172 | 168 | access of the config parser""" | |
| 173 | - try: | ||
| 174 | - parent_matches_head = repo.head.commit == parent_commit | ||
| 175 | - except ValueError: | ||
| 176 | - # We are most likely in an empty repository, so the HEAD doesn't point to a valid ref | ||
| 177 | - parent_matches_head = True | ||
| 178 | - # end | ||
| 169 | + parent_matches_head = True | ||
| 170 | + if parent_commit is not None: | ||
| 171 | + try: | ||
| 172 | + parent_matches_head = repo.head.commit == parent_commit | ||
| 173 | + except ValueError: | ||
| 174 | + # We are most likely in an empty repository, so the HEAD doesn't point to a valid ref | ||
| 175 | + pass | ||
| 176 | + # end hanlde parent_commit | ||
| 179 | 177 | ||
| 180 | 178 | if not repo.bare and parent_matches_head: | |
| 181 | 179 | fp_module = os.path.join(repo.working_tree_dir, cls.k_modules_file) | |
| 182 | 180 | else: | |
| 181 | + assert parent_commit is not None, "need valid parent_commit in bare repositories" | ||
| 183 | 182 | try: | |
| 184 | 183 | fp_module = cls._sio_modules(parent_commit) | |
| 185 | 184 | except KeyError: | |
@@ -213,7 +212,12 @@ def _sio_modules(cls, parent_commit): | |||
| 213 | 212 | ||
| 214 | 213 | def _config_parser_constrained(self, read_only): | |
| 215 | 214 | """:return: Config Parser constrained to our submodule in read or write mode""" | |
| 216 | - parser = self._config_parser(self.repo, self._parent_commit, read_only) | ||
| 215 | + try: | ||
| 216 | + pc = self.parent_commit | ||
| 217 | + except ValueError: | ||
| 218 | + pc = None | ||
| 219 | + # end hande empty parent repository | ||
| 220 | + parser = self._config_parser(self.repo, pc, read_only) | ||
| 217 | 221 | parser.set_submodule(self) | |
| 218 | 222 | return SectionConstraint(parser, sm_section(self.name)) | |
| 219 | 223 | ||
@@ -407,9 +411,10 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False): | |||
| 407 | 411 | del(writer) | |
| 408 | 412 | ||
| 409 | 413 | # we deliberatly assume that our head matches our index ! | |
| 410 | - parent_repo_is_empty = False | ||
| 414 | + | ||
| 411 | 415 | try: | |
| 412 | - sm._parent_commit = repo.head.commit | ||
| 416 | + repo.head.commit | ||
| 417 | + parent_repo_is_empty = False | ||
| 413 | 418 | except ValueError: | |
| 414 | 419 | parent_repo_is_empty = True | |
| 415 | 420 | # Can't set this yet, if the parent repo is empty. | |
@@ -418,9 +423,6 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False): | |||
| 418 | 423 | index.add([sm], write=True) | |
| 419 | 424 | ||
| 420 | 425 | if parent_repo_is_empty: | |
| 421 | - # The user is expected to make a commit, and this submodule will initialize itself when | ||
| 422 | - # _parent_commit is required | ||
| 423 | - del sm._parent_commit | ||
| 424 | 426 | log.debug("Will not set _parent_commit now as the parent repository has no commit yet.") | |
| 425 | 427 | # end | |
| 426 | 428 | ||
@@ -885,13 +887,18 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False): | |||
| 885 | 887 | def set_parent_commit(self, commit, check=True): | |
| 886 | 888 | """Set this instance to use the given commit whose tree is supposed to | |
| 887 | 889 | contain the .gitmodules blob. | |
| 888 | - :param commit: Commit'ish reference pointing at the root_tree, or None always point to the most recent commit | ||
| 890 | + :param commit: Commit'ish reference pointing at the root_tree, or None to always point to the | ||
| 891 | + most recent commit | ||
| 889 | 892 | :param check: if True, relatively expensive checks will be performed to verify | |
| 890 | 893 | validity of the submodule. | |
| 891 | 894 | :raise ValueError: if the commit's tree didn't contain the .gitmodules blob. | |
| 892 | 895 | :raise ValueError: if the parent commit didn't store this submodule under the | |
| 893 | 896 | current path | |
| 894 | 897 | :return: self""" | |
| 898 | + if commit is None: | ||
| 899 | + self._parent_commit = None | ||
| 900 | + return self | ||
| 901 | + # end handle None | ||
| 895 | 902 | pcommit = self.repo.commit(commit) | |
| 896 | 903 | pctree = pcommit.tree | |
| 897 | 904 | if self.k_modules_file not in pctree: | |
@@ -1036,7 +1043,7 @@ def exists(self): | |||
| 1036 | 1043 | if hasattr(self, attr): | |
| 1037 | 1044 | loc[attr] = getattr(self, attr) | |
| 1038 | 1045 | # END if we have the attribute cache | |
| 1039 | - except cp.NoSectionError: | ||
| 1046 | + except (cp.NoSectionError, ValueError): | ||
| 1040 | 1047 | # on PY3, this can happen apparently ... don't know why this doesn't happen on PY2 | |
| 1041 | 1048 | pass | |
| 1042 | 1049 | # END for each attr | |
@@ -1086,6 +1093,8 @@ def url(self): | |||
| 1086 | 1093 | def parent_commit(self): | |
| 1087 | 1094 | """:return: Commit instance with the tree containing the .gitmodules file | |
| 1088 | 1095 | :note: will always point to the current head's commit if it was not set explicitly""" | |
| 1096 | + if self._parent_commit is None: | ||
| 1097 | + return self.repo.commit() | ||
| 1089 | 1098 | return self._parent_commit | |
| 1090 | 1099 | ||
| 1091 | 1100 | @property | |
@@ -1157,7 +1166,9 @@ def iter_items(cls, repo, parent_commit='HEAD'): | |||
| 1157 | 1166 | ||
| 1158 | 1167 | # fill in remaining info - saves time as it doesn't have to be parsed again | |
| 1159 | 1168 | sm._name = n | |
| 1160 | - sm._parent_commit = pc | ||
| 1169 | + if pc != repo.commit(): | ||
| 1170 | + sm._parent_commit = pc | ||
| 1171 | + # end set only if not most recent ! | ||
| 1161 | 1172 | sm._branch_path = git.Head.to_full_path(b) | |
| 1162 | 1173 | sm._url = u | |
| 1163 | 1174 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -320,9 +320,11 @@ def _do_base_tests(self, rwrepo): | |||
| 320 | 320 | assert sm.config_reader().get_value('url') | |
| 321 | 321 | ||
| 322 | 322 | # delete the rest | |
| 323 | + sm_path = sm.path | ||
| 323 | 324 | sm.remove() | |
| 324 | 325 | assert not sm.exists() | |
| 325 | 326 | assert not sm.module_exists() | |
| 327 | + self.failUnlessRaises(ValueError, getattr, sm, 'path') | ||
| 326 | 328 | ||
| 327 | 329 | assert len(rwrepo.submodules) == 0 | |
| 328 | 330 | ||
@@ -359,11 +361,11 @@ def _do_base_tests(self, rwrepo): | |||
| 359 | 361 | ||
| 360 | 362 | # MOVE MODULE | |
| 361 | 363 | ############# | |
| 362 | - # invalid inptu | ||
| 364 | + # invalid input | ||
| 363 | 365 | self.failUnlessRaises(ValueError, nsm.move, 'doesntmatter', module=False, configuration=False) | |
| 364 | 366 | ||
| 365 | 367 | # renaming to the same path does nothing | |
| 366 | - assert nsm.move(sm.path) is nsm | ||
| 368 | + assert nsm.move(sm_path) is nsm | ||
| 367 | 369 | ||
| 368 | 370 | # rename a module | |
| 369 | 371 | nmp = join_path_native("new", "module", "dir") + "/" # new module path | |
@@ -708,7 +710,6 @@ def assert_exists(sm, value=True): | |||
| 708 | 710 | ||
| 709 | 711 | # test move | |
| 710 | 712 | new_sm_path = 'submodules/one' | |
| 711 | - sm.set_parent_commit(parent.commit()) | ||
| 712 | 713 | sm.move(new_sm_path) | |
| 713 | 714 | assert_exists(sm) | |
| 714 | 715 | ||
@@ -717,7 +718,6 @@ def assert_exists(sm, value=True): | |||
| 717 | 718 | url=self._submodule_url()) | |
| 718 | 719 | sm.module().index.commit("added nested submodule") | |
| 719 | 720 | sm_head_commit = sm.module().commit() | |
| 720 | - csm.set_parent_commit(sm_head_commit) | ||
| 721 | 721 | assert_exists(csm) | |
| 722 | 722 | ||
| 723 | 723 | # Fails because there are new commits, compared to the remote we cloned from | |
@@ -739,7 +739,6 @@ def assert_exists(sm, value=True): | |||
| 739 | 739 | csm_writer = csm.config_writer().set_value('url', 'foo') | |
| 740 | 740 | csm_writer.release() | |
| 741 | 741 | csm.repo.index.commit("Have to commit submodule change for algorithm to pick it up") | |
| 742 | - csm.set_parent_commit(csm.repo.commit()) | ||
| 743 | 742 | assert csm.url == 'foo' | |
| 744 | 743 | ||
| 745 | 744 | self.failUnlessRaises(Exception, rsm.update, recursive=True, to_latest_revision=True, progress=prog) | |
@@ -760,7 +759,6 @@ def test_rename(self, rwdir): | |||
| 760 | 759 | sm_name = 'mymodules/myname' | |
| 761 | 760 | sm = parent.create_submodule(sm_name, sm_name, url=self._submodule_url()) | |
| 762 | 761 | parent.index.commit("Added submodule") | |
| 763 | - assert sm._parent_commit is not None | ||
| 764 | 762 | ||
| 765 | 763 | assert sm.rename(sm_name) is sm and sm.name == sm_name | |
| 766 | 764 | assert not sm.repo.is_dirty(index=True, working_tree=False, untracked_files=False) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments