Fix NPE when calling CreateBranch without explict startpoint

When creating a branch with CreateBranchCommand.call() without
specifying an explicit startPoint HEAD should be used as startPoint.
There was a bug leading to an NPE in such a case.

Change-Id: Ic0a5dc1f33a0987d66c09996c8012c45785500ff
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
This commit is contained in:
Christian Halstrick 2010-10-12 13:36:02 +02:00
parent be93452842
commit 285d08d8b7
2 changed files with 9 additions and 4 deletions

View File

@ -48,6 +48,7 @@
import org.eclipse.jgit.api.ListBranchCommand.ListMode;
import org.eclipse.jgit.api.errors.CannotDeleteCurrentBranchException;
import org.eclipse.jgit.api.errors.DetachedHeadException;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.api.errors.InvalidRefNameException;
import org.eclipse.jgit.api.errors.JGitInternalException;
import org.eclipse.jgit.api.errors.NotMergedException;
@ -400,6 +401,11 @@ public void testRenameRemoteTrackingBranch() throws Exception {
assertEquals(Constants.R_REMOTES + "newRemote", renamed.getName());
}
public void testCreationImplicitStart() throws JGitInternalException,
GitAPIException {
git.branchCreate().setName("topic").call();
}
public Ref createBranch(Git actGit, String name, boolean force,
String startPoint, SetupUpstreamMode mode)
throws JGitInternalException, RefAlreadyExistsException,

View File

@ -77,7 +77,7 @@ public class CreateBranchCommand extends GitCommand<Ref> {
private SetupUpstreamMode upstreamMode;
private String startPoint;
private String startPoint = Constants.HEAD;
private RevCommit startCommit;
@ -275,9 +275,8 @@ private ObjectId getStartPoint() throws AmbiguousObjectException,
return startCommit.getId();
ObjectId result = null;
try {
if (startPoint == null)
result = repo.resolve(Constants.HEAD);
result = repo.resolve(startPoint);
result = repo.resolve((startPoint == null) ? Constants.HEAD
: startPoint);
} catch (AmbiguousObjectException e) {
throw e;
}