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

Commitaf5abca

Browse files
committed
Added a few utility methods and improved the test. Refs need an improvement though to allow easy configuration of branch-specific settings
1 parentd4fd7fc commitaf5abca

File tree

2 files changed

+64
-17
lines changed

2 files changed

+64
-17
lines changed

‎lib/git/objects/submodule.py

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,17 @@ def update(self, recursive=False, init=True):
251251
local_branch=git.Head(mrepo,git.Head.to_full_path(self.branch))
252252
ifnotlocal_branch.is_valid():
253253
mrepo.git.checkout(remote_branch,b=self.branch)
254+
else:
255+
# have a valid branch, but no checkout - make sure we can figure
256+
# that out by marking the commit with a null_sha
257+
# have to write it directly as .commit = NULLSHA tries to resolve the sha
258+
ref=mrepo.head.ref
259+
refpath=join_path_native(mrepo.git_dir,ref.to_full_path(ref.path))
260+
refdir=os.path.dirname(refpath)
261+
ifnotos.path.isdir(refdir):
262+
os.makedirs(refdir)
263+
#END handle directory
264+
open(refpath,'w').write(self.NULL_HEX_SHA)
254265
# END initial checkout + branch creation
255266
# make sure we are not detached
256267
mrepo.head.ref=local_branch
@@ -259,24 +270,24 @@ def update(self, recursive=False, init=True):
259270
#END handle tracking branch
260271
#END handle initalization
261272

262-
#if thecommit to checkout is on the current branch, merge the branch
263-
ifmrepo.head.is_detached:
264-
ifmrepo.head.commit.binsha!=self.binsha:
273+
#update theworking tree
274+
ifmrepo.head.commit.binsha!=self.binsha:
275+
ifmrepo.head.is_detached:
265276
mrepo.git.checkout(self.hexsha)
266-
# END checkout commit
267-
else:
268-
# TODO:allow to specify a rebase, merge, or reset
269-
# TODO: Warn if the hexsha forces the tracking branch offtheremote
270-
# branch - this should be prevented when setting the branch option
271-
mrepo.head.reset(self.hexsha,index=True,working_tree=True)
272-
# END handle checkout
273-
274-
ifrecursive:
275-
forsubmoduleinself.iter_items(self.module()):
276-
submodule.update(recursive,init)
277-
# ENDhandle recursive update
278-
# ENDfor each submodule
279-
277+
else:
278+
# TODO: allow to specify a rebase, merge, or reset
279+
# TODO:Warn if the hexsha forces the tracking branch off the remote
280+
# branch - this should be prevented when settingthebranch option
281+
mrepo.head.reset(self.hexsha,index=True,working_tree=True)
282+
# END handle checkout
283+
284+
ifrecursive:
285+
forsubmoduleinself.iter_items(self.module()):
286+
submodule.update(recursive,init)
287+
# END handlerecursive update
288+
# ENDfor each submodule
289+
# ENDupdate to new commit only if needed
290+
280291
returnself
281292

282293
defset_parent_commit(self,commit,check=True):
@@ -354,6 +365,15 @@ def module(self):
354365
defmodule_path(self):
355366
""":return: full path to the root of our module. It is relative to the filesystem root"""
356367
returnjoin_path_native(self.repo.working_tree_dir,self.path)
368+
369+
defmodule_exists(self):
370+
""":return: True if our module exists and is a valid git repository. See module() method"""
371+
try:
372+
self.module()
373+
returnTrue
374+
exceptInvalidGitRepositoryError:
375+
returnFalse
376+
# END handle exception
357377

358378
@property
359379
defbranch(self):
@@ -391,6 +411,12 @@ def config_reader(self):
391411
:raise IOError: If the .gitmodules file/blob could not be read"""
392412
returnself._config_parser_constrained(read_only=True)
393413

414+
defchildren(self):
415+
""":return: IterableList(Submodule, ...) an iterable list of submodules instances
416+
which are children of this submodule
417+
:raise InvalidGitRepositoryError: if the submodule is not checked-out"""
418+
returnself._get_intermediate_items(self)
419+
394420
#} END query interface
395421

396422
#{ Iterable Interface

‎test/git/test_submodule.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ def _do_base_tests(self, rwrepo):
8888
else:
8989
# its not checked out in our case
9090
self.failUnlessRaises(InvalidGitRepositoryError,sm.module)
91+
assertnotsm.module_exists()
92+
93+
# currently there is only one submodule
94+
assertlen(list(rwrepo.iter_submodules()))==1
9195

9296
# lets update it - its a recursive one too
9397
newdir=os.path.join(sm.module_path(),'dir')
@@ -98,12 +102,29 @@ def _do_base_tests(self, rwrepo):
98102
os.rmdir(newdir)
99103

100104
assertsm.update()issm
105+
assertsm.module_exists()
101106
assertisinstance(sm.module(),git.Repo)
102107
assertsm.module().working_tree_dir==sm.module_path()
103108

104109
# delete the whole directory and re-initialize
105110
shutil.rmtree(sm.module_path())
111+
sm.update(recursive=False)
112+
assertlen(list(rwrepo.iter_submodules()))==2
113+
assertlen(sm.children())==1# its not checked out yet
114+
csm=sm.children()[0]
115+
assertnotcsm.module_exists()
116+
117+
# adjust the path of the submodules module to point to the local destination
118+
new_csm_path=to_native_path_linux(join_path_native(self.rorepo.working_tree_dir,sm.path,csm.path))
119+
csm.config_writer().set_value('url',new_csm_path)
120+
assertcsm.url==new_csm_path
121+
122+
123+
# update recuesively again
106124
sm.update(recursive=True)
125+
126+
# this flushed in a sub-submodule
127+
assertlen(list(rwrepo.iter_submodules()))==2
107128
# END handle bare mode
108129

109130

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp