ExternalProject-gitupdate.cmake does not fetch new revisions specified by SHA hash
There's a bug in
ExternalProject_Add (and related functions) when pulling in an external dependency with Git, using a SHA hash as the
The bug occurs when the repo already exists in the local build directory (i.e. this isn't the first build in the directory), and the SHA hash is updated to a newer hash that doesn't exist in the local copy of the repo. In this situation, the generated
import-lib_name-gitupdate.cmake won't fetch from the upstream, and the build fails with an error like:
fatal: reference is not a tree: da4b9237bacccdf19c0760cab7aec4a8359010b0 CMake Error at .../import-lib_name-gitupdate.cmake:175 (execute_process): execute_process failed command indexes: 1: "Child return code: 128"
This happens because
ExternalProject-gitupdate.cmake assumes that git will return
"" for a non-existent hash, which is not true.
For example, SHA
b6589f doesn't exist in my local repo, but
git rev-parse still parses it happily:
$ git rev-parse b6589fc6ab0dc82cf12099d1c2d40ab994e8410c b6589fc6ab0dc82cf12099d1c2d40ab994e8410c
My CMake and git versions:
$ cmake --version cmake version 3.20.2 CMake suite maintained and supported by Kitware (kitware.com/cmake). $ /usr/bin/git --version git version 2.31.1