@@ -126,15 +126,18 @@ endfunction()
126126
127127Pull the given repository
128128
129- It will temporarily switch back to the previous branch if the head is detached for updating
129+ If ``TARGET_REVISION`` is given, the pull is skipped if the current revision is the same as the target revision.
130+
131+ It will temporarily switch back to the previous branch if the head is detached for updating.
130132
131133Input variables:
132134
133135- ``REPOSITORY_PATH``: The path to the repository
136+ - ``TARGET_REVISION``: if the current revision of the repository is the same as this given revision, the pull is skipped
134137
135138]]
136139function (git_pull )
137- set (oneValueArgs REPOSITORY_PATH)
140+ set (oneValueArgs REPOSITORY_PATH TARGET_REVISION )
138141 cmake_parse_arguments (_fun "" "${oneValueArgs} " "" ${ARGN} )
139142
140143 if ("${_fun_REPOSITORY_PATH} " STREQUAL "" )
@@ -144,14 +147,26 @@ function(git_pull)
144147 # store the current revision
145148 git_revision (REVISION REPOSITORY_PATH "${_fun_REPOSITORY_PATH} " )
146149
150+ # skip the pull if the revision is the same
151+ if (NOT "${_fun_TARGET_REVISION} " STREQUAL "" AND "${REVISION} " STREQUAL "${_fun_TARGET_REVISION} " )
152+ message (STATUS "Skipping pull of ${_fun_REPOSITORY_PATH} because it's already at ${REVISION} " )
153+ return ()
154+ else ()
155+ # pull and restore it after the pull
156+ set (_fun_TARGET_REVISION "${REVISION} " )
157+ endif ()
158+
147159 git_switch_back (REPOSITORY_PATH "${_fun_REPOSITORY_PATH} " )
148160
149161 message (STATUS "Updating ${_fun_REPOSITORY_PATH} " )
150162 find_program (GIT_EXECUTABLE "git" REQUIRED )
151- execute_process (COMMAND "${GIT_EXECUTABLE} " "pull" WORKING_DIRECTORY "${_fun_REPOSITORY_PATH} " )
163+ execute_process (
164+ COMMAND "${GIT_EXECUTABLE} " "pull" WORKING_DIRECTORY "${_fun_REPOSITORY_PATH} "
165+ COMMAND_ERROR_IS_FATAL LAST
166+ )
152167
153168 # restore the revision
154- git_checkout (REPOSITORY_PATH "${_fun_REPOSITORY_PATH} " REVISION "${REVISION } " )
169+ git_checkout (REPOSITORY_PATH "${_fun_REPOSITORY_PATH} " REVISION "${_fun_TARGET_REVISION } " )
155170endfunction ()
156171
157172#[[ .rst:
@@ -192,6 +207,11 @@ function(git_checkout)
192207 message (FATAL_ERROR "REPOSITORY_PATH and REVISION are required" )
193208 endif ()
194209
210+ git_revision (REVISION REPOSITORY_PATH "${_fun_REPOSITORY_PATH} " )
211+ if ("${REVISION} " STREQUAL "${_fun_REVISION} " )
212+ return ()
213+ endif ()
214+
195215 find_program (GIT_EXECUTABLE "git" REQUIRED )
196216 execute_process (
197217 COMMAND "${GIT_EXECUTABLE} " "-c" "advice.detachedHead=false" "checkout" "${_fun_REVISION} "
0 commit comments