| find_package(Git QUIET REQUIRED) | |
| include(ExternalProject) | |
| if(CMAKE_GENERATOR STREQUAL "Borland Makefiles" OR | |
| CMAKE_GENERATOR STREQUAL "Watcom WMake") | |
| set(fs_delay 3) | |
| else() | |
| set(fs_delay 1.125) | |
| endif() | |
| set(srcRepo ${CMAKE_CURRENT_BINARY_DIR}/srcRepo) | |
| set(srcDir ${CMAKE_CURRENT_BINARY_DIR}/src) | |
| set(binDir ${CMAKE_CURRENT_BINARY_DIR}/build) | |
| file(REMOVE_RECURSE ${srcRepo} ${binDir}) | |
| file(MAKE_DIRECTORY ${srcRepo}) | |
| file(MAKE_DIRECTORY ${srcDir}) | |
| configure_file(${CMAKE_CURRENT_LIST_DIR}/FetchGitShallowHash/CMakeLists.txt | |
| ${srcDir}/CMakeLists.txt COPYONLY) | |
| # Use a file:// URL. git ignores --depth when cloning a plain local path. | |
| set(repoUrl "file://${srcRepo}") | |
| function(execGitCommand) | |
| execute_process( | |
| WORKING_DIRECTORY ${srcRepo} | |
| COMMAND ${GIT_EXECUTABLE} ${ARGN} | |
| COMMAND_ECHO STDOUT | |
| COMMAND_ERROR_IS_FATAL ANY | |
| ) | |
| endfunction() | |
| function(commitFile name out_var) | |
| file(TOUCH ${srcRepo}/${name}) | |
| execGitCommand(add ${name}) | |
| execGitCommand(commit -m "Add ${name}") | |
| execute_process( | |
| WORKING_DIRECTORY ${srcRepo} | |
| COMMAND ${GIT_EXECUTABLE} rev-parse HEAD | |
| COMMAND_ERROR_IS_FATAL ANY | |
| OUTPUT_VARIABLE commit_hash | |
| OUTPUT_STRIP_TRAILING_WHITESPACE | |
| ) | |
| set(${out_var} ${commit_hash} PARENT_SCOPE) | |
| endfunction() | |
| set(generatorArgs "") | |
| if(CMAKE_GENERATOR_INSTANCE) | |
| list(APPEND generatorArgs -D "CMAKE_GENERATOR_INSTANCE=${CMAKE_GENERATOR_INSTANCE}") | |
| endif() | |
| if(CMAKE_MAKE_PROGRAM) | |
| list(APPEND generatorArgs -D "CMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}") | |
| endif() | |
| function(configureAndBuild tag dir) | |
| execute_process(COMMAND ${CMAKE_COMMAND} | |
| -G ${CMAKE_GENERATOR} -T "${CMAKE_GENERATOR_TOOLSET}" | |
| -A "${CMAKE_GENERATOR_PLATFORM}" | |
| ${generatorArgs} | |
| -D repoUrl:STRING=${repoUrl} | |
| -D gitTag:STRING=${tag} | |
| ${ARGN} | |
| -B ${dir} | |
| -S ${srcDir} | |
| COMMAND_ECHO STDOUT | |
| COMMAND_ERROR_IS_FATAL ANY | |
| ) | |
| execute_process(COMMAND ${CMAKE_COMMAND} --build ${dir} --target fetcher | |
| WORKING_DIRECTORY ${dir} | |
| COMMAND_ECHO STDOUT | |
| RESULT_VARIABLE result | |
| OUTPUT_VARIABLE output | |
| ERROR_VARIABLE output | |
| ) | |
| set(build_result "${result}" PARENT_SCOPE) | |
| set(build_output "${output}" PARENT_SCOPE) | |
| endfunction() | |
| function(checkBuilt) | |
| if(NOT build_result EQUAL 0) | |
| message(FATAL_ERROR "Build failed:\n${build_output}") | |
| endif() | |
| endfunction() | |
| # Checks that ref resolves to the expected commit in the repository the | |
| # build in dir fetched, or that it is missing. Name a commit as "<hash>^0", | |
| # not "<hash>^{commit}": the MSYS2 and Cygwin builds of git expand braces in | |
| # the arguments that a native Windows process gives them. | |
| function(checkRef dir ref expected) | |
| execute_process( | |
| WORKING_DIRECTORY ${dir}/fetcher-prefix/src/fetcher | |
| COMMAND ${GIT_EXECUTABLE} rev-parse --verify --quiet "${ref}" | |
| RESULT_VARIABLE result | |
| OUTPUT_VARIABLE hash | |
| OUTPUT_STRIP_TRAILING_WHITESPACE | |
| ) | |
| if(expected STREQUAL "missing") | |
| if(result EQUAL 0) | |
| message(FATAL_ERROR "${ref} should not have been fetched") | |
| endif() | |
| elseif(NOT result EQUAL 0 OR NOT hash STREQUAL expected) | |
| message(FATAL_ERROR "${ref} is '${hash}', expected '${expected}'") | |
| endif() | |
| endfunction() | |
| # Checks that the repository the build in dir fetched has no branches, that | |
| # its only tags are those named, and that it has only the commit checked out. | |
| function(checkOnlyCommit dir) | |
| set(expected "") | |
| foreach(tag IN LISTS ARGN) | |
| string(APPEND expected "refs/tags/${tag}\n") | |
| endforeach() | |
| execute_process( | |
| WORKING_DIRECTORY ${dir}/fetcher-prefix/src/fetcher | |
| COMMAND ${GIT_EXECUTABLE} for-each-ref "--format=%(refname)" | |
| OUTPUT_VARIABLE refs | |
| COMMAND_ERROR_IS_FATAL ANY | |
| ) | |
| if(NOT refs STREQUAL expected) | |
| message(FATAL_ERROR "The clone should have only the refs:\n${expected}but has:\n${refs}") | |
| endif() | |
| execute_process( | |
| WORKING_DIRECTORY ${dir}/fetcher-prefix/src/fetcher | |
| COMMAND ${GIT_EXECUTABLE} rev-list --count HEAD | |
| OUTPUT_VARIABLE count | |
| OUTPUT_STRIP_TRAILING_WHITESPACE | |
| COMMAND_ERROR_IS_FATAL ANY | |
| ) | |
| if(NOT count EQUAL 1) | |
| message(FATAL_ERROR "The clone has ${count} commits of history") | |
| endif() | |
| endfunction() | |
| function(makeLocalChanges dir) | |
| set(checkout ${dir}/fetcher-prefix/src/fetcher) | |
| file(WRITE ${checkout}/firstFile.txt "staged edit") | |
| execute_process( | |
| COMMAND ${GIT_EXECUTABLE} add firstFile.txt | |
| WORKING_DIRECTORY ${checkout} | |
| COMMAND_ERROR_IS_FATAL ANY | |
| ) | |
| file(WRITE ${checkout}/firstFile.txt "tracked edit") | |
| file(WRITE ${checkout}/local.txt "untracked edit") | |
| endfunction() | |
| function(checkLocalChanges dir) | |
| set(checkout ${dir}/fetcher-prefix/src/fetcher) | |
| execute_process( | |
| COMMAND ${GIT_EXECUTABLE} show :firstFile.txt | |
| WORKING_DIRECTORY ${checkout} | |
| OUTPUT_VARIABLE staged | |
| COMMAND_ERROR_IS_FATAL ANY | |
| ) | |
| file(READ ${checkout}/firstFile.txt tracked) | |
| file(READ ${checkout}/local.txt untracked) | |
| if(NOT staged STREQUAL "staged edit" OR NOT tracked STREQUAL "tracked edit" | |
| OR NOT untracked STREQUAL "untracked edit") | |
| message(FATAL_ERROR "Update lost a local edit") | |
| endif() | |
| endfunction() | |
| function(checkUpdate tag expected) | |
| configureAndBuild(${tag} ${binDir} ${ARGN}) | |
| checkBuilt() | |
| checkRef(${binDir} HEAD ${expected}) | |
| checkLocalChanges(${binDir}) | |
| endfunction() | |
| # Setup a fresh source repo with a predictable default branch across all | |
| # git versions. Let it send commits that are not branch tips or tags, as | |
| # git servers commonly do, even to clients using git protocol version 0. | |
| execGitCommand(-c init.defaultBranch=master init) | |
| # Also provide an identity for stashing changes in the checkouts. | |
| set(ENV{GIT_AUTHOR_NAME} testauthor) | |
| set(ENV{GIT_AUTHOR_EMAIL} testauthor@cmake.org) | |
| set(ENV{GIT_COMMITTER_NAME} testauthor) | |
| set(ENV{GIT_COMMITTER_EMAIL} testauthor@cmake.org) | |
| execGitCommand(config commit.gpgsign "false") | |
| execGitCommand(config tag.gpgsign "false") | |
| execGitCommand(config uploadpack.allowReachableSHA1InWant "true") | |
| # Three commits on master, the second one tagged, and another branch. | |
| commitFile(firstFile.txt firstCommit) | |
| commitFile(secondFile.txt secondCommit) | |
| execGitCommand(tag -a -m "Annotated tag" annotated_tag) | |
| commitFile(thirdFile.txt thirdCommit) | |
| execGitCommand(checkout -b other ${firstCommit}) | |
| commitFile(otherFile.txt otherCommit) | |
| execGitCommand(checkout master) | |
| execGitCommand(tag -a -m "Tag named like a branch" other ${secondCommit}) | |
| set(secondCommitTags annotated_tag other) | |
| # The clone has only the commit and the tags that point at it, and names | |
| # its remote even if git would name it otherwise, for the update step to | |
| # fetch from. | |
| set(ENV{GIT_CONFIG_COUNT} 1) | |
| set(ENV{GIT_CONFIG_KEY_0} clone.defaultRemoteName) | |
| set(ENV{GIT_CONFIG_VALUE_0} upstream) | |
| set(envConfig ${CMAKE_CURRENT_BINARY_DIR}/envConfig) | |
| file(WRITE ${envConfig} "") | |
| set(ENV{GIT_CONFIG} ${envConfig}) | |
| message(STATUS "Clone at commit hash ${secondCommit}") | |
| configureAndBuild(${secondCommit} ${binDir}) | |
| unset(ENV{GIT_CONFIG_COUNT}) | |
| unset(ENV{GIT_CONFIG_KEY_0}) | |
| unset(ENV{GIT_CONFIG_VALUE_0}) | |
| unset(ENV{GIT_CONFIG}) | |
| checkBuilt() | |
| file(READ ${envConfig} envConfigContents) | |
| if(NOT envConfigContents STREQUAL "") | |
| message(FATAL_ERROR "The clone wrote to GIT_CONFIG:\n${envConfigContents}") | |
| endif() | |
| checkRef(${binDir} HEAD ${secondCommit}) | |
| checkOnlyCommit(${binDir} ${secondCommitTags}) | |
| checkRef(${binDir} "${firstCommit}^0" missing) | |
| checkRef(${binDir} "${thirdCommit}^0" missing) | |
| checkRef(${binDir} "${otherCommit}^0" missing) | |
| # Look only at the clone's own configuration: the users may add remotes. | |
| execute_process( | |
| WORKING_DIRECTORY ${binDir}/fetcher-prefix/src/fetcher | |
| COMMAND ${GIT_EXECUTABLE} config --local --get remote.origin.url | |
| RESULT_VARIABLE result | |
| OUTPUT_QUIET | |
| ) | |
| if(NOT result EQUAL 0) | |
| message(FATAL_ERROR "The clone has no remote named origin") | |
| endif() | |
| makeLocalChanges(${binDir}) | |
| # A new pin needs no branches or other tags. A known pin can be checked out | |
| # offline, and an unknown name must fail without fetching or recloning. | |
| checkUpdate(${firstCommit} ${firstCommit}) | |
| checkOnlyCommit(${binDir} ${secondCommitTags}) | |
| checkRef(${binDir} "${thirdCommit}^0" missing) | |
| checkRef(${binDir} "${otherCommit}^0" missing) | |
| # Take the repository away, so that any fetch would fail. | |
| file(RENAME ${srcRepo} ${srcRepo}-offline) | |
| checkUpdate(${secondCommit} ${secondCommit} -Ddisconnected=ON) | |
| # The disconnected update step reruns only when its script is newer than | |
| # its stamp, which some file systems resolve only to the second. | |
| execute_process(COMMAND ${CMAKE_COMMAND} -E sleep ${fs_delay}) | |
| configureAndBuild(origin/other ${binDir} -Ddisconnected=ON) | |
| if(build_result EQUAL 0 OR NOT build_output MATCHES "is not present locally") | |
| message(FATAL_ERROR "Expected an unknown ref while disconnected:\n${build_output}") | |
| endif() | |
| file(RENAME ${srcRepo}-offline ${srcRepo}) | |
| checkRef(${binDir} HEAD ${secondCommit}) | |
| checkOnlyCommit(${binDir} ${secondCommitTags}) | |
| checkLocalChanges(${binDir}) | |
| # Fetch named refs into the existing clone. A branch and tag share the | |
| # name "other" but point at different commits. Returning to a pin keeps | |
| # both refs, even offline. | |
| checkUpdate(origin/other ${otherCommit} -Ddisconnected=OFF) | |
| # The branch tips are fetched without their history, as for an ordinary | |
| # shallow clone, though a fresh one would lack our old pin. | |
| checkRef(${binDir} "refs/remotes/origin/master^" missing) | |
| checkRef(${binDir} "${firstCommit}^0" ${firstCommit}) | |
| checkUpdate(refs/tags/other ${secondCommit}) | |
| checkUpdate(origin/HEAD ${thirdCommit}) | |
| checkUpdate(annotated_tag ${secondCommit}) | |
| file(RENAME ${srcRepo} ${srcRepo}-offline) | |
| checkUpdate(${otherCommit} ${otherCommit} -Ddisconnected=ON) | |
| file(RENAME ${srcRepo}-offline ${srcRepo}) | |
| checkRef(${binDir} refs/remotes/origin/other ${otherCommit}) | |
| checkRef(${binDir} "refs/tags/other^0" ${secondCommit}) | |
| # A missing pin fails, and leaves the checkout and its local changes. | |
| set(missingCommit 0123456789abcdef0123456789abcdef01234567) | |
| configureAndBuild(${missingCommit} ${binDir} -Ddisconnected=OFF) | |
| if(build_result EQUAL 0 OR NOT build_output MATCHES "Failed to checkout: '${missingCommit}'") | |
| message(FATAL_ERROR "Expected an error for the missing commit:\n${build_output}") | |
| endif() | |
| checkRef(${binDir} HEAD ${otherCommit}) | |
| checkLocalChanges(${binDir}) | |
| # A bare branch name can be fetched and checked out normally. A local | |
| # branch created at the previous pin stays at its original tip. | |
| block() | |
| set(binDir ${binDir}-work-branch) | |
| configureAndBuild(${secondCommit} ${binDir}) | |
| checkBuilt() | |
| execute_process( | |
| COMMAND ${GIT_EXECUTABLE} checkout -b work | |
| WORKING_DIRECTORY ${binDir}/fetcher-prefix/src/fetcher | |
| COMMAND_ERROR_IS_FATAL ANY | |
| ) | |
| configureAndBuild(master ${binDir}) | |
| checkBuilt() | |
| checkRef(${binDir} HEAD ${thirdCommit}) | |
| checkRef(${binDir} refs/heads/work ${secondCommit}) | |
| endblock() | |
| # Start with an ordinary shallow clone at a branch. Pinning the same | |
| # commit, then switching to a tag or a different hash, keeps the clone. | |
| block() | |
| set(binDir ${binDir}-branch) | |
| configureAndBuild(master ${binDir}) | |
| checkBuilt() | |
| # A developer may have switched to a local branch between builds. | |
| execute_process( | |
| COMMAND ${GIT_EXECUTABLE} checkout master | |
| WORKING_DIRECTORY ${binDir}/fetcher-prefix/src/fetcher | |
| COMMAND_ERROR_IS_FATAL ANY | |
| ) | |
| makeLocalChanges(${binDir}) | |
| checkUpdate(${thirdCommit} ${thirdCommit}) | |
| execute_process( | |
| COMMAND ${GIT_EXECUTABLE} symbolic-ref HEAD | |
| WORKING_DIRECTORY ${binDir}/fetcher-prefix/src/fetcher | |
| OUTPUT_VARIABLE branch | |
| OUTPUT_STRIP_TRAILING_WHITESPACE | |
| COMMAND_ERROR_IS_FATAL ANY | |
| ) | |
| if(NOT branch STREQUAL "refs/heads/master") | |
| message(FATAL_ERROR "Pinning the current commit moved HEAD off master") | |
| endif() | |
| checkUpdate(annotated_tag ${secondCommit}) | |
| checkUpdate(${firstCommit} ${firstCommit}) | |
| checkRef(${binDir} refs/remotes/origin/master ${thirdCommit}) | |
| endblock() | |
| # A server using git protocol version 0, without | |
| # allowReachableSHA1InWant, won't send a commit that only a tag points at | |
| # by itself. The branch tips and tags are cloned instead, without showing | |
| # git's error, which some build tools would report as a build error. That | |
| # clone can subsequently fetch the branch's history, including commits | |
| # between its previous tip and the new one. | |
| execGitCommand(config uploadpack.allowReachableSHA1InWant "false") | |
| message(STATUS "Clone at commit hash ${secondCommit} from a strict server") | |
| configureAndBuild(${secondCommit} ${binDir}-strict -Dprogress=ON -D gitConfig=protocol.version=0) | |
| checkBuilt() | |
| # Before git 2.12, a fetch of the commit asks the server for the tags that | |
| # point at it instead, and so gets the commit with them. | |
| if(GIT_VERSION_STRING VERSION_GREATER_EQUAL 2.12) | |
| if(NOT build_output MATCHES "Cloning commit ${secondCommit}" OR | |
| NOT build_output MATCHES "Cloning the branch tips and tags instead") | |
| message(FATAL_ERROR "Build did not clone the branch tips and tags:\n${build_output}") | |
| endif() | |
| checkRef(${binDir}-strict refs/remotes/origin/other ${otherCommit}) | |
| endif() | |
| if(build_output MATCHES "(^|\n)[ \t]*(error|fatal):") | |
| message(FATAL_ERROR "Build showed a git error:\n${build_output}") | |
| endif() | |
| checkRef(${binDir}-strict HEAD ${secondCommit}) | |
| # The server does send a branch tip by itself, so a clone of one has only | |
| # the commit. An update to a commit that only a tag points at fetches the | |
| # tags instead, again without showing git's error. Before git 2.14, git | |
| # doesn't ask this server for a commit hash, even that of a branch tip, so | |
| # the branch tips and tags are cloned. | |
| if(GIT_VERSION_STRING VERSION_GREATER_EQUAL 2.14) | |
| set(strictServerSendsTip TRUE) | |
| else() | |
| set(strictServerSendsTip FALSE) | |
| endif() | |
| message(STATUS "Clone at the tip of master from a strict server") | |
| configureAndBuild(${thirdCommit} ${binDir}-strict-tip -D gitConfig=protocol.version=0) | |
| checkBuilt() | |
| if(strictServerSendsTip) | |
| checkOnlyCommit(${binDir}-strict-tip) | |
| endif() | |
| message(STATUS "Update to commit hash ${secondCommit} from a strict server") | |
| configureAndBuild(${secondCommit} ${binDir}-strict-tip) | |
| checkBuilt() | |
| if(build_output MATCHES "(^|\n)[ \t]*(error|fatal):") | |
| message(FATAL_ERROR "Build showed a git error:\n${build_output}") | |
| endif() | |
| checkRef(${binDir}-strict-tip HEAD ${secondCommit}) | |
| checkRef(${binDir}-strict-tip refs/remotes/origin/master ${thirdCommit}) | |
| # Start another pin-only checkout before the remote advances. The strict | |
| # server must supply the intermediate pin with the ordinary branch fetch. | |
| configureAndBuild(${thirdCommit} ${binDir}-strict-advance -D gitConfig=protocol.version=0) | |
| checkBuilt() | |
| if(strictServerSendsTip) | |
| checkOnlyCommit(${binDir}-strict-advance) | |
| endif() | |
| makeLocalChanges(${binDir}-strict-advance) | |
| commitFile(fourthFile.txt fourthCommit) | |
| commitFile(fifthFile.txt fifthCommit) | |
| configureAndBuild(${fourthCommit} ${binDir}-strict-advance) | |
| checkBuilt() | |
| checkRef(${binDir}-strict-advance HEAD ${fourthCommit}) | |
| checkLocalChanges(${binDir}-strict-advance) | |
| configureAndBuild(${fourthCommit} ${binDir}-strict) | |
| checkBuilt() | |
| checkRef(${binDir}-strict HEAD ${fourthCommit}) | |
| execGitCommand(reset --hard ${thirdCommit}) | |
| execGitCommand(config uploadpack.allowReachableSHA1InWant "true") | |
| # git clone records the remote's default branch as origin/HEAD. The first | |
| # fetch of branches into a clone of only a commit does too, even when git | |
| # fetch doesn't, as in older versions and with this setting. | |
| message(STATUS "Clone at commit hash ${secondCommit}, then update to origin/HEAD") | |
| configureAndBuild(${secondCommit} ${binDir}-remote-head | |
| -D gitConfig=remote.origin.followRemoteHEAD=never | |
| ) | |
| checkBuilt() | |
| checkRef(${binDir}-remote-head refs/remotes/origin/HEAD missing) | |
| configureAndBuild(origin/HEAD ${binDir}-remote-head) | |
| checkBuilt() | |
| checkRef(${binDir}-remote-head HEAD ${thirdCommit}) | |
| # An update to another commit fetches the tags that point at it too, and | |
| # the clone still has no branches. | |
| message(STATUS "Clone at commit hash ${thirdCommit}, then update to ${secondCommit}") | |
| configureAndBuild(${thirdCommit} ${binDir}-update-tags) | |
| checkBuilt() | |
| checkOnlyCommit(${binDir}-update-tags) | |
| configureAndBuild(${secondCommit} ${binDir}-update-tags) | |
| checkBuilt() | |
| checkRef(${binDir}-update-tags HEAD ${secondCommit}) | |
| checkOnlyCommit(${binDir}-update-tags ${secondCommitTags}) | |
| checkRef(${binDir}-update-tags "${firstCommit}^0" missing) | |
| # A lightweight tag would make its commit an advertised one for the server | |
| # above, so make it only now. | |
| execGitCommand(tag lightweight_tag ${firstCommit}) | |
| configureAndBuild(${firstCommit} ${binDir}-update-tags) | |
| checkBuilt() | |
| checkRef(${binDir}-update-tags HEAD ${firstCommit}) | |
| checkOnlyCommit(${binDir}-update-tags annotated_tag lightweight_tag other) | |
| # A bare name means the remote's default branch even if a tag has that name | |
| # too, as in an ordinary clone, which has a local branch of that name. The | |
| # tag points at the pin here, so the clone has it. git must not need to | |
| # guess the branch either. | |
| block() | |
| set(binDir ${binDir}-default-branch) | |
| set(srcRepo ${srcRepo}-default-branch) | |
| set(repoUrl "file://${srcRepo}") | |
| file(REMOVE_RECURSE ${srcRepo}) | |
| file(MAKE_DIRECTORY ${srcRepo}) | |
| execGitCommand(-c init.defaultBranch=master init) | |
| execGitCommand(config uploadpack.allowReachableSHA1InWant true) | |
| execGitCommand(config commit.gpgsign false) | |
| execGitCommand(config tag.gpgsign false) | |
| commitFile(pinned.txt pin) | |
| execGitCommand(tag master) | |
| commitFile(later.txt tip) | |
| configureAndBuild(${pin} ${binDir} -D gitConfig=checkout.guess=false) | |
| checkBuilt() | |
| checkOnlyCommit(${binDir} master) | |
| configureAndBuild(master ${binDir}) | |
| checkBuilt() | |
| checkRef(${binDir} HEAD ${tip}) | |
| endblock() | |
| # The repository made for the commit must have the object format of the | |
| # remote, even when the client's default format is different. SHA-256 | |
| # repositories need git 2.29. | |
| if(GIT_VERSION_STRING VERSION_GREATER_EQUAL 2.29) | |
| block() | |
| set(binDir ${binDir}-sha256) | |
| set(srcRepo ${srcRepo}-sha256) | |
| set(repoUrl "file://${srcRepo}") | |
| file(REMOVE_RECURSE ${srcRepo}) | |
| file(MAKE_DIRECTORY ${srcRepo}) | |
| execGitCommand(init --object-format=sha256) | |
| execGitCommand(config uploadpack.allowReachableSHA1InWant true) | |
| execGitCommand(config commit.gpgsign false) | |
| commitFile(first.txt pin) | |
| commitFile(later.txt tip) | |
| configureAndBuild(${pin} ${binDir}) | |
| checkBuilt() | |
| checkRef(${binDir} HEAD ${pin}) | |
| checkOnlyCommit(${binDir}) | |
| checkRef(${binDir} "${tip}^0" missing) | |
| endblock() | |
| endif() | |
| # A plain local path has only the commit cloned too, rather than every | |
| # object copied. | |
| message(STATUS "Clone a local path at commit hash ${secondCommit}") | |
| configureAndBuild(${secondCommit} ${binDir}-local -D repoUrl:STRING=${srcRepo}) | |
| checkBuilt() | |
| checkRef(${binDir}-local HEAD ${secondCommit}) | |
| checkOnlyCommit(${binDir}-local ${secondCommitTags}) | |
| checkRef(${binDir}-local "${otherCommit}^0" missing) | |
| # A fetch refspec given with GIT_CONFIG asks for more than the commit, so | |
| # the ordinary clone is made. Before git 2.21, git clone fetches only the | |
| # branches and tags, and leaves the requested refs to later fetches. | |
| if(GIT_VERSION_STRING VERSION_GREATER_EQUAL 2.21) | |
| set(cloneFetchesRefspec TRUE) | |
| else() | |
| set(cloneFetchesRefspec FALSE) | |
| endif() | |
| message(STATUS "Clone at commit hash ${secondCommit} with a refspec of the project") | |
| configureAndBuild(${secondCommit} ${binDir}-refspec | |
| -D "gitConfig=remote.origin.fetch=+refs/heads/other:refs/vendor/other" | |
| ) | |
| checkBuilt() | |
| checkRef(${binDir}-refspec HEAD ${secondCommit}) | |
| if(cloneFetchesRefspec) | |
| checkRef(${binDir}-refspec refs/vendor/other ${otherCommit}) | |
| endif() | |
| checkRef(${binDir}-refspec refs/remotes/origin/master ${thirdCommit}) | |
| # So does one in a file that GIT_CONFIG includes. | |
| set(includedConfig ${CMAKE_CURRENT_BINARY_DIR}/included.gitconfig) | |
| file(WRITE ${includedConfig} [=[ | |
| [remote "origin"] | |
| fetch = +refs/heads/other:refs/vendor/other | |
| ]=]) | |
| configureAndBuild(${secondCommit} ${binDir}-refspec-include | |
| -D "gitConfig=include.path=${includedConfig}" | |
| ) | |
| checkBuilt() | |
| checkRef(${binDir}-refspec-include HEAD ${secondCommit}) | |
| if(cloneFetchesRefspec) | |
| checkRef(${binDir}-refspec-include refs/vendor/other ${otherCommit}) | |
| endif() | |
| checkRef(${binDir}-refspec-include refs/remotes/origin/master ${thirdCommit}) | |
| # The TLS settings also apply to later fetches, so the clone of only the | |
| # commit records them as the ordinary clone does. A fetch refspec given | |
| # with GIT_CONFIG makes the ordinary clone. | |
| message(STATUS "Clone at commit hash ${secondCommit} with TLS settings") | |
| set(tlsArgs -D CMAKE_TLS_VERSION=1.2 -D CMAKE_TLS_VERIFY=OFF) | |
| configureAndBuild(${secondCommit} ${binDir}-tls ${tlsArgs}) | |
| checkBuilt() | |
| checkOnlyCommit(${binDir}-tls ${secondCommitTags}) | |
| configureAndBuild(${secondCommit} ${binDir}-tls-refspec ${tlsArgs} | |
| -D "gitConfig=remote.origin.fetch=+refs/heads/other:refs/vendor/other" | |
| ) | |
| checkBuilt() | |
| checkRef(${binDir}-tls-refspec refs/remotes/origin/master ${thirdCommit}) | |
| foreach(dir IN ITEMS ${binDir}-tls ${binDir}-tls-refspec) | |
| execute_process( | |
| WORKING_DIRECTORY ${dir}/fetcher-prefix/src/fetcher | |
| COMMAND ${GIT_EXECUTABLE} config --local --get-regexp "^http\\.ssl" | |
| OUTPUT_VARIABLE tlsConfig | |
| ) | |
| if(NOT tlsConfig MATCHES "http\\.sslversion tlsv1\\.2\n" OR | |
| NOT tlsConfig MATCHES "http\\.sslverify false\n") | |
| message(FATAL_ERROR "The clone in ${dir} lacks the TLS settings:\n${tlsConfig}") | |
| endif() | |
| endforeach() | |
| # A commit the server doesn't have can't be cloned by itself, or with the | |
| # branch tips and tags, so the checkout fails. | |
| set(missingCommit 0123456789abcdef0123456789abcdef01234567) | |
| message(STATUS "Clone at missing commit hash") | |
| configureAndBuild(${missingCommit} ${binDir}-missing) | |
| if(build_result EQUAL 0) | |
| message(FATAL_ERROR "Build at a missing commit succeeded") | |
| endif() | |
| if(NOT build_output MATCHES "Failed to checkout tag: '${missingCommit}'") | |
| message(FATAL_ERROR "Build did not report the missing commit:\n${build_output}") | |
| endif() |