有人在尝试通过 FetchContent 获取私有存储库时遇到过这样的问题吗?
CMakeLists.txt:
include(FetchContent)
FetchContent_Declare(
{repository}
GIT_REPOSITORY https://{username}@github.com/{company}/{repository}
USES_TERMINAL_DOWNLOAD ON
)
FetchContent_GetProperties({repository})
if(NOT {repository}_POPULATED)
FetchContent_Populate({repository})
endif()
输出:
MSBuild version 17.3.1+2badb37d1 for .NET Framework
Performing download step (git clone) for '{repository}-populate'
Cloning into '{repository}-src'...
bash: line 1: /dev/tty: No such device or address
CUSTOMBUILD : error : failed to execute prompt script (exit code 1) [C:\git\.....vcxproj]
fatal: could not read Password for 'https://{username}@github.com': No such file or directory
...
-- Had to git clone more than once: 3 times.
CMake Error at {repository}-subbuild/{repository}-populate-prefix/tmp/{repository}-populate-gitclone.cmake:39 (message):
Failed to clone repository: 'https://{username}@github.com/{company}/{repository}'
...
-- Configuring incomplete, errors occurred!
git config --global credential.helper store
运行良好(需要存储的个人访问令牌(PAT) - 例如,您可以在克隆存储库时设置它)
如果您尝试通过 ssh 密钥在本地使用 FetchContent,请确保以下两点:
FetchContent_Declare
FetchContent_Declare(
Project
GIT_REPOSITORY [email protected]:user/Project.git
GIT_TAG master
GIT_PROGRESS TRUE
GIT_SHALLOW TRUE
)
FetchContent_MakeAvailable(Project)
# Add this to .profile
export SSH_AUTH_SOCK=~/.ssh/ssh-agent.$HOSTNAME.sock
ssh-add -l 2>/dev/null >/dev/null
if [ $? -ge 2 ]; then
ssh-agent -a "$SSH_AUTH_SOCK" >/dev/null
fi