我有以下代码(请参阅有关正在发生的事情的评论):
// 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:
网址保存到.git/FETCH_HEAD
文件中,然后将其用于推送。由于git:
协议不支持身份验证,我无法推送到遥控器并且该过程失败。
.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上重现。
重现问题的最简单方法是create一个虚拟GitHub存储库,然后start building你在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)
答案 0 :(得分:2)
看起来你已经定义了
Git提供了一种使用以下配置重写URL的方法:
git config --global url."git://".insteadOf https://
要验证是否已设置它,请检查存储库的配置:
git config --list
您将在输出中看到以下行:
url.git://.insteadof=https://
您还可以查看.gitconfig
个文件,确认您的配置文件中没有此条目
[url "git://"]
insteadOf = https://