标签: jgit

在jgit中配置known_hosts

使用带有gitolite的jgit进行源代码控制,我有一个应用程序可以根据命令生成某些代码,我们希望将其提交给源代码控制.目标是快速前进,提交新代码,然后推送它.

我有以下方法:

private void commitToGitRepository(String updateComment, Config config)
      throws IOException, NoFilepatternException, GitAPIException
{
   if(git == null)
   {
      git = Git.open(new File(config.getDpuCheckoutDir()));
   }
   PullCommand pull = git.pull();
   pull.call();
}
Run Code Online (Sandbox Code Playgroud)

此方法在pull.call()方法调用上失败,但有以下异常:

com.jcraft.jsch.JSchException: UnknownHostKey: www.somehost.com. RSA key fingerprint is 9d:92:a9:c5:5d:cb:5f:dc:57:ff:38:7e:34:31:fe:75
at com.jcraft.jsch.Session.checkHost(Session.java:748)
at com.jcraft.jsch.Session.connect(Session.java:319)
at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:116)
at org.eclipse.jgit.transport.SshTransport.getSession(SshTransport.java:121)
at org.eclipse.jgit.transport.TransportGitSsh$SshFetchConnection.<init>(TransportGitSsh.java:248)
at org.eclipse.jgit.transport.TransportGitSsh.openFetch(TransportGitSsh.java:147)
at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:136)
at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:122)
at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1104)
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:128)
at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:245)
at net.intellidata.dpu.controller.schema.EntityMappingController.commitToGitRepository(EntityMappingController.java:149)
... (truncated where it meets my code)
Run Code Online (Sandbox Code Playgroud)

我读这个的方式,似乎它没有找到我的known_hosts文件user_home/.git.但是,我一直在寻找一个小时,我没有找到一种方法来配置JGit告诉JSch在哪里查找known_hosts文件.

建议?我知道origin的条目存在于我的known_hosts文件中

java git ssh jsch jgit

6
推荐指数
1
解决办法
4437
查看次数

JGit检测工作副本中的重命名

Contex的

我正在尝试在工作副本中检测上次提交后发生的可能的文件重命名.在我的例子中,我有一个干净的工作副本,我这样做:

git mv old.txt new.txt
Run Code Online (Sandbox Code Playgroud)

运行$ git status显示预期结果:

# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       renamed:    old.txt -> new.txt
Run Code Online (Sandbox Code Playgroud)

我试过了

使用StatusCommand,我可以看到old.txt中删除列表,new.txt中添加列表.但我找不到将它们联系在一起的方法.

我知道RenameDetector它的存在,但它可以使用DiffEntry,我不知道如何在HEAD工作副本之间获得DiffEntries .

java git jgit

6
推荐指数
1
解决办法
939
查看次数

结帐与文件冲突.我该怎么办?

我刚刚从持有我的团队项目的远程存储库中提取了一些更改.

这是我收到的消息:

结帐冲突

显然,我的一个合作伙伴改变了与我相同的文件.

我该如何从这里开始?消息很模糊.有错误吗?我必须撤消我的所作所为吗?他有吗?

java eclipse egit jgit vcs-checkout

6
推荐指数
2
解决办法
3万
查看次数

使用Java用户名和密码在ssh上克隆git存储库

我试图用ssh克隆一个带Java的git项目.我有git-shell用户的用户名和密码作为凭据.我可以使用以下命令在终端中克隆项目,没有任何问题.(当然,它首先要求输入密码)

git clone user@HOST:/path/Example.git
Run Code Online (Sandbox Code Playgroud)

但是当我使用JGIT api尝试以下代码时

File localPath = new File("TempProject");
Git.cloneRepository()
    .setURI("ssh://HOST/path/example.git")
    .setDirectory(localPath)
    .setCredentialsProvider(new UsernamePasswordCredentialsProvider("***", "***"))
    .call();
Run Code Online (Sandbox Code Playgroud)

我有

Exception in thread "main" org.eclipse.jgit.api.errors.TransportException: ssh://HOST/path/example.git: Auth fail
Run Code Online (Sandbox Code Playgroud)

我该怎么办?有任何想法吗?(我使用的是OSX 10.9.4和JDK 1.8)

java git ssh jgit

6
推荐指数
1
解决办法
3312
查看次数

如何在JGit中完成合并?

我正在查看JGit文档,目前版本为3.5.1.201410131835-r,我找不到相当于git-merge-base的版本.

我想确定一个分支是最新的,后面的,前面的还是分叉的,如git所示:检查是否需要拉.

JGit中最简洁的方法是找到合并的最佳共同祖先?

java git jgit

6
推荐指数
1
解决办法
1297
查看次数

Scala版本的Jgit

寻找JGit的稳定Scala实现(或类似的东西).

有没有人喜欢它?

我找到了scala-git,但这不是我想要的.

scala jgit

6
推荐指数
1
解决办法
526
查看次数

如何使用Kerberos使用JGit https身份验证

我试图从Windows服务器上通过https克隆一个git存储库.此服务器使用单点登录,因此与kerberos5相关.对我的简单代码知之甚少:

