0

I am trying to use CMake's FetchContent to retrieve an external project.

(Also note that this is the first time that I am trying into a clean directory. I tell this because in some forums they were telling that this occurs when GIT SHA changes after first successful try.)

I have this:

FetchContent_Declare(
    MyExternal
    PREFIX prefix TMP_DIR tmp STAMP_DIR stamp LOG_DIR log DOWNLOAD_DIR download SOURCE_DIR source BINARY_DIR binary INSTALL_DIR install 
GIT_REPOSITORY https://myexternal.com/myexternal.git
GIT_TAG c06d39b285754e62f421b5f36e123ca620a5482d
GIT_PROGRESS TRUE
GIT_CONFIG http.sslVerify=false
GIT_SHALLOW FALSE
    )
FetchContent_MakeAvailable(MyExternal)

But what I get is this:

fatal: reference is not a tree: c06d39b285754e62f421b5f36e123ca620a5482d

I have checked manually and this commit hash do exists and I can checkout it.

How could I get this with FetchContent?

Edit:

Thanks to @tsyvarev, I have got what cmake exactly is doing. It calls just 2 commands:

git clone --no-checkout --progress --config advice.detachedHead=false --config http.sslVerify=false https://myexternal.com/myexternal.git source

and

git checkout c06d39b285754e62f421b5f36e123ca620a5482d --

I have tried exact commands manually and I have discovered that to make this work, between 1. and 2. commands, I have to make this:

git fetch --depth 1 origin c06d39b285754e62f421b5f36e123ca620a5482d

But I don't know why I have to do git fetch especially for this commit. Maybe git experts would explain that.

Mert Mertce
  • 1,049
  • 7
  • 34
  • 2
    Possibly related: [git submodule update fatal error: reference is not a tree](/q/13425298), [Git submodule head 'reference is not a tree' error](/q/2155887), [git checkout throws fatal reference is not a tree](/q/16363909), [Git error on checkout: "fatal: reference is not a tree"](/q/54225047) – starball Jan 25 '23 at 17:40
  • @user I have already searched SO with “not a tree”. – Mert Mertce Jan 25 '23 at 17:59
  • @MertMertce this is related more to git than to CMake, so I would suggest trying to replicate what exactly `FetchContent_Declare` passes to git and try it by using only git. If the issue persists I would refer to the git related questions and if not it's more suited towards CMake`s github. – Milan Š. Jan 25 '23 at 18:02
  • @MilanŠ. their github is just a mirror of their GitLab and doesn't look like it takes issue tickets. Issue tickets should go to [their GitLab](https://gitlab.kitware.com/cmake/cmake/-/issues). – starball Jan 25 '23 at 18:03
  • Probably, the error message is emitted by the script [Modules/ExternalProject/gitupdate.cmake.in](https://github.com/Kitware/CMake/blob/master/Modules/ExternalProject/gitupdate.cmake.in) in some of `execute_process` calls, which contains "checkout" word. You could modify that script (make sure to create backup before!) by adding `COMMAND_ECHO STDOUT` to every such call. That way, in a fresh build (with clean build directory) CMake will print the exact `git checkout` command which is actually executed. – Tsyvarev Jan 25 '23 at 18:38
  • Instead of adding `COMMAND_ECHO STDOUT` into several places, you try to add line `set(CMAKE_EXECUTE_PROCESS_COMMAND_ECHO STDOUT)` at the beginning of that script: https://stackoverflow.com/questions/63529161/how-do-you-make-cmake-print-all-commands-not-just-build-commands. Note, that setting `CMAKE_EXECUTE_PROCESS_COMMAND_ECHO` in your `CMakeLists.txt` is not sufficient, because commands of ExternalProject are executed in separate CMake project. – Tsyvarev Jan 25 '23 at 18:47
  • @MertMertce if the "myexternal" repository is your repository you can try tagging your commit with `git tag`. Then you can pass to `FetchContent_Declare`: `GIT_SHALLOW 1` and instead of `GIT_TAG ` the actual `tag` you used to tag the commit. Based on what you wrote I think it will resolve the issue. – Milan Š. Jan 25 '23 at 22:17

0 Answers0