diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java index 3fb9288d0..8b5688c02 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BranchCommandTest.java +++ b/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, diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java index 792f0a3ea..791145e88 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CreateBranchCommand.java @@ -77,7 +77,7 @@ public class CreateBranchCommand extends GitCommand { private SetupUpstreamMode upstreamMode; - private String startPoint; + private String startPoint = Constants.HEAD; private RevCommit startCommit; @@ -275,9 +275,8 @@ public class CreateBranchCommand extends GitCommand { 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; }