@@ -118,13 +118,23 @@ def __init__(self, stm32_serie, stm32cube_repo_path, force, noclean):
118118
119119 def clone_cube_repo (self ):
120120 """Clone or fetch a stm32 serie repo"""
121+ # check whether master branch exist, otherwise use main branch
122+ master_branch_exist = subprocess .check_output (
123+ "git ls-remote --heads origin master" , cwd = self .stm32cube_serie_path
124+ ).decode ("utf-8" )
125+ if master_branch_exist :
126+ branch = "master"
127+ else :
128+ branch = "main"
129+ logging .info ("Branch used:" + branch )
130+
121131 if self .stm32cube_serie_path .exists ():
122132 logging .info ("fetching repo " + str (self .stm32cube_serie_path ))
123133 # if already exists, then just clean and fetch
124134 os_cmd (("git" , "clean" , "-fdx" ), cwd = self .stm32cube_serie_path )
125135 os_cmd (("git" , "fetch" ), cwd = self .stm32cube_serie_path )
126136 os_cmd (
127- ("git" , "reset" , "--hard" , "master" ),
137+ ("git" , "reset" , "--hard" , branch ),
128138 cwd = self .stm32cube_serie_path ,
129139 )
130140 else :
@@ -135,7 +145,7 @@ def clone_cube_repo(self):
135145
136146 # get the latest version of cube,
137147 # with the most recent one created being the last entry.
138- os_cmd (("git" , "checkout" , "master" ), cwd = self .stm32cube_serie_path )
148+ os_cmd (("git" , "checkout" , branch ), cwd = self .stm32cube_serie_path )
139149 self .version_tag = subprocess .check_output (
140150 "git tag -l" , cwd = self .stm32cube_serie_path
141151 ).splitlines ()
0 commit comments