[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [jgit-dev] How To Checkout with a Specified Tag using CheckoutCommand
|
Hi,
I guess the NullPointerException is not thrown by
git.checkout().setName("my_tag").call()
but because you are later trying to access the result of this call. Look at the JavaDoc: CheckoutCommand.call() will return something non-null if it created a new branch. If you checkout an existing branch or a tag the result will be null. Checkout this code which shows howto checkout a tag:
File tmpDir = new File(System.getProperty("java.io.tmpdir"),
"JGitTest_CloneAndCheckoutExample_"
+ System.currentTimeMillis());
tmpDir.mkdirs();
Git git = Git.cloneRepository().setURI("https://github.com/chalstrick/dondalfi.git").setDirectory(tmpDir).call();
for (Ref tag: git.tagList().call())
System.out.println("Found tag: "+tag.getName());
Ref newBranch = git.checkout().setName("1.0").call();
System.out.println("Checked out 1.0. Newly created branch: "+((newBranch==null) ? "null" : newBranch.getName()));
newBranch = git.checkout().setName("1.1").call();
// Expect a RefNotFoundException here
Ciao
Chris