summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorAdrian Goerler2011-07-01 11:26:36 (EDT)
committer Adrian Goerler2011-07-01 11:26:36 (EDT)
commit7facdf8de309c59aac52524dcd9d158fc3dc21df (patch)
tree204505aed9c5514339cbec5ac5efa86c74ea35ac
parent3c8a0b052aa47526ca8cd8c8332e1d08a49614b2 (diff)
downloadegit-7facdf8de309c59aac52524dcd9d158fc3dc21df.zip
egit-7facdf8de309c59aac52524dcd9d158fc3dc21df.tar.gz
egit-7facdf8de309c59aac52524dcd9d158fc3dc21df.tar.bz2
Log JGitInternalException occurring during push, e.g. invalid URIrefs/changes/10/3810/1
Bug: 346922 Change-Id: I021bfec3e073c3abc9e24e7e557a4613e2f8f7e8 Signed-off-by: Adrian Goerler <adrian.goerler@sap.com>
-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 8fe813a..4a1102e 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 9fbe632..7bdbd65 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 3259273..2857f17 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 6892266..7655c2b 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);
+ }
+
}