@@ -73,7 +73,9 @@ def create_config():
73
73
)
74
74
)
75
75
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
+ )
77
79
path_config_file .close ()
78
80
exit (1 )
79
81
@@ -103,16 +105,40 @@ def checkConfig():
103
105
createFolder (repo_local_path )
104
106
105
107
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
+
106
124
def updateCoreRepo ():
107
125
# Handle core repo
108
126
repo_path = repo_local_path / repo_core_name
109
127
print ("Updating {}..." .format (repo_core_name ))
110
128
if repo_path .exists ():
129
+ rname , bname = getRepoBranchName (repo_path )
111
130
# Get new tags from the remote
112
131
git_cmds = [
113
- ["git" , "-C" , repo_path , "clean" , "-fdx" ],
114
132
["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
+ ],
116
142
]
117
143
else :
118
144
# Clone it as it does not exists yet
@@ -129,11 +155,19 @@ def updateSTRepo():
129
155
gh_STM32Cube = urljoin (gh_st , repo_name + ".git" )
130
156
print ("Updating " + repo_name + "..." )
131
157
if repo_path .exists ():
158
+ rname , bname = getRepoBranchName (repo_path )
132
159
# Get new tags from the remote
133
160
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
+ ],
137
171
]
138
172
else :
139
173
# Clone it as it does not exists yet
@@ -512,7 +546,7 @@ def updateCore():
512
546
513
547
# Parser
514
548
upparser = 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"
516
550
)
517
551
518
552
upparser .add_argument (
0 commit comments