标签: jgit

JGit S3 仅支持标准美国存储桶?

除了美国标准的 S3 存储桶之外,是否可以使用 JGit 的其他位置(即通过配置文件等),还是我在这里做错了什么?

如果我尝试将位于 EU 的 S3 存储桶与 JGit 一起使用,jgit 会抛出错误

-> jgit push origin master
Counting objects:       3
Finding sources:        100% (3/3)
Getting sizes:          100% (2/2)
Compressing objects:    100% (1/1)
Writing objects:        100% (3/3)
java.lang.NullPointerException
    at org.eclipse.jgit.transport.AmazonS3.error(AmazonS3.java:518)
    at org.eclipse.jgit.transport.AmazonS3.putImpl(AmazonS3.java:505)
        ...
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用位于美国标准的存储桶时,一切正常。

-> git push origin master
Counting objects:       3
Finding sources:        100% (3/3)
Getting sizes:          100% (2/2)
Compressing objects:    100% (1/1)
Writing objects:        100% (3/3)
Put pack-132548a..idx:  100% (1/1)
To amazon-s3://.jgit@usreponame/chef-receipes.git
 * [new branch]      master -> master
Run Code Online (Sandbox Code Playgroud)

amazon-s3 jgit

2
推荐指数
1
解决办法
616
查看次数

如何在JGit中"git log --follow <path>"?(要检索包括重命名的完整历史记录)

我如何扩展以下logCommand,以获得--followgit log命令的选项?

Git git = new Git(myRepository);
Iterable<RevCommit> log = git.log().addPath("com/mycompany/myclass.java").call();
Run Code Online (Sandbox Code Playgroud)

此选项在jGit中实现,但我不知道如何使用它.logCommand的方法似乎没有用处.谢谢!

git git-log jgit

2
推荐指数
1
解决办法
3435
查看次数

如何使用JGit删除远程分支

我无法弄清楚如何删除远程分支.

我试图模仿以下GIT命令:git push origin:branchToDelete

以下代码及其与空源的变化:

RefSpec refSpec = new RefSpec();
refSpec = refSpec.setSource("");
// remove branch from origin:
git.push().setRefSpecs(refSpec).add(branchToDelete).call();
Run Code Online (Sandbox Code Playgroud)

投掷和例外如:

org.eclipse.jgit.api.errors.JGitInternalException: Exception caught during execution of push command
    at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:175)
    at org.gitscripts.DeleteBranchOperation.execute(DeleteBranchOperation.java:27)
    at org.gitscripts.Main.main(Main.java:27)
Caused by: java.io.IOException: Source ref  doesnt resolve to any object.
    at org.eclipse.jgit.transport.RemoteRefUpdate.<init>(RemoteRefUpdate.java:285)
    at org.eclipse.jgit.transport.RemoteRefUpdate.<init>(RemoteRefUpdate.java:189)
    at org.eclipse.jgit.transport.Transport.findRemoteRefUpdatesFor(Transport.java:612)
    at org.eclipse.jgit.transport.Transport.findRemoteRefUpdatesFor(Transport.java:1150)
    at org.eclipse.jgit.api.PushCommand.call(PushCommand.java:149)
    ... 2 more
Run Code Online (Sandbox Code Playgroud)

提前感谢您的想法和解决方案.

java git remote-branch jgit

2
推荐指数
2
解决办法
4148
查看次数

用JGit抓取GitHub

我正在尝试使用JGit抓取GitHub Wiki.
当我尝试使用一个URL时,它工作得非常好.然后我用另一个随机URL尝试了它并得到了一个错误.
请参阅我的代码摘录:

import java.io.File;
import java.io.IOException;

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;

public class Main {
    // with this URL I get an error
    String url = "https://github.com/radiant/radiant.wiki.git";
    // this URL works
    // String url = "https://github.com/WardCunningham/Smallest-Federated-Wiki.wiki.git";

    public static void main(String[] args) {
        Main m = new Main();
        m.jgitTest();
        System.out.println("Done!");
    }

