jgit

How do I do the equivalent of “git diff --name-status” with jgit?

青春壹個敷衍的年華 提交于 2019-11-30 20:13:53
I want to get a list of changed/added/deleted files between revision XXXXXX and HEAD. This is what I have so far: String oldHash = "a97e5553e37a25bd1a3c99eab303145baed08dbd"; Git git = Git.open(new File("/tmp/jgit")); Repository repository = git.getRepository(); ObjectId old = repository.resolve(oldHash); ObjectId head = repository.resolve("HEAD"); // how do i get the trees from the obj. id? List<<DiffEntry> diffs = git.diff().setNewTree(null).setOldTree(null).call(); for(DiffEntry diff : diffs) { // do stuff } Is this the right way to go about it and if so, how do I get the trees required for

Jenkins git-client: how to move to jgit on windows

人盡茶涼 提交于 2019-11-30 17:36:43
问题 Since the Jenkins git-client plugin moved to use jgit , there have been a lot of issues with configuration and all of the solutions I have seen involve just switching back to using the old git command line since most installations by now have most of the hacks in place to make it work most of the time. We are in the same boat, but the git command line is still very unreliable under Windows. We like the idea of using jgit under the hood in the new git-client , and would like to see if it

JGit and finding the Head

北城余情 提交于 2019-11-30 17:19:16
I'm trying to get my hands on the HEAD commit with JGit: val builder = new FileRepositoryBuilder() val repo = builder.setGitDir(new File("/www/test-repo")) .readEnvironment() .findGitDir() .build() val walk: RevWalk = new RevWalk(repo, 100) val head: ObjectId = repo.resolve(Constants.HEAD) val headCommit: RevCommit = walk.parseCommit(head) I find that it opens the repo fine, but head value is set to null . I wonder why it can't find HEAD? I'm reading this documentation: http://wiki.eclipse.org/JGit/User_Guide The repository is constructed just like the doc says, and the RevWalk as well. I'm

How to “git log --follow <path>” in JGit? (To retrieve the full history including renames)

回眸只為那壹抹淺笑 提交于 2019-11-30 16:13:44
问题 How do I have to extend the following logCommand, to get the --follow option of the git log command working? Git git = new Git(myRepository); Iterable<RevCommit> log = git.log().addPath("com/mycompany/myclass.java").call(); This option is implemented in jGit, but I don't know how to use it. The logCommand's methods don't appear to be useful. Thank you! 回答1: During some midnight work I got the following: The last commit of a LogCommand will get checked for renames against all older commits

Looping over commits for a file with jGit

会有一股神秘感。 提交于 2019-11-30 12:17:18
问题 I've managed to get to grips with the basics of jGit file in terms of connecting to a repos and adding, commiting, and even looping of the commit messages for the files. File gitDir = new File("/Users/myname/Sites/helloworld/.git"); RepositoryBuilder builder = new RepositoryBuilder(); Repository repository; repository = builder.setGitDir(gitDir).readEnvironment() .findGitDir().build(); Git git = new Git(repository); RevWalk walk = new RevWalk(repository); RevCommit commit = null; // Add all

jGit - how to add all files to staging area

妖精的绣舞 提交于 2019-11-30 11:25:49
I tried in a lot of ways to clone a repo with jGit (it works). Then, I write some archive in the repository, and tried to add all (a git add * , git add -A or something like it).. but it don't work. The files simple are not added to the staging area. My code is like this: FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(new File(folder)) .readEnvironment().findGitDir().setup().build(); CloneCommand clone = Git.cloneRepository(); clone.setBare(false).setCloneAllBranches(true); clone.setDirectory(f).setURI("git@192.168.2.43:test.git"); try {

How do I do git push with JGit?

♀尐吖头ヾ 提交于 2019-11-30 04:48:06
I'm trying to build a Java application that allows users to use Git based repositories. I was able to do this from the command-line, using the following commands: git init <create some files> git add . git commit git remote add <remote repository name> <remote repository URI> git push -u <remote repository name> master This allowed me to create, add and commit content to my local repository and push contents to the remote repository. I am now trying to do the same thing in my Java code, using JGit. I was able to easily do git init, add and commit using JGit API. Repository localRepo = new

Looping over commits for a file with jGit

筅森魡賤 提交于 2019-11-30 02:23:55
I've managed to get to grips with the basics of jGit file in terms of connecting to a repos and adding, commiting, and even looping of the commit messages for the files. File gitDir = new File("/Users/myname/Sites/helloworld/.git"); RepositoryBuilder builder = new RepositoryBuilder(); Repository repository; repository = builder.setGitDir(gitDir).readEnvironment() .findGitDir().build(); Git git = new Git(repository); RevWalk walk = new RevWalk(repository); RevCommit commit = null; // Add all files // AddCommand add = git.add(); // add.addFilepattern(".").call(); // Commit them // CommitCommand

JGit and finding the Head

戏子无情 提交于 2019-11-30 01:02:26
问题 I'm trying to get my hands on the HEAD commit with JGit: val builder = new FileRepositoryBuilder() val repo = builder.setGitDir(new File("/www/test-repo")) .readEnvironment() .findGitDir() .build() val walk: RevWalk = new RevWalk(repo, 100) val head: ObjectId = repo.resolve(Constants.HEAD) val headCommit: RevCommit = walk.parseCommit(head) I find that it opens the repo fine, but head value is set to null . I wonder why it can't find HEAD? I'm reading this documentation: http://wiki.eclipse

Java 实现Git拉包 maven打包项目

假装没事ソ 提交于 2019-11-29 20:08:13
开发过程中遇到这样的需求,Java拉取指定代码库指定分支的代码java代码,然后有maven打包,将打包好的jar上传到文件服务器。 解决思路分三步: 1.从Git仓库下载代码文件 2.用maven打包下载好的代码文件 3.上传jar 解决方案: 1.利用eclipse提供的JGit工具包实现拉包,Java执行Windows/Linux脚本实现maven构建(Linux类似) 参考地址:https://github.com/eclipse/jgit import org.eclipse.jgit.api.Git; import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider; import java.io.File; public class GitTest { public static void main(String[] arg) { String url = "http://git.mrpei.com/peizhouyu/HelloTest.git"; String localPath = "D:\\project\\"; String branchName = "master"; String username = "peizhouyu"; String password = "123456."