From 9b66c8faf5a2c0d482c5565056ce844b7b4570ad Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Fri, 27 Jul 2012 17:38:01 +0000 Subject: ExternalProject: Always do a git fetch for a remote ref. Remote git refs always require a git fetch, because the remote may move around where the ref points. --- Modules/ExternalProject.cmake | 15 ++++++++++++++- .../ExternalProjectUpdate/ExternalProjectUpdateTest.cmake | 4 +++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Modules/ExternalProject.cmake b/Modules/ExternalProject.cmake index 7a8aa5f..2355dac 100644 --- a/Modules/ExternalProject.cmake +++ b/Modules/ExternalProject.cmake @@ -418,6 +418,19 @@ if(error_code) message(FATAL_ERROR \"Failed to get the hash for HEAD\") endif() +execute_process( + COMMAND \"${git_EXECUTABLE}\" show-ref ${git_tag} + WORKING_DIRECTORY \"${work_dir}\" + OUTPUT_VARIABLE show_ref_output + ) +# If a remote ref is asked for, which can possibly move around, +# we must always do a fetch and checkout. +if(\"\${show_ref_output}\" MATCHES \"remotes\") + set(is_remote_ref 1) +else() + set(is_remote_ref 0) +endif() + # This will fail if the tag does not exist (it probably has not been fetched # yet). execute_process( @@ -428,7 +441,7 @@ execute_process( ) # Is the hash checkout out that we want? -if(error_code OR NOT (\"\${tag_sha}\" STREQUAL \"\${head_sha}\")) +if(error_code OR is_remote_ref OR NOT (\"\${tag_sha}\" STREQUAL \"\${head_sha}\")) execute_process( COMMAND \"${git_EXECUTABLE}\" fetch WORKING_DIRECTORY \"${work_dir}\" diff --git a/Tests/ExternalProjectUpdate/ExternalProjectUpdateTest.cmake b/Tests/ExternalProjectUpdate/ExternalProjectUpdateTest.cmake index fed40ef..0f9a999 100644 --- a/Tests/ExternalProjectUpdate/ExternalProjectUpdateTest.cmake +++ b/Tests/ExternalProjectUpdate/ExternalProjectUpdateTest.cmake @@ -29,12 +29,12 @@ macro(check_a_tag desired_tag resulting_sha) WORKING_DIRECTORY ${ExternalProjectUpdate_BINARY_DIR}/CMakeExternals/Source/TutorialStep1-GIT RESULT_VARIABLE error_code OUTPUT_VARIABLE tag_sha + OUTPUT_STRIP_TRAILING_WHITESPACE ) if(error_code) message(FATAL_ERROR "Could not check the sha.") endif() - string(STRIP "${tag_sha}" tag_sha) if(NOT (${tag_sha} STREQUAL ${resulting_sha})) message(FATAL_ERROR "UPDATE_COMMAND produced ${tag_sha} @@ -55,4 +55,6 @@ if(GIT_EXECUTABLE) check_a_tag(tag2 5842b503ba4113976d9bb28d57b5aee1ad2736b7) check_a_tag(d19707303 d1970730310fe8bc07e73f15dc570071f9f9654a) check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7) + # This is a remote symbolic ref, so it will always trigger a 'git fetch' + check_a_tag(origin/master 5842b503ba4113976d9bb28d57b5aee1ad2736b7) endif() -- cgit v0.12