Browse Source

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>
stable-0.10
Christian Halstrick 14 years ago
parent
commit
285d08d8b7
  1. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java
  2. 7
      org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java

@ -48,6 +48,7 @@ import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
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 class BranchCommandTest extends RepositoryTestCase {
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,

7
org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java

@ -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 @@ public class CreateBranchCommand extends GitCommand<Ref> {
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;
}

Loading…
Cancel
Save