The URL understood by the git command can be in the format HTTPS or SSH.
In CMake, using ExternalProject_Add
for the specified GIT_REPOSITORY
any URL understood by the git command may be used.
Using HTTPS user credentials must be given in order to "clone" a private repository. For ExternalProject_Add
, such mechanism exists in the form of HTTP_USERNAME
and HTTP_PASSWORD
when using DOWNLOAD_COMMAND
.
For GIT_REPOSITORY
there doesn't seem to be such a method. When using:
include( ExternalProject )
ExternalProject_Add(test
GIT_REPOSITORY [email protected]:myuser/myprivaterepo.git
GIT_REMOTE_NAME origin
)
on a private repository the following error is given:
fatal: could not read Username for 'https://github.com': No such device or address
How can I make CMake request a password for GIT_REPOSITORY
when using HTTPS connections to a private repository on ExternalProject_Add
?
username and password. We can supply the username and password along with the git clone command in the remote repository url itself. The syntax of the git clone command with the http protocol is, git clone http[s]://host. xz[:port]/path/to/repo.
To connect to a Git repository with authentication over HTTP(S), every time it needs to set a username and password. You can configure Git to remember a username and password by storing them in a remote URL or by using Git credential helper.
While CMake doesn't provide explicit Git options for providing user credentials (like HTTP_USERNAME
and HTTP_PASSWORD
), you can manipulate the Git URL so that you are prompted for login password, as mentioned here. Just specify your username
with a @
in the URL:
ExternalProject_Add(test
GIT_REPOSITORY https://[email protected]/myuser/myprivaterepo.git
GIT_REMOTE_NAME origin
USES_TERMINAL_DOWNLOAD ON
)
Note, you may also need to enable the USES_TERMINAL_DOWNLOAD
option to allow terminal input to enter your credentials. You could also provide your password directly in the URL itself, but best practices do not recommend this:
ExternalProject_Add(test
GIT_REPOSITORY https://username:[email protected]/myuser/myprivaterepo.git
GIT_REMOTE_NAME origin
USES_TERMINAL_DOWNLOAD ON
)
As a bonus, this will also work for Bitbucket accounts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With