Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JGit sets git: URI instead of https: for remote on CircleCI

I have the following code (see the comments for what's happening):

// Clone repository from GitHub into a local directory.
Git git = Git.cloneRepository()
             .setBranch("gh-pages")
             .setURI("https://github.com/RAnders00/KayonDoc.git")
             .setDirectory(new File("/home/ubuntu/KayonDoc"))
             .call();

// Print out remotes in config from JGit
Config config = git.getRepository().getConfig();
config.getSubsections("remote").forEach(it -> {
    System.out.println(config.getString("remote", it, "url"));
});
// Prints https://github.com/RAnders00/KayonDoc.git
// Everything seems OK

// You could perform some changes to the repository here...

// Push changes to origin
git.push()
   .setCredentialsManager(new UsernamePasswordCredentialsProvider("RAnders00", "hunter2"))
   .call();
// Throws exception (look below)
Caught: org.eclipse.jgit.api.errors.TransportException: [email protected]:RAnders00/KayonDoc.git: push not permitted
org.eclipse.jgit.api.errors.TransportException: [email protected]:RAnders00/KayonDoc.git: push not permitted
        at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:164)
        at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:80)
        at <your class> (YourClass.java:?)
Caused by: org.eclipse.jgit.errors.TransportException: [email protected]:RAnders00/KayonDoc.git: push not permitted
        at org.eclipse.jgit.transport.BasePackPushConnection.noRepository(BasePackPushConnection.java:176)
        at org.eclipse.jgit.transport.BasePackConnection.readAdvertisedRefsImpl(BasePackConnection.java:200)
        at org.eclipse.jgit.transport.BasePackConnection.readAdvertisedRefs(BasePackConnection.java:178)
        at org.eclipse.jgit.transport.TransportGitSsh$SshPushConnection.<init>(TransportGitSsh.java:341)
        at org.eclipse.jgit.transport.TransportGitSsh.openPush(TransportGitSsh.java:166)
        at org.eclipse.jgit.transport.PushProcess.execute(PushProcess.java:154)
        at org.eclipse.jgit.transport.Transport.push(Transport.java:1200)
        at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:157)
        ... 3 more

JGit is saving the git: url into the .git/FETCH_HEAD file, which is then being used for pushing. Since the git: protocol does not support authentication, I am unable to push to the remote and the process fails.

The .git/config file contains the correct https: URI for the remote (that's why the code is printing the https: URI).

My question is:

What can I do to make JGit set the https: URI correctly
(which would then allow me to push again)?


This issue only arises in a very special environment (on CircleCI, a Ubuntu 12.04.2 LTS virtual box) - it's not reproducable on 15.10, 14.04 LTS and 12.04.2 LTS fresh ubuntu distributions and not reproducable on Windows.

The easiest way to reproduce the issue is to create a dummy GitHub repository, then start building your dummy project on CircleCI, and then to rerun your first build with SSH. You then have 30 minutes of SSH time to upload any groovy/java files to the box. After the 30 minutes the box will be forcefully shut down.


If I use git remote -v in the directory this was cloned into, I get: (which points me to the fact that the git: URIs are indeed used)

origin  [email protected]:RAnders00/KayonDoc.git (fetch)
origin  [email protected]:RAnders00/KayonDoc.git (push)
like image 417
randers Avatar asked Nov 20 '15 20:11

randers


1 Answers

Looks like you have defined

URL Rewriting

Git provides a way to rewrite URLs with the following config:

git config --global url."git://".insteadOf https://

To verify if you have set it check the configuration of your repository:

git config --list

You'll see the following line in the output:

url.git://.insteadof=https://

You can also check your .gitconfig files to verify that you don't have this entry in your config files

[url "git://"]
    insteadOf = https://
like image 151
CodeWizard Avatar answered Oct 20 '22 06:10

CodeWizard