【发布时间】:2020-10-05 13:56:23
【问题描述】:
使用来自 java 应用程序的 jgit 库 api 执行 git 操作时出现以下错误。此应用程序在 docker 容器内的 tomcat 上运行。
异常堆栈跟踪:
Caused by: org.eclipse.jgit.api.errors.TransportException: https://gitlab.com/xxxxx/testproject.git: git-upload-pack not permitted on 'https://gitlab.com/xxxxx/testproject.git/'
at org.eclipse.jgit.api.LsRemoteCommand.execute(LsRemoteCommand.java:189)
at org.eclipse.jgit.api.LsRemoteCommand.call(LsRemoteCommand.java:128)
at com.test.vcs.JGitUploadPackTest.testRepoUpdate(JGitUploadPackTest.java:35)
Caused by: org.eclipse.jgit.errors.TransportException: https://gitlab.com/xxxxx/testproject.git: git-upload-pack not permitted on 'https://gitlab.com/xxxxx/testproject.git/'
at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:545)
at org.eclipse.jgit.transport.TransportHttp.openFetch(TransportHttp.java:359)
at org.eclipse.jgit.api.LsRemoteCommand.execute(LsRemoteCommand.java:167)
... 135 common frames omitted
注意:JGIT 依赖版本:5.7.0.202003110725-r
重现问题的步骤:
public void getRefBranches() throws IOException, GitAPIException {
FileRepositoryBuilder builder = new FileRepositoryBuilder();
Repository repository = builder.readEnvironment().findGitDir(new File("${projectLocation}")).build();
Git git = new Git(repository);
CredentialsProvider credentialProvider = new UsernamePasswordCredentialsProvider("userName", "password");
LsRemoteCommand listRemoteReferences = git.lsRemote();
listRemoteReferences.setCredentialsProvider(credentialProvider);
listRemoteReferences.setRemote("https://gitlab.com/xxxxx/testproject.git/");
listRemoteReferences.setHeads(true);
listRemoteReferences.setTags(false);
Collection<Ref> remoteBranches = listRemoteReferences.call();
}
【问题讨论】:
-
这不是一个问题,而是对使用过时软件会出现什么问题的问题的答案。您已经落后了三年多,并且落后了 28(!) 个版本。
-
嘿@howlger 我已经尝试过使用最新版本的 jgit (5.7.0.202003110725-r)。使用那个版本,我也遇到了同样的错误。
-
你是如何传递 Gitlab 访问令牌的? eclipse.org/forums/index.php/t/1091325顺便说一下,JGit最新版本是5.8,前两天发布了。
-
我将用户名和密码作为 CredentialsProvider credentialProvider = new UsernamePasswordCredentialsProvider("userName", "password");
-
终于找到问题了,错误是由于默认的HttpConnection。更新了代码以使用 apache HttpClientConnectionFactory。
HttpTransport.setConnectionFactory(new HttpClientConnectionFactory());感谢@howlger,您的意见
标签: java git eclipse gitlab jgit