@@ -73,7 +73,9 @@ def create_config():
7373 )
7474 )
7575 path_config_file = open (path_config_filename , "w" )
76- path_config_file .write (json .dumps ({"REPO_LOCAL_PATH" : str (repo_local_path )}, indent = 2 ))
76+ path_config_file .write (
77+ json .dumps ({"REPO_LOCAL_PATH" : str (repo_local_path )}, indent = 2 )
78+ )
7779 path_config_file .close ()
7880 exit (1 )
7981
@@ -103,16 +105,40 @@ def checkConfig():
103105 createFolder (repo_local_path )
104106
105107
108+ def getRepoBranchName (repo_path ):
109+ bname = ""
110+ rname = ""
111+ cmd = ["git" , "-C" , repo_path , "branch" , "-r" ]
112+ bnames = execute_cmd (cmd , None ).split ("\n " )
113+ for b in bnames :
114+ name_match = re .match (r"\S+/\S+ -> (\S+)/(\S+)" , b .strip ())
115+ if name_match :
116+ rname = name_match .group (1 )
117+ bname = name_match .group (2 )
118+ if not bname :
119+ print ("Could not find branch name for {}!" .format (repo_path ))
120+ exit (1 )
121+ return (rname , bname )
122+
123+
106124def updateCoreRepo ():
107125 # Handle core repo
108126 repo_path = repo_local_path / repo_core_name
109127 print ("Updating {}..." .format (repo_core_name ))
110128 if repo_path .exists ():
129+ rname , bname = getRepoBranchName (repo_path )
111130 # Get new tags from the remote
112131 git_cmds = [
113- ["git" , "-C" , repo_path , "clean" , "-fdx" ],
114132 ["git" , "-C" , repo_path , "fetch" ],
115- ["git" , "-C" , repo_path , "reset" , "--hard" , "origin/master" ],
133+ [
134+ "git" ,
135+ "-C" ,
136+ repo_path ,
137+ "checkout" ,
138+ "-B" ,
139+ bname ,
140+ "{}/{}" .format (rname , bname ),
141+ ],
116142 ]
117143 else :
118144 # Clone it as it does not exists yet
@@ -129,11 +155,19 @@ def updateSTRepo():
129155 gh_STM32Cube = urljoin (gh_st , repo_name + ".git" )
130156 print ("Updating " + repo_name + "..." )
131157 if repo_path .exists ():
158+ rname , bname = getRepoBranchName (repo_path )
132159 # Get new tags from the remote
133160 git_cmds = [
134- ["git" , "-C" , repo_path , "clean" , "-fdx" ],
135- ["git" , "-C" , repo_path , "fetch" , "--tags" ],
136- ["git" , "-C" , repo_path , "reset" , "--hard" , "origin/master" ],
161+ ["git" , "-C" , repo_path , "fetch" ],
162+ [
163+ "git" ,
164+ "-C" ,
165+ repo_path ,
166+ "checkout" ,
167+ "-B" ,
168+ bname ,
169+ "{}/{}" .format (rname , bname ),
170+ ],
137171 ]
138172 else :
139173 # Clone it as it does not exists yet
@@ -512,7 +546,7 @@ def updateCore():
512546
513547# Parser
514548upparser = argparse .ArgumentParser (
515- description = "Update HAL drivers and CMSIS devices from STM32cube released on GitHub"
549+ description = "Manage HAL drivers and CMSIS devices from STM32cube released on GitHub"
516550)
517551
518552upparser .add_argument (
0 commit comments