jgit

Using Keys with JGit to Access a Git Repository Securely

不羁的心 提交于 2019-11-27 19:52:18
I'm using JGit to access a remote Git repo, and I need to use SSH for it. JGit uses JSch to provide secure access. However, I'm not sure how to set the key file and the knows hosts file for JGit. What I have tried is as follows. Created a custom configuration of the SshSessionFactory , using by subclassing JSchConfigSessionFactory : public class CustomJschConfigSessionFactory extends JschConfigSessionFactory { @Override protected void configure(OpenSshConfig.Host host, Session session) { session.setConfig("StrictHostKeyChecking", "yes"); } } In the class which I access the remote Git repo, did

How to “cat” a file in JGit?

落花浮王杯 提交于 2019-11-27 18:46:53
A while back I was looking for an embeddable distributed version control system in Java , and I think I have found it in JGit , which is a pure Java implementation of git. However, there is not much in the way of sample code or tutorials. How can I use JGit to retrieve the HEAD version of a certain file (just like svn cat or hg cat whould do)? I suppose this involves some rev-tree-walking and am looking for a code sample. morisil Unfortunately Thilo's answer does not work with the latest JGit API. Here is the solution I found: File repoDir = new File("test-git"); // open the repository

JGit: How to get all commits of a branch? (Without changes to the working directory …)

天涯浪子 提交于 2019-11-27 17:52:05
问题 how do I get all commits of a branch with JGit, without changing the working directory? Unfortunately the JGit docs are not very good ... In ruby with grit it is very easy: repo = Grit::Repo.new(pathToRepo) repo.commits(branchName, false).each do |commit| doSomethingWithTheCommit end Bye, hurik 回答1: Tried this here first: https://stackoverflow.com/a/13925765/2246865 But it wasn't was working always, so I found this here: http://www.eclipse.org/forums/index.php/t/280339/ Here my solution, it

Egit hooks do not get triggered

假装没事ソ 提交于 2019-11-27 09:25:14
I have a git repo with a pre-commit hook that intentionally fails 100% of the time. cat .git/hooks/pre-commit > exit 1 If I try to commit through the command line, it fails as expected. However, if I commit from egit, the hook is ignored and the changes get committed. Does egit/jgit not recognize hooks yet? Is there a workaround for this? Thanks in advance! (Original answer: June 2011) MatrixFrog correctly points out to the bug 299315 , which mentions those hooks aren't supported yet. You also can explore the JGit repository, now on GitHub , which doesn't show any commit about hooks . And you

Using native git not jgit in Eclipse git?

匆匆过客 提交于 2019-11-27 06:47:22
问题 Is there any way to configure egit to use your native (OS) git and not the jgit implementation? If not, are there any alternative git Eclipse plugins? EDIT #1 - I should note, AWS CodeCommit uses a credential helper for auth, from .gitconfig: [credential] helper = !/usr/local/bin/aws --profile CodeCommitProfile codecommit credential-helper $@ UseHttpPath = true I'm guessing this is something specific to CodeCommit and is not in jgit. 回答1: EGit strictly uses JGit, the Java implementation of

Clone a git repository into an InMemoryRepository with JGit

≡放荡痞女 提交于 2019-11-27 06:15:55
问题 I need to clone an existing git repository into an InMemoryRepository , using JGit, change a file's content and push the changes back to the remote repository. I couldn't find any examples of cloning a repository into an in-memory repository. I tried this: InMemoryRepository.Builder builder = new InMemoryRepository.Builder(); InMemoryRepository inm = builder.build(); Git.cloneRepository().setURI("git@[github_url].git").setDirectory(inm.getDirectory()).call(); Which resulted in an error :

Check out specific revision from Git repository with JGit

∥☆過路亽.° 提交于 2019-11-27 05:55:50
问题 I am trying to use jGit to clone a repository and checkout a particular commit. Assuming the commit hash is: 1e9ae842ca94f326215358917c620ac407323c81. My first step is: // Cloning the repository Git.cloneRepository() .setURI(remotePath) .setDirectory(localPath) .call(); I then found another question which suggested this approach: git.checkout(). setCreateBranch(true). setName("branchName"). setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK). setStartPoint("origin/" + branchName).

Git: Squashing consecutive commits that are not the most recent commits, and do not start at the root

懵懂的女人 提交于 2019-11-27 03:36:33
问题 I have reviewed several related questions about squashing the most recent commits and squashing a commit at the root, but neither will help me squash non-recent commits that are not at the root. Here is my starting scenario: D---E---F---G---H---I---J master and my desired result: D---E---Z---I---J master where Z is the squash of F---G---H , and F---G---H , D---E , and I---J can be an arbitrarily long sequence of non-branching commits. First approach: [lucas]/home/blah/$ git rebase -i D rebase

Confusion in choosing between JavaGit, JGit and EGit

感情迁移 提交于 2019-11-27 00:49:06
问题 I am making a Java application that uses Git. I found that there is something called JavaGit, EGit and JGit. I know that JavaGit and EGit/JGit are different. What I don't understand is the difference between EGit and JGit. Both are hosted on Eclipse projects but one seems to be Eclipse related and the other not. I don't use Eclipse and I don't plan to, so I really don't care much about "Eclipse integration". Is JGit somehow connected to Eclipse? (It is hosted on www.eclipse.org, and the

How to show changes between commits with JGit

萝らか妹 提交于 2019-11-26 23:05:10
I am trying to show a git diff between two commits for a file. Basically, I did it as in https://github.com/centic9/jgit-cookbook/blob/master/src/main/java/org/dstadler/jgit/porcelain/ShowChangedFilesBetweenCommits.java You can see my full code under https://github.com/svenhornberg/JGitDiff public class RepoDiff { public void compare(byte[] fileContentOld, byte[] fileContentNew) { try { Repository repository = createNewRepository(); Git git = new Git(repository); // create the file commitFileContent(fileContentOld, repository, git, true); commitFileContent(fileContentNew, repository, git,