diff options
author | Brad King <brad.king@kitware.com> | 2021-05-10 14:04:59 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2021-05-10 14:05:11 (GMT) |
commit | 8ac314b3818bfd4ab3b5066301e8450d398ebd99 (patch) | |
tree | ae3f6b468a3cfb2c8fec86eba4c6455b104521aa | |
parent | fdbb5a599fc373a1ec7dbbfdcca34ff9669f3c48 (diff) | |
parent | 5e941a545bf5882ddf101cad383dc815fb651f26 (diff) | |
download | CMake-8ac314b3818bfd4ab3b5066301e8450d398ebd99.zip CMake-8ac314b3818bfd4ab3b5066301e8450d398ebd99.tar.gz CMake-8ac314b3818bfd4ab3b5066301e8450d398ebd99.tar.bz2 |
Merge topic 'ep-update-git-hash-missing' into release-3.20
5e941a545b ExternalProject: Ensure git fetch if updating to hash we don't have yet
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Ben Boeckel <ben.boeckel@kitware.com>
Merge-request: !6109
-rw-r--r-- | Modules/ExternalProject-gitupdate.cmake.in | 2 | ||||
-rw-r--r-- | Tests/RunCMake/ExternalProject/FetchGitRefs.cmake (renamed from Tests/RunCMake/ExternalProject/FetchGitTags.cmake) | 21 | ||||
-rw-r--r-- | Tests/RunCMake/ExternalProject/FetchGitRefs/CMakeLists.txt (renamed from Tests/RunCMake/ExternalProject/FetchGitTags/CMakeLists.txt) | 0 | ||||
-rw-r--r-- | Tests/RunCMake/ExternalProject/RunCMakeTest.cmake | 2 |
4 files changed, 21 insertions, 4 deletions
diff --git a/Modules/ExternalProject-gitupdate.cmake.in b/Modules/ExternalProject-gitupdate.cmake.in index 7033918..461e323 100644 --- a/Modules/ExternalProject-gitupdate.cmake.in +++ b/Modules/ExternalProject-gitupdate.cmake.in @@ -5,7 +5,7 @@ cmake_minimum_required(VERSION 3.5) function(get_hash_for_ref ref out_var err_var) execute_process( - COMMAND "@git_EXECUTABLE@" rev-parse "${ref}" + COMMAND "@git_EXECUTABLE@" rev-parse "${ref}^{commit}" WORKING_DIRECTORY "@work_dir@" RESULT_VARIABLE error_code OUTPUT_VARIABLE ref_hash diff --git a/Tests/RunCMake/ExternalProject/FetchGitTags.cmake b/Tests/RunCMake/ExternalProject/FetchGitRefs.cmake index 37d1b40..a00908b 100644 --- a/Tests/RunCMake/ExternalProject/FetchGitTags.cmake +++ b/Tests/RunCMake/ExternalProject/FetchGitRefs.cmake @@ -11,7 +11,7 @@ file(MAKE_DIRECTORY ${srcDir}) file(GLOB entries ${srcRepo}/*) file(REMOVE_RECURSE ${entries} ${binDir}) file(TOUCH ${srcRepo}/firstFile.txt) -configure_file(${CMAKE_CURRENT_LIST_DIR}/FetchGitTags/CMakeLists.txt +configure_file(${CMAKE_CURRENT_LIST_DIR}/FetchGitRefs/CMakeLists.txt ${srcDir}/CMakeLists.txt COPYONLY) function(execGitCommand) @@ -63,5 +63,22 @@ execGitCommand(commit -m "Second file") execGitCommand(tag -a -m "Adding tag" tag_of_interest) execGitCommand(reset --hard HEAD~1) -message(STATUS "Second configure-and-build") +message(STATUS "Configure-and-build, update to tag") configureAndBuild(tag_of_interest) + +# Do the same, but this time for a commit hash +file(TOUCH ${srcRepo}/thirdFile.txt) +execGitCommand(add thirdFile.txt) +execGitCommand(commit -m "Third file") +execGitCommand(tag -a -m "Adding another tag" check_for_hash) +execGitCommand(reset --hard HEAD~1) +execute_process( + WORKING_DIRECTORY ${srcRepo} + COMMAND ${GIT_EXECUTABLE} rev-parse check_for_hash + COMMAND_ERROR_IS_FATAL ANY + OUTPUT_VARIABLE commit_hash + OUTPUT_STRIP_TRAILING_WHITESPACE +) + +message(STATUS "Configure-and-build, update to commit hash ${commit_hash}") +configureAndBuild(${commit_hash}) diff --git a/Tests/RunCMake/ExternalProject/FetchGitTags/CMakeLists.txt b/Tests/RunCMake/ExternalProject/FetchGitRefs/CMakeLists.txt index d9a380c..d9a380c 100644 --- a/Tests/RunCMake/ExternalProject/FetchGitTags/CMakeLists.txt +++ b/Tests/RunCMake/ExternalProject/FetchGitRefs/CMakeLists.txt diff --git a/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake b/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake index 3205dd5..a4244e3 100644 --- a/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake +++ b/Tests/RunCMake/ExternalProject/RunCMakeTest.cmake @@ -185,6 +185,6 @@ if(GIT_EXECUTABLE) # Note that there appear to be differences in where git writes its output to # on some platforms. It may go to stdout or stderr, so force it to be merged. set(RunCMake_TEST_OUTPUT_MERGE TRUE) - run_cmake(FetchGitTags) + run_cmake(FetchGitRefs) set(RunCMake_TEST_OUTPUT_MERGE FALSE) endif() |