Browse Source

Guard against null branch in PullCommand

Throw a NoHeadException when Repository.getFullBranch
returns null

Bug: 351543
Change-Id: I666cd5b67781508a293ae553c6fe5c080c8f4d99
Signed-off-by: Kevin Sawicki <kevin@github.com>
tags/v1.2.0.201112221803-r
Kevin Sawicki 12 years ago
parent
commit
c3fe50bb18

+ 12
- 0
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java View File

@@ -55,8 +55,11 @@ import java.io.IOException;

import org.eclipse.jgit.api.CreateBranchCommand.SetupUpstreamMode;
import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.api.errors.NoHeadException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.RefUpdate;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.lib.RepositoryTestCase;
import org.eclipse.jgit.lib.StoredConfig;
@@ -220,6 +223,15 @@ public class PullCommandTest extends RepositoryTestCase {
.getRepositoryState());
}

@Test(expected = NoHeadException.class)
public void testPullEmptyRepository() throws Exception {
Repository empty = createWorkRepository();
RefUpdate delete = empty.updateRef(Constants.HEAD, true);
delete.setForceUpdate(true);
delete.delete();
Git.wrap(empty).pull().call();
}

@Override
@Before
public void setUp() throws Exception {

+ 1
- 0
org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties View File

@@ -352,6 +352,7 @@ prefixRemote=remote:
problemWithResolvingPushRefSpecsLocally=Problem with resolving push ref specs locally: {0}
progressMonUploading=Uploading {0}
propertyIsAlreadyNonNull=Property is already non null
pullOnRepoWithoutHEADCurrentlyNotSupported=Pull on repository without HEAD currently not supported
pullTaskName=Pull
pushCancelled=push cancelled
pushIsNotSupportedForBundleTransport=Push is not supported for bundle transport

+ 1
- 0
org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java View File

@@ -412,6 +412,7 @@ public class JGitText extends TranslationBundle {
/***/ public String problemWithResolvingPushRefSpecsLocally;
/***/ public String progressMonUploading;
/***/ public String propertyIsAlreadyNonNull;
/***/ public String pullOnRepoWithoutHEADCurrentlyNotSupported;
/***/ public String pullTaskName;
/***/ public String pushCancelled;
/***/ public String pushIsNotSupportedForBundleTransport;

+ 5
- 1
org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java View File

@@ -112,7 +112,8 @@ public class PullCommand extends TransportCommand<PullCommand, PullResult> {
*/
public PullResult call() throws WrongRepositoryStateException,
InvalidConfigurationException, DetachedHeadException,
InvalidRemoteException, CanceledException, RefNotFoundException {
InvalidRemoteException, CanceledException, RefNotFoundException,
NoHeadException {
checkCallable();

monitor.beginTask(JGitText.get().pullTaskName, 2);
@@ -120,6 +121,9 @@ public class PullCommand extends TransportCommand<PullCommand, PullResult> {
String branchName;
try {
String fullBranch = repo.getFullBranch();
if (fullBranch == null)
throw new NoHeadException(
JGitText.get().pullOnRepoWithoutHEADCurrentlyNotSupported);
if (!fullBranch.startsWith(Constants.R_HEADS)) {
// we can not pull if HEAD is detached and branch is not
// specified explicitly

Loading…
Cancel
Save