gitgithubcmakeprivate-repositoryfetchcontent

FetchContent access to private Git repository


Has anybody faced with such a issue while trying to get private repository via 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()

Output:

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!

Solution

  • git config --global credential.helper store
    

    works well (requires stored personal access token (PAT) - you could set it while cloning the repo for example)