diff --git a/src/Git.cmake b/src/Git.cmake index 33cad874..b925ca7f 100644 --- a/src/Git.cmake +++ b/src/Git.cmake @@ -12,11 +12,19 @@ Input variables: - ``REPOSITORY_PATH``: The path to the repository - ``REMOTE_URL``: The url of the remote to add - ``REMOTE_NAME``: The name of the remote to add (defaults to the remote user) +- ``SHALLOW_SINCE``: Create a shallow clone with a history after the specified time. date should be in format of `git log --date=raw`. +- ``BRANCH``: Only clone the given branch - ``FORCE_CLONE``: Force the clone even if the directory exists - ]] function(git_clone) - set(oneValueArgs REPOSITORY_PATH REMOTE_URL REMOTE_NAME FORCE_CLONE) + set(oneValueArgs + REPOSITORY_PATH + REMOTE_URL + REMOTE_NAME + SHALLOW_SINCE + BRANCH + FORCE_CLONE + ) cmake_parse_arguments(_fun "" "${oneValueArgs}" "" ${ARGN}) if("${_fun_REPOSITORY_PATH}" STREQUAL "" OR "${_fun_REMOTE_URL}" STREQUAL "") @@ -29,14 +37,23 @@ function(git_clone) find_program(GIT_EXECUTABLE "git" REQUIRED) get_filename_component(_fun_REPOSITORY_PARENT_PATH "${_fun_REPOSITORY_PATH}" DIRECTORY) + + set(GIT_ARGS "clone" "${_fun_REMOTE_URL}" "${_fun_REPOSITORY_PATH}") + + if(NOT "${_fun_SHALLOW_SINCE}" STREQUAL "") + list(APPEND GIT_ARGS "--shallow-since=${_fun_SHALLOW_SINCE}") + endif() + + if(NOT "${_fun_BRANCH}" STREQUAL "") + list(APPEND GIT_ARGS "--single-branch" "--branch=${_fun_BRANCH}") + endif() + execute_process( - COMMAND "${GIT_EXECUTABLE}" "clone" "${_fun_REMOTE_URL}" - WORKING_DIRECTORY "${_fun_REPOSITORY_PARENT_PATH}" COMMAND_ERROR_IS_FATAL LAST + COMMAND "${GIT_EXECUTABLE}" ${GIT_ARGS} WORKING_DIRECTORY "${_fun_REPOSITORY_PARENT_PATH}" + COMMAND_ERROR_IS_FATAL LAST ) else() - message( - STATUS "Repository already exists at ${_fun_REPOSITORY_PATH}. Waiting for git lock file.." - ) + message(STATUS "Repository already exists at ${_fun_REPOSITORY_PATH}.") git_wait(REPOSITORY_PATH "${_fun_REPOSITORY_PATH}") if(NOT EXISTS "${_fun_REPOSITORY_PATH}/.git") @@ -389,6 +406,8 @@ function(git_wait) set(counter 0) + message(STATUS "Waiting for git lock file...[${counter}/${_fun_TIMEOUT_COUNTER}]") + # wait until .git/index is present (in case a parallel clone is running) while(NOT EXISTS "${_fun_REPOSITORY_PATH}/.git/index" OR EXISTS "${_fun_REPOSITORY_PATH}/.git/index.lock"