@@ -284,17 +284,18 @@ def sparse_checkout(self):
284284 if not os .path .isdir (infodir ):
285285 os .makedirs (infodir )
286286 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 ):
287+ if os .path .isfile (gitsparse ):
288+ self .logger .warning (
289+ "submodule {} is already initialized {}" .format (self .name , rootdotgit )
290+ )
291+ os .remove (gitsparse )
292+
294293 if os .path .isfile (self .fxsparse ):
295-
296294 shutil .copy (self .fxsparse , gitsparse )
297-
295+ else :
296+ self .logger .warning (
297+ "submodule {} could not find {}" .format (self .name , self .fxsparse )
298+ )
298299
299300 # Finally checkout the repo
300301 sprepo_git .git_operation ("fetch" , "origin" , "--tags" )
@@ -303,6 +304,13 @@ def sparse_checkout(self):
303304 print (f"Error checking out { self .name :>20} at { self .fxtag } " )
304305 else :
305306 print (f"Successfully checked out { self .name :>20} at { self .fxtag } " )
307+ status ,f = sprepo_git .git_operation ("status" )
308+ # Restore any files deleted from sandbox
309+ for line in f .splitlines ():
310+ if "deleted:" in line :
311+ deleted_file = line .split ("deleted:" )[1 ].strip ()
312+ sprepo_git .git_operation ("checkout" , deleted_file )
313+
306314 rgit .config_set_value ('submodule.' + self .name , "active" , "true" )
307315 rgit .config_set_value ('submodule.' + self .name , "url" , self .url )
308316 rgit .config_set_value ('submodule.' + self .name , "path" , self .path )
@@ -341,6 +349,9 @@ async def update(self):
341349 # Look for a .gitmodules file in the newly checkedout repo
342350 if self .fxsparse :
343351 print (f"Sparse checkout { self .name } fxsparse { self .fxsparse } " )
352+ if not os .path .isfile (self .fxsparse ):
353+ self .logger .info ("Submodule {} fxsparse file not found" .format (self .name ))
354+
344355 self .sparse_checkout ()
345356 else :
346357 if not repo_exists and self .url :
@@ -409,6 +420,18 @@ async def update(self):
409420 if fxtag and fxtag not in tags :
410421 git .git_operation ("fetch" , newremote , "--tags" )
411422 status , atag = git .git_operation ("describe" , "--tags" , "--always" )
423+ status , files = git .git_operation ("diff" , "--name-only" , "-z" )
424+ modfiles = []
425+ moddirs = []
426+ if files :
427+ for f in files .split ('\0 ' ):
428+ if f :
429+ if os .path .exists (f ):
430+ git .git_operation ("checkout" ,f )
431+ elif os .path .isdir (f ):
432+ moddirs .append (f )
433+ else :
434+ modfiles .append (f )
412435 if fxtag and fxtag != atag :
413436 try :
414437 status , _ = git .git_operation ("checkout" , fxtag )
@@ -420,6 +443,10 @@ async def update(self):
420443
421444 elif not fxtag :
422445 print (f"No fxtag found for submodule { self .name :>20} " )
446+ elif modfiles :
447+ print (f"{ self .name :>20} has modified files: { modfiles } " )
448+ elif moddirs :
449+ print (f"{ self .name :>20} has modified directories: { moddirs } " )
423450 else :
424451 print (f"{ self .name :>20} up to date." )
425452
0 commit comments