    public void jgitTest() {
        try {
            File localPath = File.createTempFile("TestGitRepository", "");
            localPath.delete();
            Git.cloneRepository().setURI(url).setDirectory(localPath).call();
        } catch (IOException | GitAPIException e) {
            System.err.println("excepton: " + e.getMessage());
            e.printStackTrace();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这是堆栈跟踪: …

java git github jgit

2
推荐指数
1
解决办法
1751
查看次数

如何在JGit中从一个git分支硬重置到另一个?

我有两个分支,一个是主,另一个是1.现在level1是我需要通过git bash将master重置为level1的最新版本我可以通过以下命令来实现.

$ git checkout master
$ git tag old-master-branch 
$ git reset --hard level1
$ git merge -s ours origin/master 
$ git push origin master
Run Code Online (Sandbox Code Playgroud)

这个对我来说很好.我的问题是如何使用JGit实现它.我试过了.但我无法弄清楚如何设置源和目标分支.

考虑我克隆了一个主分支的场景

 Git git = Git.cloneRepository().setURI(remote).setCredentialsProvider(new UsernamePasswordCredentialsProvider("obuli", "xxxxxx")).setDirectory(gitPath)                    .setNoCheckout(true).call();
Run Code Online (Sandbox Code Playgroud)

现在我需要将其重置为level1.

git.reset().setMode(ResetType.HARD).call();
Run Code Online (Sandbox Code Playgroud)

但在这里我没有指定level1.我不知道如何指定它.还请说明如何git merge -s ours origin/master在JGit中提供

java git bash jgit

2
推荐指数
1
解决办法
2111
查看次数

使用 JGit 从标签加载内容

在 Java 中,我试图加载由我的 git 存储库的标签指向的内容。我想临时访问与该标签对应的版本子文件夹。我尝试使用 的parseTag方法RevWalk,但我不确定这是否是我在文档中发现的正确方法,ObjectLoader可以作为解决此问题的高速公路。仍然不确定我应该使用哪一个。

java git jgit

2
推荐指数
1
解决办法
1558
查看次数

mvn jgitflow:release-finish 正在合并发布 --&gt; 主 --&gt; 开发

当我使用

mvn jgitflow:release-finish
Run Code Online (Sandbox Code Playgroud)

我注意到 release 分支合并到 master 分支。

问题:这是正确的方法吗?

抱歉,我的问题可能很幼稚,因为我是新手。我在想来自 release 分支的代码将合并到 develop 和 master 而不是 release --> master --> develop。

问题:如果我不希望这种情况发生,而是我应该能够从 master 进行 rebase 开发,该怎么办?

maven-3 maven jgit jgitflow-maven-plugin

2
推荐指数
1
解决办法
4065
查看次数

RevCommit JGit 模拟

我的问题是关于模拟RevCommitJGit 库中的对象。当简单地模拟这种类型的对象并定义它的行为时,我收到一个错误。例如:

RevCommit revCommitMock = mock(RevCommit.class);        
Mockito.when(revCommitMock.getShortMessage()).thenReturn("ExampleMessage");
Run Code Online (Sandbox Code Playgroud)

这将导致一个NullPointerException.

也许,正确的方法是调用方法:

parse(RevWalk rw, byte[] raw) 
Run Code Online (Sandbox Code Playgroud)

在对象的实例上RevCommit,但如何正确地做到这一点?我得到了NullPointerException解析类型的模拟对象RevWalk。感谢您提前提供的任何帮助。

java unit-testing mockito jgit

2
推荐指数
1
解决办法
1838
查看次数

不安装Git的Jgit使用

我可以在计算机上不安装 Git 的情况下使用 JGit 吗?

我在想在Jgit上工作之前是否需要安装git,或者JGit提供了自己的便携式git版本?

java git jgit

2
推荐指数
1
解决办法
968
查看次数

Spring Cloud配置服务器git连接问题

连接到存储配置的存储库时,我在 Spring 云配置服务器 (Springboot) 日志中看到问题。我不确定是否由于凭据或其他原因而无法克隆(不允许 git-upload-pack)。任何对此的指示都会很棒。

2021-10-06 22:52:51.763  INFO 1 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2021-10-06 22:52:51.764  INFO 1 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2021-10-06 22:52:51.765  INFO 1 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
2021-10-06 22:52:54.769  WARN 1 --- [nio-8080-exec-1] .c.s.e.MultipleJGitEnvironmentRepository : Error occured cloning to base directory.

org.eclipse.jgit.api.errors.TransportException: https://github.asdf.asdf.asdf.com/asdfad/sdasdf: git-upload-pack not permitted on 'https://github.asdf.asdf.adsf.com/sdfdf/asdfsad-configs/'
    at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:254) ~[org.eclipse.jgit-5.1.3.201810200350-r.jar!/:5.1.3.201810200350-r]
    at org.eclipse.jgit.api.CloneCommand.fetch(CloneCommand.java:306) ~[org.eclipse.jgit-5.1.3.201810200350-r.jar!/:5.1.3.201810200350-r]
    at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:200) ~[org.eclipse.jgit-5.1.3.201810200350-r.jar!/:5.1.3.201810200350-r]
    at org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.cloneToBasedir(JGitEnvironmentRepository.java:612) [spring-cloud-config-server-3.0.4.jar!/:3.0.4]
    at org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.copyRepository(JGitEnvironmentRepository.java:587) [spring-cloud-config-server-3.0.4.jar!/:3.0.4]
    at org.springframework.cloud.config.server.environment.JGitEnvironmentRepository.createGitClient(JGitEnvironmentRepository.java:570) …
Run Code Online (Sandbox Code Playgroud)

github jgit spring-boot kubernetes

2
推荐指数
1
解决办法
2826
查看次数

JGit - 获取影响文件/路径的所有提交(PlotCommitList)

我正在尝试获取包含我的存储库的特定目录或文件的所有提交。

我尝试了以下代码:

public PlotCommitList getPlotCommits(String path){
    System.out.println(path);
    PlotCommitList<PlotLane> plotCommitList = new PlotCommitList<PlotLane>();
    PlotWalk revWalk = new PlotWalk(repository);
    try {

        ObjectId rootId = repository.resolve("HEAD");
        if (rootId != null) {
            RevCommit root = revWalk.parseCommit(rootId);
            revWalk.markStart(root);
            revWalk.setTreeFilter(PathFilter.create(path));
            plotCommitList.source(revWalk);
            plotCommitList.fillTo(Integer.MAX_VALUE);
            return plotCommitList;
        }

    } catch (AmbiguousObjectException ex) {
        Logger.getLogger(GitRepository.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(GitRepository.class.getName()).log(Level.SEVERE, null, ex);
    }
    return plotCommitList;
}
Run Code Online (Sandbox Code Playgroud)

我不只得到影响该文件的提交。我得到了整个列表的一些“子列表”,但不仅仅是那些影响该文件的提交。

也许 TreeFilter 不起作用我怎么想?我应该使用其他方式来获得这些提交吗?我看到 log 命令有一个路径过滤器,但我还没有尝试过,因为它返回一个 RevCommit 列表,对于我的 PlotCommitList,我需要一个 revwalk 来用作源。而且我认为我不能将 RevCommit 转换为 PlotCommit。

一个人在这里遇到了同样的问题(文件A和文件B问题的第一个答案):链接 - 单击此处

commit path filter jgit

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

如何用jgit做“ git grep -e &lt;模式&gt;”?

我正在使用“ git grep -e”来查找与内容模式匹配的文件。我查看了jgit的索引,找不到“ grep”,但最接近的是PatternMatchRevFilter。这类似于“ git grep”在做什么?

在JGit官方用户指南中,它说“ TODO谈论过滤器”。:)有人有使用此过滤器的示例吗?

谢谢!

杰森

ps。这可能是一个单独的问题-如何为搜索指定分支?

git jgit

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

JGit:远程存储库的状态

我正在尝试在 Eclipse 中使用 JGit 获取 Git 存储库的状态。
我在这里找到了一些例子:1 , 2并将它们合并:

import java.io.File;
import java.io.IOException;

import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRemoteException;
import org.eclipse.jgit.api.errors.TransportException;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
import org.eclipse.jgit.api.Status;

public class Main {

     private static final String REMOTE_URL = "https://github.com/github/testrepo.git";

        public static void main(String[] args) throws IOException, InvalidRemoteException, TransportException, GitAPIException {
            // prepare a new folder for the cloned repository
            File localPath = File.createTempFile("TestGitRepository", "");
            localPath.delete();

            // then clone
            System.out.println("Cloning from " + REMOTE_URL + " to " + …
Run Code Online (Sandbox Code Playgroud)

java eclipse git github jgit

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