@@ -27,7 +27,7 @@ def __init__(self, root_dir, name, path, url, fxtag=None, fxurl=None, fxsparse=N
2727 """
2828 self .name = name
2929 self .root_dir = root_dir
30- self .path = path
30+ self .path = path
3131 self .url = url
3232 self .fxurl = fxurl
3333 self .fxtag = fxtag
@@ -37,14 +37,14 @@ def __init__(self, root_dir, name, path, url, fxtag=None, fxurl=None, fxsparse=N
3737 else :
3838 self .fxrequired = "AlwaysRequired"
3939 self .logger = logger
40-
40+
4141 def status (self ):
4242 """
4343 Checks the status of the submodule and returns 4 parameters:
4444 - result (str): The status of the submodule.
4545 - needsupdate (bool): An indicator if the submodule needs to be updated.
4646 - localmods (bool): An indicator if the submodule has local modifications.
47- - testfails (bool): An indicator if the submodule has failed a test, this is used for testing purposes.
47+ - testfails (bool): An indicator if the submodule has failed a test, this is used for testing purposes.
4848 """
4949
5050 smpath = os .path .join (self .root_dir , self .path )
@@ -54,7 +54,7 @@ def status(self):
5454 ahash = None
5555 optional = ""
5656 if "Optional" in self .fxrequired :
57- optional = " (optional)"
57+ optional = " (optional)"
5858 required = None
5959 level = None
6060 if not os .path .exists (os .path .join (smpath , ".git" )):
@@ -63,7 +63,7 @@ def status(self):
6363 status , tags = rootgit .git_operation ("ls-remote" , "--tags" , self .url )
6464 status , result = rootgit .git_operation ("submodule" ,"status" ,smpath )
6565 result = result .split ()
66-
66+
6767 if result :
6868 ahash = result [0 ][1 :]
6969 hhash = None
@@ -102,7 +102,7 @@ def status(self):
102102 result = f"e { self .name :>20} has no associated remote"
103103 testfails = True
104104 needsupdate = True
105- return result , needsupdate , localmods , testfails
105+ return result , needsupdate , localmods , testfails
106106 status , rurl = git .git_operation ("ls-remote" ,"--get-url" )
107107 status , lines = git .git_operation ("log" , "--pretty=format:\" %h %d\" " )
108108 line = lines .partition ('\n ' )[0 ]
@@ -148,15 +148,15 @@ def status(self):
148148 else :
149149 result = f"e { self .name :>20} has no fxtag defined in .gitmodules, module at { ahash } "
150150 testfails = False
151-
151+
152152 status , output = git .git_operation ("status" , "--ignore-submodules" , "-uno" )
153153 if "nothing to commit" not in output :
154154 localmods = True
155155 result = "M" + textwrap .indent (output , " " )
156156# print(f"result {result} needsupdate {needsupdate} localmods {localmods} testfails {testfails}")
157157 return result , needsupdate , localmods , testfails
158158
159-
159+
160160 def _add_remote (self , git ):
161161 """
162162 Adds a new remote to the submodule if it does not already exist.
@@ -170,7 +170,7 @@ def _add_remote(self, git):
170170
171171 Returns:
172172 str: The name of the new remote if added, or the name of the existing remote that matches the submodule's URL.
173- """
173+ """
174174 status , remotes = git .git_operation ("remote" , "-v" )
175175 remotes = remotes .splitlines ()
176176 upstream = None
@@ -212,7 +212,7 @@ def sparse_checkout(self):
212212
213213 Returns:
214214 None
215- """
215+ """
216216 self .logger .info ("Called sparse_checkout for {}" .format (self .name ))
217217 rgit = GitInterface (self .root_dir , self .logger )
218218 status , superroot = rgit .git_operation ("rev-parse" , "--show-superproject-working-tree" )
@@ -250,7 +250,7 @@ def sparse_checkout(self):
250250 sprepo_git .config_set_value ("core" , "sparseCheckout" , "true" )
251251
252252 # set the repository remote
253-
253+
254254 self .logger .info ("Setting remote origin in {}/{}" .format (self .root_dir , self .path ))
255255 status , remotes = sprepo_git .git_operation ("remote" , "-v" )
256256 if self .url not in remotes :
@@ -287,7 +287,7 @@ def sparse_checkout(self):
287287 "submodule {} is already initialized {}" .format (self .name , rootdotgit )
288288 )
289289 os .remove (gitsparse )
290-
290+
291291 if os .path .isfile (self .fxsparse ):
292292 shutil .copy (self .fxsparse , gitsparse )
293293 else :
@@ -377,21 +377,21 @@ async def update(self):
377377 shutil .rmtree (os .path .join (repodir , ".git" ))
378378 else :
379379 shutil .move (os .path .join (repodir , ".git" ), newpath )
380-
380+
381381 with open (os .path .join (repodir , ".git" ), "w" ) as f :
382382 f .write ("gitdir: " + os .path .relpath (newpath , start = repodir ))
383383
384384 if not os .path .exists (repodir ):
385385 parent = os .path .dirname (repodir )
386386 if not os .path .isdir (parent ):
387387 os .makedirs (parent )
388- git .git_operation ("submodule" , "add" , "--name" , self .name , "--" , self .url , self .path )
388+ git .git_operation ("submodule" , "add" , "--name" , self .name , "--" , self .url , self .path )
389389
390390 if not repo_exists :
391391 git .git_operation ("submodule" , "init" , "--" , self .path )
392392 await git .git_operation_async ("submodule" , "update" , "--" , self .path )
393393
394- if self .fxtag :
394+ if self .fxtag :
395395 smgit = GitInterface (repodir , self .logger )
396396 newremote = self ._add_remote (smgit )
397397 # Trying to distingush a tag from a hash
@@ -401,18 +401,21 @@ async def update(self):
401401 # This is a tag
402402 tag = f"refs/tags/{ self .fxtag } :refs/tags/{ self .fxtag } "
403403 status ,_ = smgit .git_operation ("fetch" , newremote , tag )
404+ else :
405+ # This is likely a hash, so fetch full history just in case
406+ status ,_ = smgit .git_operation ("fetch" , newremote )
404407 if status == 0 :
405408 status ,_ = smgit .git_operation ("checkout" , self .fxtag )
406409 if status :
407410 utils .fatal_error (
408411 f"Failed to checkout { self .name } at tag or hash { self .fxtag } from { repodir } "
409412 )
410-
413+
411414 if not os .path .exists (os .path .join (repodir , ".git" )):
412415 utils .fatal_error (
413416 f"Failed to checkout { self .name } { repo_exists } { repodir } { self .path } "
414417 )
415-
418+
416419
417420 if os .path .exists (os .path .join (self .path , ".git" )):
418421 submoddir = os .path .join (self .root_dir , self .path )
@@ -445,7 +448,7 @@ async def update(self):
445448 print (f"{ self .name :>20} updated to { fxtag } " )
446449 except Exception as error :
447450 print (error )
448-
451+
449452
450453 elif not fxtag :
451454 print (f"No fxtag found for submodule { self .name :>20} " )
@@ -457,5 +460,5 @@ async def update(self):
457460 print (f"{ self .name :>20} up to date." )
458461
459462
460-
463+
461464 return
0 commit comments