Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/PushOperationTest.java67
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java3
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties1
-rw-r--r--org.eclipse.egit.core/src/org/eclipse/egit/core/op/PushOperation.java20
4 files changed, 85 insertions, 6 deletions
diff --git a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/PushOperationTest.java b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/PushOperationTest.java
index 8fe813a8fe..4a1102ebff 100644
--- a/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/PushOperationTest.java
+++ b/org.eclipse.egit.core.test/src/org/eclipse/egit/core/test/op/PushOperationTest.java
@@ -10,12 +10,14 @@ package org.eclipse.egit.core.test.op;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.eclipse.core.filesystem.EFS;
@@ -24,6 +26,9 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.ILog;
+import org.eclipse.core.runtime.ILogListener;
+import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.op.AddToIndexOperation;
@@ -48,6 +53,9 @@ import org.junit.Test;
public class PushOperationTest extends DualRepositoryTestCase {
+
+ private static final String INVALID_URI = "invalid-uri";
+
File workdir;
File workdir2;
@@ -186,6 +194,65 @@ public class PushOperationTest extends DualRepositoryTestCase {
}
/**
+ * An invalid URI should yield an operation result with an error message
+ * and the exception should be logged
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testInvalidUriDuringPush() throws Exception {
+ ILog log = Activator.getDefault().getLog();
+ LogListener listener = new LogListener();
+ log.addLogListener(listener);
+
+ PushOperation pop = createInvalidPushOperation();
+ pop.run(new NullProgressMonitor());
+ PushOperationResult result = pop.getOperationResult();
+ String errorMessage = result.getErrorMessage(new URIish(INVALID_URI));
+ assertNotNull(errorMessage);
+ assertTrue(errorMessage.contains(INVALID_URI));
+
+ assertTrue(listener.loggedSomething());
+ assertTrue(listener.loggedException());
+
+ }
+
+ private PushOperation createInvalidPushOperation() throws Exception {
+ // set up push with invalid URI to provoke an exception
+ PushOperationSpecification spec = new PushOperationSpecification();
+ // the remote is invalid
+ URIish remote = new URIish(INVALID_URI);
+ // update master upon master
+ Repository local = repository1.getRepository();
+ RemoteRefUpdate update = new RemoteRefUpdate(local, "HEAD", "refs/heads/test",
+ false, null, null);
+ spec.addURIRefUpdates(remote, Collections.singletonList(update));
+ // now we can construct the push operation
+ PushOperation pop = new PushOperation(local, spec, false, 0);
+ return pop;
+ }
+
+ private final class LogListener implements ILogListener {
+ private boolean loggedSomething = false;
+ private boolean loggedException = false;
+
+ public void logging(IStatus status, String plugin) {
+ loggedSomething = true;
+ loggedException = status.getException() != null;
+
+ }
+
+ public boolean loggedSomething() {
+ return loggedSomething;
+ }
+
+ public boolean loggedException() {
+ return loggedException;
+ }
+
+}
+
+ /**
* We should get an {@link IllegalStateException} if we run
* getOperationResult before run()
*
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java
index 9fbe632691..7bdbd659b3 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/CoreText.java
@@ -225,6 +225,9 @@ public class CoreText extends NLS {
public static String PushOperation_InternalExceptionOccurredMessage;
/** */
+ public static String PushOperation_ExceptionOccurredDuringPushOnUriMessage;
+
+ /** */
public static String PushOperation_resultCancelled;
/** */
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties b/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties
index 3259273ebd..2857f178a6 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/coretext.properties
@@ -87,6 +87,7 @@ PullOperation_DetachedHeadMessage=No local branch is currently checked out
PullOperation_PullNotConfiguredMessage=The current branch is not configured for pull
PullOperation_TaskName=Pulling {0} repositories
PushOperation_InternalExceptionOccurredMessage=An internal Exception occurred during push: {0}
+PushOperation_ExceptionOccurredDuringPushOnUriMessage=An exception occurred during push on URI {0}: {1}
PushOperation_resultCancelled=Operation was cancelled.
PushOperation_taskNameDryRun=Trying pushing to remote repositories
PushOperation_taskNameNormalRun=Pushing to remote repositories
diff --git a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/PushOperation.java b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/PushOperation.java
index 689226637a..7655c2bf94 100644
--- a/org.eclipse.egit.core/src/org/eclipse/egit/core/op/PushOperation.java
+++ b/org.eclipse.egit.core/src/org/eclipse/egit/core/op/PushOperation.java
@@ -16,6 +16,7 @@ import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.SubProgressMonitor;
+import org.eclipse.egit.core.Activator;
import org.eclipse.egit.core.CoreText;
import org.eclipse.egit.core.EclipseGitProgressTransformer;
import org.eclipse.jgit.api.Git;
@@ -199,13 +200,12 @@ public class PushOperation {
} catch (JGitInternalException e) {
String errorMessage = e.getCause() != null ? e
.getCause().getMessage() : e.getMessage();
- String userMessage = NLS
- .bind(
+ String userMessage = NLS.bind(
CoreText.PushOperation_InternalExceptionOccurredMessage,
errorMessage);
- operationResult.addOperationResult(uri, userMessage);
+ handleException(uri, e, userMessage);
} catch (InvalidRemoteException e) {
- operationResult.addOperationResult(uri, e.getMessage());
+ handleException(uri, e, e.getMessage());
}
monitor.worked(WORK_UNITS_PER_TRANSPORT);
@@ -235,13 +235,21 @@ public class PushOperation {
errorMessage);
URIish uri = rc.getPushURIs().isEmpty() ? rc.getURIs().get(0)
: rc.getPushURIs().get(0);
- operationResult.addOperationResult(uri, userMessage);
+ handleException(uri, e, userMessage);
} catch (InvalidRemoteException e) {
URIish uri = rc.getPushURIs().isEmpty() ? rc.getURIs().get(0)
: rc.getPushURIs().get(0);
- operationResult.addOperationResult(uri, e.getMessage());
+ handleException(uri, e, e.getMessage());
}
}
monitor.done();
}
+
+ private void handleException(final URIish uri, Exception e,
+ String userMessage) {
+ operationResult.addOperationResult(uri, userMessage);
+ String userMessageForUri = NLS.bind(CoreText.PushOperation_ExceptionOccurredDuringPushOnUriMessage, uri, userMessage);
+ Activator.logError(userMessageForUri, e);
+ }
+
}

Back to the top