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

Commit80701fc

Browse files
committed
Submodule.parent_commit() now automatically points to repo.head unless it was set before.
That way, you don't always have to keep the parent commit uptodate when changing therepo, which can lead to errors which are hard to debug and make no sense to the user,who previously never set parent_commit (yet it matters thanks to the cache).
1 parent9fbae71 commit80701fc

File tree

2 files changed

+42
-33
lines changed

2 files changed

+42
-33
lines changed

‎git/objects/submodule/base.py

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ def __init__(self, repo, binsha, mode=None, path=None, name=None, parent_commit=
9898
:param branch_path: full (relative) path to ref to checkout when cloning the remote repository"""
9999
super(Submodule,self).__init__(repo,binsha,mode,path)
100100
self.size=0
101-
ifparent_commitisnotNone:
102-
self._parent_commit=parent_commit
101+
self._parent_commit=parent_commit
103102
ifurlisnotNone:
104103
self._url=url
105104
ifbranch_pathisnotNone:
@@ -109,18 +108,15 @@ def __init__(self, repo, binsha, mode=None, path=None, name=None, parent_commit=
109108
self._name=name
110109

111110
def_set_cache_(self,attr):
112-
ifattr=='_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-
exceptValueError:
117-
# This fails in an empty repository.
118-
self._parent_commit=None
119-
# end exception handling
120-
elifattrin ('path','_url','_branch_path'):
111+
ifattrin ('path','_url','_branch_path'):
121112
reader=self.config_reader()
122113
# default submodule values
123-
self.path=reader.get_value('path')
114+
try:
115+
self.path=reader.get_value('path')
116+
exceptcp.NoSectionError:
117+
raiseValueError("This submodule instance does not exist anymore in '%s' file"
118+
%os.path.join(self.repo.working_tree_dir,'.gitmodules'))
119+
# end
124120
self._url=reader.get_value('url')
125121
# git-python extension values - optional
126122
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):
170166
:raise IOError: If the .gitmodules file cannot be found, either locally or in the repository
171167
at the given parent commit. Otherwise the exception would be delayed until the first
172168
access of the config parser"""
173-
try:
174-
parent_matches_head=repo.head.commit==parent_commit
175-
exceptValueError:
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+
ifparent_commitisnotNone:
171+
try:
172+
parent_matches_head=repo.head.commit==parent_commit
173+
exceptValueError:
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
179177

180178
ifnotrepo.bareandparent_matches_head:
181179
fp_module=os.path.join(repo.working_tree_dir,cls.k_modules_file)
182180
else:
181+
assertparent_commitisnotNone,"need valid parent_commit in bare repositories"
183182
try:
184183
fp_module=cls._sio_modules(parent_commit)
185184
exceptKeyError:
@@ -213,7 +212,12 @@ def _sio_modules(cls, parent_commit):
213212

214213
def_config_parser_constrained(self,read_only):
215214
""":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+
exceptValueError:
218+
pc=None
219+
# end hande empty parent repository
220+
parser=self._config_parser(self.repo,pc,read_only)
217221
parser.set_submodule(self)
218222
returnSectionConstraint(parser,sm_section(self.name))
219223

@@ -407,9 +411,10 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False):
407411
del(writer)
408412

409413
# we deliberatly assume that our head matches our index !
410-
parent_repo_is_empty=False
414+
411415
try:
412-
sm._parent_commit=repo.head.commit
416+
repo.head.commit
417+
parent_repo_is_empty=False
413418
exceptValueError:
414419
parent_repo_is_empty=True
415420
# 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):
418423
index.add([sm],write=True)
419424

420425
ifparent_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-
delsm._parent_commit
424426
log.debug("Will not set _parent_commit now as the parent repository has no commit yet.")
425427
# end
426428

@@ -885,13 +887,18 @@ def remove(self, module=True, force=False, configuration=True, dry_run=False):
885887
defset_parent_commit(self,commit,check=True):
886888
"""Set this instance to use the given commit whose tree is supposed to
887889
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
889892
:param check: if True, relatively expensive checks will be performed to verify
890893
validity of the submodule.
891894
:raise ValueError: if the commit's tree didn't contain the .gitmodules blob.
892895
:raise ValueError: if the parent commit didn't store this submodule under the
893896
current path
894897
:return: self"""
898+
ifcommitisNone:
899+
self._parent_commit=None
900+
returnself
901+
# end handle None
895902
pcommit=self.repo.commit(commit)
896903
pctree=pcommit.tree
897904
ifself.k_modules_filenotinpctree:
@@ -1036,7 +1043,7 @@ def exists(self):
10361043
ifhasattr(self,attr):
10371044
loc[attr]=getattr(self,attr)
10381045
# END if we have the attribute cache
1039-
exceptcp.NoSectionError:
1046+
except(cp.NoSectionError,ValueError):
10401047
# on PY3, this can happen apparently ... don't know why this doesn't happen on PY2
10411048
pass
10421049
# END for each attr
@@ -1086,6 +1093,8 @@ def url(self):
10861093
defparent_commit(self):
10871094
""":return: Commit instance with the tree containing the .gitmodules file
10881095
:note: will always point to the current head's commit if it was not set explicitly"""
1096+
ifself._parent_commitisNone:
1097+
returnself.repo.commit()
10891098
returnself._parent_commit
10901099

10911100
@property
@@ -1157,7 +1166,9 @@ def iter_items(cls, repo, parent_commit='HEAD'):
11571166

11581167
# fill in remaining info - saves time as it doesn't have to be parsed again
11591168
sm._name=n
1160-
sm._parent_commit=pc
1169+
ifpc!=repo.commit():
1170+
sm._parent_commit=pc
1171+
# end set only if not most recent !
11611172
sm._branch_path=git.Head.to_full_path(b)
11621173
sm._url=u
11631174

‎git/test/test_submodule.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -320,9 +320,11 @@ def _do_base_tests(self, rwrepo):
320320
assertsm.config_reader().get_value('url')
321321

322322
# delete the rest
323+
sm_path=sm.path
323324
sm.remove()
324325
assertnotsm.exists()
325326
assertnotsm.module_exists()
327+
self.failUnlessRaises(ValueError,getattr,sm,'path')
326328

327329
assertlen(rwrepo.submodules)==0
328330

@@ -359,11 +361,11 @@ def _do_base_tests(self, rwrepo):
359361

360362
# MOVE MODULE
361363
#############
362-
# invalidinptu
364+
# invalidinput
363365
self.failUnlessRaises(ValueError,nsm.move,'doesntmatter',module=False,configuration=False)
364366

365367
# renaming to the same path does nothing
366-
assertnsm.move(sm.path)isnsm
368+
assertnsm.move(sm_path)isnsm
367369

368370
# rename a module
369371
nmp=join_path_native("new","module","dir")+"/"# new module path
@@ -708,7 +710,6 @@ def assert_exists(sm, value=True):
708710

709711
# test move
710712
new_sm_path='submodules/one'
711-
sm.set_parent_commit(parent.commit())
712713
sm.move(new_sm_path)
713714
assert_exists(sm)
714715

@@ -717,7 +718,6 @@ def assert_exists(sm, value=True):
717718
url=self._submodule_url())
718719
sm.module().index.commit("added nested submodule")
719720
sm_head_commit=sm.module().commit()
720-
csm.set_parent_commit(sm_head_commit)
721721
assert_exists(csm)
722722

723723
# Fails because there are new commits, compared to the remote we cloned from
@@ -739,7 +739,6 @@ def assert_exists(sm, value=True):
739739
csm_writer=csm.config_writer().set_value('url','foo')
740740
csm_writer.release()
741741
csm.repo.index.commit("Have to commit submodule change for algorithm to pick it up")
742-
csm.set_parent_commit(csm.repo.commit())
743742
assertcsm.url=='foo'
744743

745744
self.failUnlessRaises(Exception,rsm.update,recursive=True,to_latest_revision=True,progress=prog)
@@ -760,7 +759,6 @@ def test_rename(self, rwdir):
760759
sm_name='mymodules/myname'
761760
sm=parent.create_submodule(sm_name,sm_name,url=self._submodule_url())
762761
parent.index.commit("Added submodule")
763-
assertsm._parent_commitisnotNone
764762

765763
assertsm.rename(sm_name)issmandsm.name==sm_name
766764
assertnotsm.repo.is_dirty(index=True,working_tree=False,untracked_files=False)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp