lfk
lfk

Reputation: 97

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!

Upvotes: 2

Views: 2731

Answers (2)

Jacob Sánchez
Jacob Sánchez

Reputation: 459

If you are trying to use FetchContent locally with an ssh key, make sure of two things:

  1. Do not use an https url when calling FetchContent_Declare
FetchContent_Declare(
    Project
    GIT_REPOSITORY [email protected]:user/Project.git
    GIT_TAG        master
    GIT_PROGRESS TRUE
    GIT_SHALLOW TRUE
)

FetchContent_MakeAvailable(Project)
  1. Make sure you can call git clone without providing any sort of login or passphrase. For this I followed this answer.
# 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

Upvotes: 0

lfk
lfk

Reputation: 97

git config --global credential.helper store

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

Upvotes: 1

Related Questions