diff options
author | Craig Scott <craig.scott@crascit.com> | 2020-02-12 06:48:01 (GMT) |
---|---|---|
committer | Craig Scott <craig.scott@crascit.com> | 2020-05-23 12:27:38 (GMT) |
commit | 0aea435aa1196fd7c32d328059c1f6a2ef3ac382 (patch) | |
tree | fe6d8c25f726e523e5d6a410ec9d5822dc0c307f /Tests | |
parent | ea410414c518afd79cc296af2ae6db8938766b4d (diff) | |
download | CMake-0aea435aa1196fd7c32d328059c1f6a2ef3ac382.zip CMake-0aea435aa1196fd7c32d328059c1f6a2ef3ac382.tar.gz CMake-0aea435aa1196fd7c32d328059c1f6a2ef3ac382.tar.bz2 |
ExternalProject: Provide choice of git update strategies
Fixes: #16528
Co-Authored-By: Michael Wake <macwake@gmail.com>
Diffstat (limited to 'Tests')
-rw-r--r-- | Tests/ExternalProjectUpdate/CMakeLists.txt | 2 | ||||
-rw-r--r-- | Tests/ExternalProjectUpdate/ExternalProjectUpdateTest.cmake | 55 |
2 files changed, 48 insertions, 9 deletions
diff --git a/Tests/ExternalProjectUpdate/CMakeLists.txt b/Tests/ExternalProjectUpdate/CMakeLists.txt index dbf26c8..9dddae2 100644 --- a/Tests/ExternalProjectUpdate/CMakeLists.txt +++ b/Tests/ExternalProjectUpdate/CMakeLists.txt @@ -78,6 +78,8 @@ if(do_git_tests) ExternalProject_Add(${proj} GIT_REPOSITORY "${local_git_repo}" GIT_TAG ${TEST_GIT_TAG} + GIT_CONFIG "user.email=testauthor@cmake.org" + "user.name=testauthor" CMAKE_GENERATOR "${CMAKE_GENERATOR}" CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> INSTALL_COMMAND "" diff --git a/Tests/ExternalProjectUpdate/ExternalProjectUpdateTest.cmake b/Tests/ExternalProjectUpdate/ExternalProjectUpdateTest.cmake index 8ea4452..ba0c598 100644 --- a/Tests/ExternalProjectUpdate/ExternalProjectUpdateTest.cmake +++ b/Tests/ExternalProjectUpdate/ExternalProjectUpdateTest.cmake @@ -2,7 +2,7 @@ # resulting checked out version is resulting_sha and rebuild. # This check's the correct behavior of the ExternalProject UPDATE_COMMAND. # Also verify that a fetch only occurs when fetch_expected is 1. -macro(check_a_tag desired_tag resulting_sha fetch_expected) +macro(check_a_tag desired_tag resulting_sha fetch_expected update_strategy) message( STATUS "Checking ExternalProjectUpdate to tag: ${desired_tag}" ) # Remove the FETCH_HEAD file, so we can check if it gets replaced with a 'git @@ -10,11 +10,16 @@ macro(check_a_tag desired_tag resulting_sha fetch_expected) set( FETCH_HEAD_file ${ExternalProjectUpdate_BINARY_DIR}/CMakeExternals/Source/TutorialStep1-GIT/.git/FETCH_HEAD ) file( REMOVE ${FETCH_HEAD_file} ) + # Give ourselves a marker in the output. It is difficult to tell where we + # are up to without this + message(STATUS "===> check_a_tag ${desired_tag} ${resulting_sha} ${fetch_expected} ${update_strategy}") + # Configure execute_process(COMMAND ${CMAKE_COMMAND} -G ${CMAKE_GENERATOR} -T "${CMAKE_GENERATOR_TOOLSET}" -A "${CMAKE_GENERATOR_PLATFORM}" -DTEST_GIT_TAG:STRING=${desired_tag} + -DCMAKE_EP_GIT_REMOTE_UPDATE_STRATEGY:STRING=${update_strategy} ${ExternalProjectUpdate_SOURCE_DIR} WORKING_DIRECTORY ${ExternalProjectUpdate_BINARY_DIR} RESULT_VARIABLE error_code @@ -176,16 +181,48 @@ if(GIT_EXECUTABLE) endif() endif() +# When re-running tests locally, this ensures we always start afresh +file(REMOVE_RECURSE ${ExternalProjectUpdate_BINARY_DIR}/CMakeExternals) + if(do_git_tests) - check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1) - check_a_tag(tag1 d1970730310fe8bc07e73f15dc570071f9f9654a 1) + check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1 REBASE) + check_a_tag(tag1 d1970730310fe8bc07e73f15dc570071f9f9654a 1 REBASE) # With the Git UPDATE_COMMAND performance patch, this will not required a # 'git fetch' - check_a_tag(tag1 d1970730310fe8bc07e73f15dc570071f9f9654a 0) - check_a_tag(tag2 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1) - check_a_tag(d19707303 d1970730310fe8bc07e73f15dc570071f9f9654a 1) - check_a_tag(d19707303 d1970730310fe8bc07e73f15dc570071f9f9654a 0) - check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1) + check_a_tag(tag1 d1970730310fe8bc07e73f15dc570071f9f9654a 0 REBASE) + check_a_tag(tag2 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1 REBASE) + check_a_tag(d19707303 d1970730310fe8bc07e73f15dc570071f9f9654a 1 REBASE) + check_a_tag(d19707303 d1970730310fe8bc07e73f15dc570071f9f9654a 0 REBASE) + check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1 REBASE) # This is a remote symbolic ref, so it will always trigger a 'git fetch' - check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1) + check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1 REBASE) + + foreach(strategy IN ITEMS CHECKOUT REBASE_CHECKOUT) + # Move local master back, then apply a change that will cause a conflict + # during rebase. We want to test the fallback to checkout. + check_a_tag(master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1 REBASE) + execute_process(COMMAND ${GIT_EXECUTABLE} reset --hard tag1 + WORKING_DIRECTORY ${ExternalProjectUpdate_BINARY_DIR}/CMakeExternals/Source/TutorialStep1-GIT + RESULT_VARIABLE error_code + ) + if(error_code) + message(FATAL_ERROR "Could not reset local master back to tag1.") + endif() + set(cmlFile ${ExternalProjectUpdate_BINARY_DIR}/CMakeExternals/Source/TutorialStep1-GIT/CMakeLists.txt) + file(READ ${cmlFile} contents) + string(REPLACE "find TutorialConfig.h" "find TutorialConfig.h (conflict here)" + conflictingContent "${contents}" + ) + file(WRITE ${cmlFile} "${conflictingContent}") + execute_process(COMMAND ${GIT_EXECUTABLE} commit -a -m "This should cause a conflict" + WORKING_DIRECTORY ${ExternalProjectUpdate_BINARY_DIR}/CMakeExternals/Source/TutorialStep1-GIT + RESULT_VARIABLE error_code + ) + if(error_code) + message(FATAL_ERROR "Could not commit conflicting change.") + endif() + # This should discard our commit but leave behind an annotated tag + check_a_tag(master 5842b503ba4113976d9bb28d57b5aee1ad2736b7 1 ${strategy}) + endforeach() + endif() |