繁体   English   中英

JGit为CircleCI上的远程设置git:URI而不是https:

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

我有以下代码(请参阅有关正在发生的事情的评论):

// 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: git@github.com:RAnders00/KayonDoc.git: push not permitted
org.eclipse.jgit.api.errors.TransportException: git@github.com: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: git@github.com: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将git: url保存到.git/FETCH_HEAD文件中,该文件随后用于推送。 由于git: protocol不支持身份验证,因此我无法推送到远程并且进程失败。

.git/config文件包含远程的正确https: URI(这就是代码打印https: URI的原因)。

我的问题是:

我该怎么做才能使JGit正确设置https: URI
(这会让我再次推)?


这个问题只出现在一个非常特殊的环境中(在CircleCI上,一个Ubuntu 12.04.2 LTS虚拟盒子) - 它不能在15.10,14.04 LTS和12.04.2 LTS新的ubuntu发行版上重现,而且不能在Windows上重现。

重现问题的最简单方法是创建一个虚拟GitHub存储库,然后开始在CircleCI上构建您的虚拟项目,然后使用SSH重新运行您的第一个构建。 然后,您有30分钟的SSH时间将任何groovy / java文件上传到该框。 30分钟后,盒子将被强行关闭。


如果我在克隆到的目录中使用git remote -v ,我得到:(这指出了确实使用了git: URI的事实)

origin  git@github.com:RAnders00/KayonDoc.git (fetch)
origin  git@github.com:RAnders00/KayonDoc.git (push)

看起来你已经定义了

URL重写

Git提供了一种使用以下配置重写URL的方法:

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

要验证是否已设置它,请检查存储库的配置:

git config --list

您将在输出中看到以下行:

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

您还可以检查.gitconfig文件以验证配置文件中没有此条目

[url "git://"]
    insteadOf = https://

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM