tl; dr JGit checkout throws exceptions and the git checkout command works fine
I am currently trying to use JGit to check for some changes from the Git online repository, in Java (for work). My current approach (and I'm very new to Git coming from SVN background, so this might be wrong):
- clone the repository to a temporary location on my hard drive
- figure out which revision I want (I tried using the SHA-1 hash as well as the branch name)
- check that version
- from there, I would use the extracted files as contributions to a later part of the program.
- checking another version
- use these files as input for another part of the program.
Essentially, I want to be able to change the contents of my temporary folder with any version. With the command line interface, I was able to do this with git checkout master and git checkout dylanbranch (where dylanbranch is the branch I made on my own clone with an arbitrarily selected revision), but my Java code tries to do the same thing fails:
Git git = Git.open(new File("checkout")); //checkout is the folder with .git git.checkout().setName("master").call(); //succeeds git.checkout().setName("dylanbranch").call(); //fails
And the exceptions printed on the console:
Exception in thread "main" org.eclipse.jgit.api.errors.JGitInternalException: Checkout conflict with files: src/sizzle test/qunit at org.eclipse.jgit.api.CheckoutCommand.call(CheckoutCommand.java:211) at com.avi.scm.git.BranchCheckout.main(BranchCheckout.java:30) Caused by: org.eclipse.jgit.errors.CheckoutConflictException: Checkout conflict with files: src/sizzle test/qunit at org.eclipse.jgit.dircache.DirCacheCheckout.checkout(DirCacheCheckout.java:387) at org.eclipse.jgit.api.CheckoutCommand.call(CheckoutCommand.java:162) ... 1 more
I can verify that the files in question are marked as deleted and not set for commit using git status , although Iβm not sure why these changes exist, and they come back anytime when I switch back to the main branch, Despite this, I can still successfully change the working tree with the Git command line.
So my question is: Why won't JDit work for this application when there is Git on the command line? Any other useful information is appreciated - educate me :)
Update . I tested the jQuery repository and noticed some more problems with JGit: when I work with the "master" branch, git status makes me wonder, m #On branch master and that there is nothing to commit (working directory clean) , but using the JGit status command I see that test/qunit and src/sizzle are marked as Missing . JGit reset does nothing.
java git jgit
Dylan
source share