How to pass authentication context to clone a git repo using RepositoryCloneLinksRequest.Builder & GitCloneBuilder


I am stuck with a seemingly simple task, “How to clone a git repo using RepositoryCloneLinksRequest.Builder / GitCloneBuilder” through my plugin.

I am able to get the link of the URL that I want to clone as below
RepositoryCloneLinksRequest repoclonelinkreq = new RepositoryCloneLinksRequest.Builder().repository(repo).protocol("http").user(null).build();

How do I proceed next to clone the repo to some /tmp directory on my sever ?

I also tried using the below

gitCommandBuilderFactory.builder(repo).workingDirectory(tmpDir).clone().normal().branch(targetBranch).checkout(true).build(); unsuccessfully.

Are there some useful links of a sample/example code that I can see to figure out how to achieve this?

Ok so, I think below is the right way of doing it.


I wonder how to pass the authentication context ?

This is what I have got so far, I am able to trigger a clone for a repo/branch. But I am not able to pass the authentication context i.e the password.

Below results in a prompt…
Password for ‘http://admin@localhost:7990’: << Prompts me for password on the console and the command times out giving me an exception.

RepositoryCloneLinksRequest rclr =  new RepositoryCloneLinksRequest.Builder().repository(getRepository(req)).protocol("http").

String repositoryURL = repositoryService.getCloneLinks(rclr).iterator().next().getHref();



Then I came across the below link, I wonder if it is possible to pass the authentication context of the logged in user for cloning a repository…

@sylvie any hint that you can give ?

Ok, so I think the HTTP/HTTPs would always ask for git password for cloning. Using SSH works fine with the authentication context provided and does not prompt for password.

RepositoryCloneLinksRequest rclr =  new RepositoryCloneLinksRequest.Builder().repository(getRepository(req)).protocol("ssh").