CloneCommand clone = Git.cloneRepository();

clone.setURI("https://gerrit.intra.infineon.com/dcgr/sys/sysbox");
clone.setCredentialsProvider(new UsernamePasswordCredentialsProvider("user", "pass"));
clone.setDirectory(new File("C:\\userdata\\temp\\gittest"));
clone.setBranch("master");
clone.call();
Run Code Online (Sandbox Code Playgroud)

导致异常:

org.eclipse.jgit.errors.TransportException: https://gerrit.mycompany.com/sampleRepo: cannot open git-upload-pack
    at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:518)
    at org.eclipse.jgit.transport.TransportHttp.openFetch(TransportHttp.java:296)
    at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:136)
    at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:122)
    at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1138)
    at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:130)
    ... 22 more
Caused by: java.io.IOException
    at org.eclipse.jgit.transport.HttpAuthMethod$Negotiate.configureRequest(HttpAuthMethod.java:547)
    at org.eclipse.jgit.transport.TransportHttp.httpOpen(TransportHttp.java:561)
    at org.eclipse.jgit.transport.TransportHttp.httpOpen(TransportHttp.java:523)
    at org.eclipse.jgit.transport.TransportHttp.connect(TransportHttp.java:462)
    ... 27 more
Caused by: GSSException: No valid credentials provided (Mechanism level: No valid credentials provided (Mechanism level: Attempt to obtain new INITIATE credentials failed! (null)))
    at sun.security.jgss.spnego.SpNegoContext.initSecContext(SpNegoContext.java:454)
    at sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:248)
    at sun.security.jgss.GSSContextImpl.initSecContext(GSSContextImpl.java:179)
    at org.eclipse.jgit.transport.HttpAuthMethod$Negotiate.configureRequest(HttpAuthMethod.java:541)
    ... …
Run Code Online (Sandbox Code Playgroud)

java security kerberos jgit

6
推荐指数
0
解决办法
667
查看次数

jgitflow:release-finish没有删除发布分支

我最近完成了一个发布分支合并到master并开发使用jgitflow:release-finish.构建成功.

在此输入图像描述

但现在我正在尝试使用创建一个新的分支jgitflow:releast-start.但它给出了以下错误.

[ERROR] Failed to execute goal external.atlassian.jgitflow:jgitflow-maven-plugin:1.0-m5.1:release-start (default-cli) on project <XXXXXXX>: Error starting release: Error starting release: a release branch [refs/remotes/origin/release/1.0.1] already exists. Finish that first! -> [Help 1]
Run Code Online (Sandbox Code Playgroud)

我跑的时候问了下面的问题,我把jgitflow:release-start它输入为1.0.2.

What is the release version for "XXXXXXX"? (org.XXX.automation:XXXXXXX) [1.0.2]: 1.0.2
Run Code Online (Sandbox Code Playgroud)

但它仍然给出了以下错误.我很困惑.

问题:

  • 我们应该手动删除release-1.0.1分支吗?
  • 如果是的话,我将失去历史.有没有办法保留它?

maven-3 maven maven-release-plugin jgit jgitflow-maven-plugin

6
推荐指数
1
解决办法
4654
查看次数

jgit - 基于文件扩展名的git diff

我正在使用JGit API(https://www.eclipse.org/jgit/)来访问git存储库.

在git存储库中,我也存储.txt文件和其他文件格式.我遇到了一个要求,我应该只得到.txt文件的差异.

基本上我试图达到相当于

git diff master HEAD -- '*.txt'  
Run Code Online (Sandbox Code Playgroud)

如何根据文件扩展名过滤git diff?使用JGit API.

从这个答案,(相当于JGit中的git diff),我理解了如何获得正常的差异.但我想添加文件扩展名限制,但我在DiffCommand文档中看不到任何内容(https://download.eclipse.org/jgit/site/5.2.0.201812061821-r/apidocs/index.html).

有人可以给一些指针吗?

java git jgit

6
推荐指数
1
解决办法
177
查看次数

JGit - 如何重用DiffFormatter

这是基于文件扩展名jgit-git diff的后续问题.

我试图添加格式化的差异,List<String>但如果我尝试使用相同的DiffFormatter下面,然后以前的条目附加到下一个条目.

List<String> changes = new LinkedList<>();
            try (OutputStream outputStream = new ByteArrayOutputStream();
                    DiffFormatter diffFormatter = new DiffFormatter(outputStream)) {
                diffFormatter.setRepository(git1.getRepository());
                TreeFilter treeFilter = PathSuffixFilter.create(".txt");
                diffFormatter.setPathFilter(treeFilter);
                List<DiffEntry> entries = diffFormatter.scan(newTree, oldTree);
                for (DiffEntry diffEntry : entries) {
                    diffFormatter.format(diffEntry);
                    changes.add(outputStream.toString());
                    diffFormatter.flush();
                }
            }
Run Code Online (Sandbox Code Playgroud)

因此我被迫DIffFormatter为每个差异条目创建一个.

有没有更好的方法来创造List<String> from List<DiffEntry>而不是DiffFormatter每次都创造新的?

java jgit

6
推荐指数
1
解决办法
109
查看次数