1919# If the current HEAD is not a named branch, use master.
2020# 5) Update the remote branches in the TESTDATA_DIR repo.
2121# 6) Check if the desired branch exists in TESTDATA_DIR's origin remote.
22- # If the desired remote branch does not exist, use master.
23- # 7) Check out the desired branch in TESTDATA_DIR repo.
24- # 8) Run 'git pull origin <branch>:<branch>' to update the repository.
22+ # 7) Check if the desired branch exists in TESTDATA_DIR as a local branch.
23+ # 8) If the neither the local or remote branch exist, use master.
24+ # 9) Check out the local <branch> in TESTDATA_DIR repo.
25+ # 10) If the remote branch exists, or we are using master, run
26+ # 'git pull origin <branch>:<branch>' to fetch/update the local branch from
27+ # the remote.
2528#
2629# Any failures are handled via non-fatal warnings. This is to allow the project
2730# to build when access to the repo is not available.
@@ -154,37 +157,57 @@ execute_process(COMMAND
154157
155158if (NOT RESULT EQUAL 0)
156159 message ("Cannot update uvcdat-testdata checkout at \" ${TESTDATA_DIR} \" . "
157- "Error updating remote branches with 'git fetch --update-shallow --depth=1':\n ."
160+ "Error updating remote branches with "
161+ "'git fetch --update-shallow --depth=1':\n ."
158162 "${OUTPUT} \n "
159163 "Baseline images may be out of date." )
160164 return ()
161165endif ()
162166
163167# 6) Check if the desired branch exists in TESTDATA_DIR's origin remote.
164- # If the desired remote branch does not exist, use master.
165168execute_process (COMMAND
166- "${GIT_EXECUTABLE} " branch -r
169+ "${GIT_EXECUTABLE} " branch -a --list "* ${BRANCH} "
167170 WORKING_DIRECTORY "${TESTDATA_DIR} "
168171 RESULT_VARIABLE RESULT
169172 ERROR_VARIABLE OUTPUT
170173 OUTPUT_VARIABLE OUTPUT )
171174
172175if (NOT RESULT EQUAL 0)
173176 message ("Cannot update uvcdat-testdata checkout at \" ${TESTDATA_DIR} \" . "
174- "Error updating remote branches with 'git fetch --update-shallow --depth=1':\n ."
175- "${OUTPUT} \n "
177+ "Error obtaining full branch list:\n ${OUTPUT} "
176178 "Baseline images may be out of date." )
177179 return ()
178180endif ()
179181
180- string (FIND "${OUTPUT} " "origin/${BRANCH} " POS)
181- if (POS EQUAL -1)
182- message ("Remote branch 'origin/${BRANCH} ' not found for repository at "
183- "'${TESTDATA_DIR} '. Using current master instead." )
182+ message ("Testing if remote branch 'origin/${BRANCH} ' exists..." )
183+ string (FIND "${OUTPUT} " " remotes/origin/${BRANCH} \n " POS)
184+ if (NOT POS EQUAL -1)
185+ message ("Remote branch exists." )
186+ set (REMOTE_EXISTS "YES" )
187+ else ()
188+ message ("Remote branch does not exist." )
189+ set (REMOTE_EXISTS "NO" )
190+ endif ()
191+
192+ # 7) Check if the desired branch exists locally:
193+ message ("Testing if local branch '${BRANCH} ' exists..." )
194+ string (FIND "${OUTPUT} " " ${BRANCH} \n " POS) # Leading space in regex intended
195+ if (NOT POS EQUAL -1)
196+ message ("Local branch exists." )
197+ set (LOCAL_EXISTS "YES" )
198+ else ()
199+ message ("Local branch does not exist." )
200+ set (LOCAL_EXISTS "NO" )
201+ endif ()
202+
203+ # 8) If the neither the local or remote branch exist, use master.
204+ if (NOT REMOTE_EXISTS AND NOT LOCAL_EXISTS)
184205 set (BRANCH "master" )
206+ set (REMOTE_EXISTS "YES" )
207+ set (LOCAL_EXISTS "YES" )
185208endif ()
186209
187- # 7 ) Check out the desired branch in TESTDATA_DIR repo.
210+ # 9 ) Check out the desired branch in TESTDATA_DIR repo.
188211message ("Checking out branch '${BRANCH} ' in repo '${TESTDATA_DIR} '." )
189212execute_process (COMMAND
190213 "${GIT_EXECUTABLE} " checkout "${BRANCH} "
@@ -201,21 +224,25 @@ if(NOT RESULT EQUAL 0)
201224 return ()
202225endif ()
203226
204- # 8) Update the branch (in case it already existed during the checkout):
205- message ("Updating \" ${TESTDATA_DIR} :${BRANCH} \" from "
206- "\" ${TESTDATA_URL} :${BRANCH} \" ..." )
207- execute_process (COMMAND
208- "${GIT_EXECUTABLE} " pull origin "${BRANCH} :${BRANCH} "
209- WORKING_DIRECTORY "${TESTDATA_DIR} "
210- RESULT_VARIABLE RESULT
211- ERROR_VARIABLE OUTPUT
212- OUTPUT_VARIABLE OUTPUT )
227+ # 10) If the remote branch exists, or we are using master, run
228+ # 'git pull origin <branch>:<branch>' to fetch/update the local branch from
229+ # the remote.
230+ if (REMOTE_EXISTS)
231+ message ("Updating \" ${TESTDATA_DIR} :${BRANCH} \" from "
232+ "\" ${TESTDATA_URL} :${BRANCH} \" ..." )
233+ execute_process (COMMAND
234+ "${GIT_EXECUTABLE} " pull origin "${BRANCH} :${BRANCH} "
235+ WORKING_DIRECTORY "${TESTDATA_DIR} "
236+ RESULT_VARIABLE RESULT
237+ ERROR_VARIABLE OUTPUT
238+ OUTPUT_VARIABLE OUTPUT )
213239
214- string (STRIP "${OUTPUT} " OUTPUT)
240+ string (STRIP "${OUTPUT} " OUTPUT)
215241
216- message ("${OUTPUT} " )
242+ message ("${OUTPUT} " )
217243
218- if (NOT RESULT EQUAL 0)
219- message ("Error updating testdata repo! "
220- "Baseline images may be out of date." )
244+ if (NOT RESULT EQUAL 0)
245+ message ("Error updating testdata repo! "
246+ "Baseline images may be out of date." )
247+ endif ()
221248endif ()
0 commit comments