Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to request a password for GIT_REPOSITORY using HTTPS URL

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?

like image 999
linuxUser123 Avatar asked Jul 08 '19 12:07

linuxUser123


People also ask

How do I copy a repository with username and password?

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.

How do I add a password to a git repository?

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.


1 Answers

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.

like image 161
Kevin Avatar answered Oct 04 '22 17:10

Kevin