FetchContent.cmake + GIT_SHALLOW fails if ref spec is far from HEAD
I am using FetchContent.cmake to get external dependencies form various git repos. When GIT_SHALLOW True
is set, and the GIT_TAG
refers to an SHA
or tag far from TIP
, then I get the following error:
-- Fetching t_cose
Scanning dependencies of target t_cose-populate
[ 11%] Creating directories for 't_cose-populate'
[ 22%] Performing download step (git clone) for 't_cose-populate'
Cloning into 't_cose-src'...
fatal: reference is not a tree: fc3a4b2c7196ff582e8242de8bd4a1bc4eec577f
CMake Error at t_cose-subbuild/t_cose-populate-prefix/tmp/t_cose-populate-gitclone.cmake:40 (message):
Failed to checkout tag: 'fc3a4b2c7196ff582e8242de8bd4a1bc4eec577f'
Due to --no-single-branch
using a tag is either safe or is less affected. --no-single-branch
seems to fetch a few commits of each branch, thus the tag will more likely be fetched. This may need further investigation.
The issue can be worked around by setting GIT_SHALLOW FALSE
, but obviously shallow "cloning" an ref not near to the tip would be an useful feature.
A workaround could be to move to a git init <destination>; git fetch <remote> <respec>; git checkout FETCH_HEAD
process. If this is shallow enough or additional command line switches are needed is to be checked.
Some data:
- I am using cmake v3.18.6 on: Windows 10, ubuntu 18.04, Linux Mint 20.03 Una
- This it the repo and SHA I am fetching: t_cose
fc3a4b2c719
- FIY: (this might be hard to follow) this is how we use FetchContent (kind of a call path):