]> source.dussan.org Git - jgit.git/commitdiff
Guard against null branch in PullCommand 68/4668/2
authorKevin Sawicki <kevin@github.com>
Wed, 23 Nov 2011 00:29:28 +0000 (16:29 -0800)
committerKevin Sawicki <kevin@github.com>
Wed, 23 Nov 2011 00:29:28 +0000 (16:29 -0800)
Throw a NoHeadException when Repository.getFullBranch
returns null

Bug: 351543
Change-Id: I666cd5b67781508a293ae553c6fe5c080c8f4d99
Signed-off-by: Kevin Sawicki <kevin@github.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
org.eclipse.jgit/resources/org/eclipse/jgit/JGitText.properties
org.eclipse.jgit/src/org/eclipse/jgit/JGitText.java
org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java

index 12b2f210e839ceaffbbd00eb14b8ef6a04d6c577..eaed8d8b8b74da17ff019046a611c8e7b3a53d27 100644 (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 {
index a5fea35ab70d49e69db502a6c0312c63c29ecf9d..fc32069999a54b900f3cc0340f88be04798412bf 100644 (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
index fcc6cafd5e6d80bc44c3b11422cdbd119d0d853e..4dabe07412ebee1635ec0a8b2d5aad8b97ca7dee 100644 (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;
index 67f9832fb6dc40c6019ed0a4a658b6507847ede6..9aa33ddf68116e50b72d3468c6954507b9fed5d3 100644 (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