FetchContent does not fetch after changing/updating GIT_TAG commit sha
Cmake version: 3.21.3
Git version: 2.31.1
Linux system
The project has a simple FetchContent handling like this:
FetchContent_Declare(
sidh
GIT_REPOSITORY https://github.com/wernerd/PQCrypto-SIDH.git
GIT_TAG eb52d2bcd1670e951d3fa8cca83d8a3f0cc94bc8 ## branch wdi top
)
FetchContent_MakeAvailable(sidh)
Running cmake clones the git repo and checks out the commit defined in the GIT_TAG. I updated the GIT_TAG hash to get a newer version and this fails because the generated script sidh-populate-gitupdate.cmake does not fetch before it tries to checkout the new commit.
The culprit seems to be this sequence inside the generated script:
...
else()
get_hash_for_ref("eb52d2bcd1670e951d3fa8cca83d8a3f0cc94bc8" tag_sha error_msg)
if(tag_sha STREQUAL head_sha)
# Have the right commit checked out already
message(VERBOSE "Already at requested ref: ${tag_sha}")
return()
elseif(tag_sha STREQUAL "")
# We don't know about this ref yet, so we have no choice but to fetch.
# We deliberately swallow any error message at the default log level
# because it can be confusing for users to see a failed git command.
# That failure is being handled here, so it isn't an error.
set(fetch_required YES)
set(checkout_name "eb52d2bcd1670e951d3fa8cca83d8a3f0cc94bc8")
if(NOT error_msg STREQUAL "")
message(VERBOSE "${error_msg}")
endif()
...
The firstif
fails because tag_sha
is not equal to head_sha
which is correct. However,
tag_sha
is not empty but contains the sha-string given to get_hash_for_ref
. Thus, the elseif
also fails and fetch_required
is not set to YES.
I checked the git ref-parse command and it returns the sha-string in stdout and therefore
the tag_sha
is set to the sha-value (see function get_hash_for_ref(...)
)