How to request a password for GIT_REPOSITORY using HTTPS URL
Asked Answered
P

1

10

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

Question

How can I make CMake request a password for GIT_REPOSITORY when using HTTPS connections to a private repository on ExternalProject_Add?

Portulaca answered 8/7, 2019 at 12:40 Comment(0)
A
1

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.

Adverbial answered 2/9, 2021 at 13:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.