jgit

Get message of tags using JGit

烈酒焚心 提交于 2021-02-19 02:23:47
问题 I need for each commit, to get the name and message of the associated tag. I managed to get the tag name associated with my commit . But I can't get the message. I tried like this: String nameTag = ""; List<Ref> call = new Git(git.getRepository()).tagList().call(); // get all tags from repository for (Ref ref: call) { if ((ref.getObjectId().getName()).equals(commit.getName())) { Map<ObjectId, String> names = git.nameRev().add(ref.getObjectId()).addPrefix("refs/tags/").call(); nameTag = names

How to define a “In between” JGit RevFilter?

倖福魔咒の 提交于 2021-02-11 01:30:59
问题 I am trying to implement a RevFilter to be used through RevWalk#setRevFilter() . In the following what I have tried: private class InBetweenRevFilter extends RevFilter { private AnyObjectId end; private AnyObjectId begin; public InBetweenRevFilter(AnyObjectId begin, AnyObjectId end) { this.begin = begin; this.end = end; } @Override public RevFilter clone() { return this; } @Override public boolean include(RevWalk walker, RevCommit c) throws StopWalkException, MissingObjectException,

How to do “git grep -e <pattern>” with jgit?

╄→尐↘猪︶ㄣ 提交于 2021-02-07 09:30:37
问题 I am using "git grep -e " to find files that matches the pattern in content. I looked in the index of jgit, and can't find "grep", but the closest is PatternMatchRevFilter. Is this similar to what "git grep" is doing? In the official JGit user guide, it says "TODO talk about filters". :) Does someone have an example of how to use this filter? Thanks! Jason ps. this might be a separate question - how can I specify a branch for the search? 回答1: First off, PatternMatchRevFilter is not the one

How to find all commits using jgit, not just referenceable ones

不羁岁月 提交于 2021-02-04 21:11:03
问题 I am trying to use jGit to get all commits in a repository, not just the ones I can reach via heads or tags, but all the ones that were not yet garbage collected. Is there a way to do this with jGit in an efficient manner? Update to better describe the actual use-case I am working on a FUSE based filesystem which provides a filesystem-view of the Git history, see https://github.com/centic9/JGitFS/ for a first version (Linux/Mac only). With this I am providing "virtual" sub-directories for

How to find all commits using jgit, not just referenceable ones

旧巷老猫 提交于 2021-02-04 21:10:41
问题 I am trying to use jGit to get all commits in a repository, not just the ones I can reach via heads or tags, but all the ones that were not yet garbage collected. Is there a way to do this with jGit in an efficient manner? Update to better describe the actual use-case I am working on a FUSE based filesystem which provides a filesystem-view of the Git history, see https://github.com/centic9/JGitFS/ for a first version (Linux/Mac only). With this I am providing "virtual" sub-directories for

How to diff with two files by JGit without creating repo?

我们两清 提交于 2021-01-27 05:24:29
问题 When I use JGit to diff with two files, I must create a repo first. But in Git, I only need to use command git diff --no-index 1.txt 2.txt . Is there a way to use diff in JGit without creating repo? 回答1: thank you! I have solved this question! method is below private static String getDiff(String file1, String file2) { OutputStream out = new ByteArrayOutputStream(); try { RawText rt1 = new RawText(new File(file1)); RawText rt2 = new RawText(new File(file2)); EditList diffList = new EditList();

How do I get the tree from parent commits using the JGit API?

不想你离开。 提交于 2021-01-27 04:23:44
问题 For a given commit I want to get the parent(s) commit tree so I can go on to compare the changes. I am finding that getTree() on the parent RevCommit objects always returns null. ObjectId lastCommitId = repository.resolve(Constants.HEAD); RevWalk revWalk = new RevWalk(repository); RevCommit commit = revWalk.parseCommit(lastCommitId); List<RevCommit> parents = new ArrayList<>(); for(RevCommit parent : commit.getParents()) { parents.add(parent); } if ( parents.get(0).getTree() == null ) {

How do I get the tree from parent commits using the JGit API?

↘锁芯ラ 提交于 2021-01-27 04:23:34
问题 For a given commit I want to get the parent(s) commit tree so I can go on to compare the changes. I am finding that getTree() on the parent RevCommit objects always returns null. ObjectId lastCommitId = repository.resolve(Constants.HEAD); RevWalk revWalk = new RevWalk(repository); RevCommit commit = revWalk.parseCommit(lastCommitId); List<RevCommit> parents = new ArrayList<>(); for(RevCommit parent : commit.getParents()) { parents.add(parent); } if ( parents.get(0).getTree() == null ) {

How can I use JGit to add deleted files to the index?

心已入冬 提交于 2020-12-31 04:40:18
问题 I want to add to the index all the modifications made in a folder: files modified files added files removed File gitDir = new File("/home/franck/Repositories/Git/Sandbox/.git"); try (Repository repo = new RepositoryBuilder().setGitDir(gitDir).build()){ try (Git git = new Git(repo)){ final Status status = git.status().addPath("testGit").call(); final AddCommand addCommand = git.add(); Set<String> removed = status.getRemoved(); for (final String s : removed) { System.out.print("removed: "+s);

How can I use JGit to add deleted files to the index?

我的梦境 提交于 2020-12-31 04:38:59
问题 I want to add to the index all the modifications made in a folder: files modified files added files removed File gitDir = new File("/home/franck/Repositories/Git/Sandbox/.git"); try (Repository repo = new RepositoryBuilder().setGitDir(gitDir).build()){ try (Git git = new Git(repo)){ final Status status = git.status().addPath("testGit").call(); final AddCommand addCommand = git.add(); Set<String> removed = status.getRemoved(); for (final String s : removed) { System.out.print("removed: "+s);