summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorKevin Sawicki2011-11-22 19:29:28 (EST)
committer Kevin Sawicki2011-11-22 19:29:28 (EST)
commitc3fe50bb18ed4e4e5e563172be4076fa5901a18a (patch)
treea9f1013f7efc1ffbf49453a42749768cc4f91a0c
parent900bdbac5bad9d40df8d310a8f319ab616d1420b (diff)
downloadjgit-c3fe50bb18ed4e4e5e563172be4076fa5901a18a.zip
jgit-c3fe50bb18ed4e4e5e563172be4076fa5901a18a.tar.gz
jgit-c3fe50bb18ed4e4e5e563172be4076fa5901a18a.tar.bz2
Guard against null branch in PullCommandrefs/changes/68/4668/2
Throw a NoHeadException when Repository.getFullBranch returns null Bug: 351543 Change-Id: I666cd5b67781508a293ae553c6fe5c080c8f4d99 Signed-off-by: Kevin Sawicki <kevin@github.com>
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java12
-rw-r--r--org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java1
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java6
4 files changed, 19 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
index 12b2f21..eaed8d8 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
@@ -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 {
diff --git a/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties b/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties
index a5fea35..fc32069 100644
--- a/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties
+++ b/org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties
@@ -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
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java b/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java
index fcc6caf..4dabe07 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java
@@ -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;
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java
index 67f9832..9aa33dd 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java
@@ -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