FetchContent and ExternalProject fail when SOURCE_DIR changes
I open this issue in response to https://discourse.cmake.org/t/error-pathspec-did-not-match-any-file-s-known-to-git. Changing `SOURCE_DIR` for fetch content or external project results in fatal error for git. The only way to recover from this state is by manually deleting files inside the build directory. a minimal example: ```cmake 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) ``` results in error: **error: pathspec did not match any file(s) known to git** another example: ```cmake cmake_minimum_required( VERSION 3.16 ) project(MyProj VERSION 0 LANGUAGES NONE) include(ExternalProject) ExternalProject_Add(myscript GIT_REPOSITORY git@gist.github.com:76c2097a0b6a74c870f6b50c2cf1f470.git SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/foo CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" ) ``` results in error: **Failed to get the hash for HEAD** my setup: CMake 3.19, Gnu Makefile generator, Linux 64b
issue