[英]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: 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 is saving the git:
url into the .git/FETCH_HEAD
file, which is then being used for pushing. JGit将
git:
url保存到.git/FETCH_HEAD
文件中,该文件随后用于推送。 Since the git:
protocol does not support authentication, I am unable to push to the remote and the process fails. 由于
git:
protocol不支持身份验证,因此我无法推送到远程并且进程失败。
The .git/config
file contains the correct https:
URI for the remote (that's why the code is printing the https:
URI). .git/config
文件包含远程的正确https:
URI(这就是代码打印https:
URI的原因)。
My question is: 我的问题是:
What can I do to make JGit set the https:
URI correctly 我该怎么做才能使JGit正确设置
https:
URI
(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. 这个问题只出现在一个非常特殊的环境中(在CircleCI上,一个Ubuntu 12.04.2 LTS虚拟盒子) - 它不能在15.10,14.04 LTS和12.04.2 LTS新的ubuntu发行版上重现,而且不能在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. 重现问题的最简单方法是创建一个虚拟GitHub存储库,然后开始在CircleCI上构建您的虚拟项目,然后使用SSH重新运行您的第一个构建。 You then have 30 minutes of SSH time to upload any groovy/java files to the box.
然后,您有30分钟的SSH时间将任何groovy / java文件上传到该框。 After the 30 minutes the box will be forcefully shut down.
30分钟后,盒子将被强行关闭。
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) 如果我在克隆到的目录中使用
git remote -v
,我得到:(这指出了确实使用了git:
URI的事实)
origin git@github.com:RAnders00/KayonDoc.git (fetch)
origin git@github.com:RAnders00/KayonDoc.git (push)
Looks like you have defined 看起来你已经定义了
Git provides a way to rewrite URLs with the following config: Git提供了一种使用以下配置重写URL的方法:
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 您还可以检查
.gitconfig
文件以验证配置文件中没有此条目
[url "git://"]
insteadOf = https://
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.