error: pathspec did not match any file(s) known to git

I am receiving this error after changing SOURCE_DIR in FetchContent_Declare:

error: pathspec did not match any file(s) known to git

a minimal example:

cmake_minimum_required( VERSION 3.16 )
project(MyProj VERSION 0 LANGUAGES NONE)
include(FetchContent)
FetchContent_Declare(myscript
  GIT_REPOSITORY git@gist.github.com:76c2097a0b6a74c870f6b50c2cf1f470.git
  SOURCE_DIR foo)

# FetchContent_GetProperties(myscript)
# if( NOT cmakebuild_POPULATED )
# 	FetchContent_Populate(myscript)
# endif()
FetchContent_MakeAvailable(myscript)

to trigger the error the project must be build once, then change SOURCE_DIR and and build again.

I used a random git repository only for demonstration. The problem shows both for MakeAvailable and Populate. My CMake version is 3.19.

To get around this error i deleted <build_dir>/_deps/xxx-subbuild/xxx-populate-prefix directory. Is there a better way?

Seems there’s some logic missing that FetchContent needs to do when the sources changes. ExternalProject might have this already?

Cc: @craig.scott

Since FetchContent is essentially forwarding this on to ExternalProject, I suspect the problem exists for using ExternalProject directly too. I’m currently buried deep in refactoring ExternalProject code at the moment. I’d prefer to wait until I’ve got that done before looking into this problem, but it’s good to be aware of it while I’m doing that.

@Gilfoyle Could you report this as a new issue in the issue tracker please?