@@ -144,6 +144,9 @@ def __hash__(self):
144144 """Hash this instance using its logical id, not the sha"""
145145 return hash (self ._name )
146146
147+ def __str__ (self ):
148+ return self ._name
149+
147150 @classmethod
148151 def _config_parser (cls , repo , parent_commit , read_only ):
149152 """:return: Config Parser constrained to our submodule in read or write mode
@@ -250,20 +253,24 @@ def update(self, recursive=False, init=True):
250253 remote_branch = mrepo .remotes .origin .refs [self .branch ]
251254 local_branch = git .Head (mrepo , git .Head .to_full_path (self .branch ))
252255 if not local_branch .is_valid ():
253- 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- if not os .path .isdir (refdir ):
262- os .makedirs (refdir )
263- #END handle directory
264- open (refpath , 'w' ).write (self .NULL_HEX_SHA )
256+ # Setup a tracking configuration - branch doesn't need to
257+ # exist to do that
258+ local_branch .set_tracking_branch (remote_branch )
259+ #END handle local branch
260+
261+ # have a valid branch, but no checkout - make sure we can figure
262+ # that out by marking the commit with a null_sha
263+ # have to write it directly as .commit = NULLSHA tries to resolve the sha
264+ # This will bring the branch into existance
265+ refpath = join_path_native (mrepo .git_dir , local_branch .path )
266+ refdir = os .path .dirname (refpath )
267+ if not os .path .isdir (refdir ):
268+ os .makedirs (refdir )
269+ #END handle directory
270+ open (refpath , 'w' ).write (self .NULL_HEX_SHA )
265271 # END initial checkout + branch creation
266- # make sure we are not detached
272+
273+ # make sure HEAD is not detached
267274 mrepo .head .ref = local_branch
268275 except IndexError :
269276 print >> sys .stderr , "Warning: Failed to checkout tracking branch %s" % self .branch
@@ -280,13 +287,14 @@ def update(self, recursive=False, init=True):
280287 # branch - this should be prevented when setting the branch option
281288 mrepo .head .reset (self .hexsha , index = True , working_tree = True )
282289 # END handle checkout
283-
284- if recursive :
285- for submodule in self .iter_items (self .module ()):
286- submodule .update (recursive , init )
287- # END handle recursive update
288- # END for each submodule
289290 # END update to new commit only if needed
291+
292+ # HANDLE RECURSION
293+ if recursive :
294+ for submodule in self .iter_items (self .module ()):
295+ submodule .update (recursive , init )
296+ # END handle recursive update
297+ # END for each submodule
290298
291299 return self
292300
0 commit comments