@@ -119,27 +119,25 @@ def status(self):
119119 atag = atag [:- 1 ]
120120 if atag == self .fxtag :
121121 break
122-
123-
124- #print(f"line is {line} ahash is {ahash} atag is {atag} {parts}")
125- # atag = git.git_operation("describe", "--tags", "--always")
126- # ahash = git.git_operation("rev-list", "HEAD").partition("\n")[0]
127-
128122 recurse = False
129123 if rurl != self .url :
130124 remote = self ._add_remote (git )
131125 git .git_operation ("fetch" , remote )
126+ # Asked for a tag and found that tag
132127 if self .fxtag and atag == self .fxtag :
133128 result = f" { self .name :>20} at tag { self .fxtag } "
134129 recurse = True
135130 testfails = False
131+ # Asked for and found a hash
136132 elif self .fxtag and (ahash [: len (self .fxtag )] == self .fxtag or (self .fxtag .find (ahash )== 0 )):
137133 result = f" { self .name :>20} at hash { ahash } "
138134 recurse = True
139135 testfails = False
136+ # Asked for and found a hash
140137 elif atag == ahash :
141138 result = f" { self .name :>20} at hash { ahash } "
142139 recurse = True
140+ # Did not find requested tag or hash
143141 elif self .fxtag :
144142 result = f"s { self .name :>20} { atag } { ahash } is out of sync with .gitmodules { self .fxtag } "
145143 testfails = True
@@ -284,17 +282,18 @@ def sparse_checkout(self):
284282 if not os .path .isdir (infodir ):
285283 os .makedirs (infodir )
286284 gitsparse = os .path .abspath (os .path .join (infodir , "sparse-checkout" ))
287- if os .path .isfile (gitsparse ):
288- self .logger .warning (
289- "submodule {} is already initialized {}" .format (self .name , rootdotgit )
290- )
291- return
292-
293- with utils .pushd (sprep_repo ):
285+ if os .path .isfile (gitsparse ):
286+ self .logger .warning (
287+ "submodule {} is already initialized {}" .format (self .name , rootdotgit )
288+ )
289+ os .remove (gitsparse )
290+
294291 if os .path .isfile (self .fxsparse ):
295-
296292 shutil .copy (self .fxsparse , gitsparse )
297-
293+ else :
294+ self .logger .warning (
295+ "submodule {} could not find {}" .format (self .name , self .fxsparse )
296+ )
298297
299298 # Finally checkout the repo
300299 sprepo_git .git_operation ("fetch" , "origin" , "--tags" )
@@ -303,11 +302,18 @@ def sparse_checkout(self):
303302 print (f"Error checking out { self .name :>20} at { self .fxtag } " )
304303 else :
305304 print (f"Successfully checked out { self .name :>20} at { self .fxtag } " )
305+ status ,f = sprepo_git .git_operation ("status" )
306+ # Restore any files deleted from sandbox
307+ for line in f .splitlines ():
308+ if "deleted:" in line :
309+ deleted_file = line .split ("deleted:" )[1 ].strip ()
310+ sprepo_git .git_operation ("checkout" , deleted_file )
311+
306312 rgit .config_set_value ('submodule.' + self .name , "active" , "true" )
307313 rgit .config_set_value ('submodule.' + self .name , "url" , self .url )
308314 rgit .config_set_value ('submodule.' + self .name , "path" , self .path )
309315
310- def update (self ):
316+ async def update (self ):
311317 """
312318 Updates the submodule to the latest or specified version.
313319
@@ -341,6 +347,9 @@ def update(self):
341347 # Look for a .gitmodules file in the newly checkedout repo
342348 if self .fxsparse :
343349 print (f"Sparse checkout { self .name } fxsparse { self .fxsparse } " )
350+ if not os .path .isfile (self .fxsparse ):
351+ self .logger .info ("Submodule {} fxsparse file not found" .format (self .name ))
352+
344353 self .sparse_checkout ()
345354 else :
346355 if not repo_exists and self .url :
@@ -378,19 +387,26 @@ def update(self):
378387 git .git_operation ("submodule" , "add" , "--name" , self .name , "--" , self .url , self .path )
379388
380389 if not repo_exists :
381- git .git_operation ("submodule" , "update" , "--init" , "--" , self .path )
390+ git .git_operation ("submodule" , "init" , "--" , self .path )
391+ await git .git_operation_async ("submodule" , "update" , "--" , self .path )
382392
383393 if self .fxtag :
384394 smgit = GitInterface (repodir , self .logger )
385395 newremote = self ._add_remote (smgit )
386396 # Trying to distingush a tag from a hash
387- allowed = set (string .digits + 'abcdef' )
397+ allowed = set (string .digits + 'abcdef' )
398+ status = 0
388399 if not set (self .fxtag ) <= allowed :
389400 # This is a tag
390401 tag = f"refs/tags/{ self .fxtag } :refs/tags/{ self .fxtag } "
391- smgit .git_operation ("fetch" , newremote , tag )
392- smgit .git_operation ("checkout" , self .fxtag )
393-
402+ status ,_ = smgit .git_operation ("fetch" , newremote , tag )
403+ if status == 0 :
404+ status ,_ = smgit .git_operation ("checkout" , self .fxtag )
405+ if status :
406+ utils .fatal_error (
407+ f"Failed to checkout { self .name } at tag or hash { self .fxtag } from { repodir } "
408+ )
409+
394410 if not os .path .exists (os .path .join (repodir , ".git" )):
395411 utils .fatal_error (
396412 f"Failed to checkout { self .name } { repo_exists } { repodir } { self .path } "
@@ -408,6 +424,18 @@ def update(self):
408424 if fxtag and fxtag not in tags :
409425 git .git_operation ("fetch" , newremote , "--tags" )
410426 status , atag = git .git_operation ("describe" , "--tags" , "--always" )
427+ status , files = git .git_operation ("diff" , "--name-only" , "-z" )
428+ modfiles = []
429+ moddirs = []
430+ if files :
431+ for f in files .split ('\0 ' ):
432+ if f :
433+ if os .path .exists (f ):
434+ git .git_operation ("checkout" ,f )
435+ elif os .path .isdir (f ):
436+ moddirs .append (f )
437+ else :
438+ modfiles .append (f )
411439 if fxtag and fxtag != atag :
412440 try :
413441 status , _ = git .git_operation ("checkout" , fxtag )
@@ -419,6 +447,10 @@ def update(self):
419447
420448 elif not fxtag :
421449 print (f"No fxtag found for submodule { self .name :>20} " )
450+ elif modfiles :
451+ print (f"{ self .name :>20} has modified files: { modfiles } " )
452+ elif moddirs :
453+ print (f"{ self .name :>20} has modified directories: { moddirs } " )
422454 else :
423455 print (f"{ self .name :>20} up to date." )
424456
0 commit comments