jgit

Get the latest commit in a repository with JGit

眉间皱痕 提交于 2019-12-01 19:35:36
I want to get the last commit metadata (the youngest one by date) in a repository using JGit. I know that I can get the commit metadata using try (RevWalk walk = new RevWalk(repository)) { RevCommit commit = walk.parseCommit(repository.resolve(commitHash)); } But how to get the latest commit hash? Is there any other way to get the youngest by date RevCommit in a repository directly? Grzegorz Górkiewicz Compare by dates of last commits in all branches. ListMode.ALL can be changed to ListMode.REMOTE to compare only remote branches. Or... the fluent setter .setListMode(whatever) can be omitted to

List commits associated with a given tag with JGit

时光总嘲笑我的痴心妄想 提交于 2019-12-01 18:12:39
问题 I need to create a history file that details all tags and for each tag, all its commits. I've tried to call getTags() on the repository object and use those object id's, but they are not commit id's. I also tried to use getAllRefsByPeeledObjectId() on the repository and that does bring back commits but I can't associate them to tags. Any ideas? 回答1: List all Tags: List<Ref> call = new Git(repository).tagList().call(); for (Ref ref : call) { System.out.println("Tag: " + ref + " " + ref.getName

Get a single file from a remote git repository

爱⌒轻易说出口 提交于 2019-12-01 17:45:32
Is there a way to programmatically download a single file from a remote git repository, in Java? I prefer a solution which uses as little bandwidth as possible, preferably only downloading that single file. I do not need to browse the repository, I already have the file's path. I prefer a solution which does not depend on other applications (e.g. an installation of another git client on the machine). A Java library which contains a git client implementation itself would be optimal. I was able to do something similar with Subversion using SVNKit and I've seen there is a pure java implementation

How do I release file system locks after cloning repo via JGit

人盡茶涼 提交于 2019-12-01 16:05:09
I am playing around with cloning a remote existing repo with jGit following the guide here: https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/porcelain/CloneRemoteRepository.java I'm using CFML for my example: Git = createObject( 'java', 'org.eclipse.jgit.api.Git' ); localPath = createObject( 'java', 'java.io.File' ).init( expandPath( 'temp' ) ); result = Git.cloneRepository() .setURI( 'https://github.com/github/testrepo.git' ) .setDirectory( localPath ) .call(); result.close(); The clone works great, but file locks are not released on "pack" files inside

How to merge in JGit?

我怕爱的太早我们不能终老 提交于 2019-12-01 15:25:47
How do I merge in JGit? Let's say I want to merge master with foo branch, how do I do this? To merge, you can use the MergeCommand (in package org.eclipse.jgit.api), after a CheckoutCommand . To provide you with an example, because indeed Jgit lacks examples: Git git = ... // you get it through a CloneCommand, InitCommand // or through the file system CheckoutCommand coCmd = git.checkout(); // Commands are part of the api module, which include git-like calls coCmd.setName("master"); coCmd.setCreateBranch(false); // probably not needed, just to make sure coCmd.call(); // switch to "master"

How do I release file system locks after cloning repo via JGit

情到浓时终转凉″ 提交于 2019-12-01 15:05:36
问题 I am playing around with cloning a remote existing repo with jGit following the guide here: https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/porcelain/CloneRemoteRepository.java I'm using CFML for my example: Git = createObject( 'java', 'org.eclipse.jgit.api.Git' ); localPath = createObject( 'java', 'java.io.File' ).init( expandPath( 'temp' ) ); result = Git.cloneRepository() .setURI( 'https://github.com/github/testrepo.git' ) .setDirectory( localPath )

How do I implement sparse checkout in JGit?

邮差的信 提交于 2019-12-01 12:52:01
问题 I need to pull the contents of a specific sub directory in a Github Repository and put it under my own directory. After much research, it seems sparse checkouts is the way to go. However, I am a little unsure, as to how to implement this using JGit. 回答1: 1) You cannot clone only part of a repo -- for example, a repo with lib and Tests but you want to clone only the lib portion. 2) You can use "git clone --depth DEPTH ..." to clone only DEPTH revisions back, but you still get the whole repo,

File diff against the last commit with JGit

﹥>﹥吖頭↗ 提交于 2019-12-01 07:14:33
I am trying to use JGit to get the differences of a file from the last commit to the most recent uncommitted changes. How can I do this with JGit? (using the command line would be the output of git diff HEAD ) Following several discussions ( link1 , link2 ) I come with a piece of code that is able to find the files that are uncommited, but it I cannot get the difference of the files Repository db = new FileRepository("/path/to/git"); Git git = new Git(db); AbstractTreeIterator oldTreeParser = this.prepareTreeParser(db, Constants.HEAD); List<DiffEntry> diff = git.diff().setOldTree(oldTreeParser

File diff against the last commit with JGit

南笙酒味 提交于 2019-12-01 04:21:40
问题 I am trying to use JGit to get the differences of a file from the last commit to the most recent uncommitted changes. How can I do this with JGit? (using the command line would be the output of git diff HEAD ) Following several discussions (link1, link2) I come with a piece of code that is able to find the files that are uncommited, but it I cannot get the difference of the files Repository db = new FileRepository("/path/to/git"); Git git = new Git(db); AbstractTreeIterator oldTreeParser =

How to write git log --stat command in JGit

拥有回忆 提交于 2019-12-01 03:04:04
问题 I have following git command: git log --stat=1000 --all > gitstat.log Is it possible to achieve this in JGit? If yes, what is the equivalent way to write this in JGit? 回答1: To access the history of a repository, JGit provides the RevWalk . Its markStart() method is used to specify at which commits the history should start. All refs in a repository can be obtained with Repository::getAllRefs() . Once a RevWalk instance is set up, use its iterator or its next() method to traverse the history.