Author: adietish
Date: 2012-01-26 11:23:14 -0500 (Thu, 26 Jan 2012)
New Revision: 38204
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/EGitUtils.java
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/EGitUtilsTest.java
Log:
[JBIDE-10624] #push will now throw a CoreException (as expected in the using code by rob),
if any part of the push operation failed.
Modified:
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/EGitUtils.java
===================================================================
---
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/EGitUtils.java 2012-01-26
15:54:58 UTC (rev 38203)
+++
trunk/openshift/plugins/org.jboss.tools.openshift.egit.core/src/org/jboss/tools/openshift/egit/core/EGitUtils.java 2012-01-26
16:23:14 UTC (rev 38204)
@@ -59,6 +59,7 @@
import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.FetchResult;
+import org.eclipse.jgit.transport.PushResult;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
import org.eclipse.jgit.transport.RemoteRefUpdate;
@@ -407,7 +408,15 @@
}
PushOperation op = createPushOperation(remoteConfig, repository, force);
op.run(monitor);
- return op.getOperationResult();
+ PushOperationResult pushResult = op.getOperationResult();
+ if (hasFailedEntries(pushResult)) {
+ throw new CoreException(
+ EGitCoreActivator.createErrorStatus(
+ NLS.bind("Could not push repository {0}: {1}",
+ repository.toString(), getErrors(pushResult))
+ , null));
+ }
+ return pushResult;
} catch (CoreException e) {
throw e;
} catch (Exception e) {
@@ -415,6 +424,16 @@
}
}
+ private static String getErrors(PushOperationResult pushResult) {
+ StringBuilder builder = new StringBuilder();
+ for(RemoteRefUpdate failedUpdate : getFailedUpdates(pushResult)) {
+ builder.append(MessageFormat.format(
+ "push from {0} to {1} was {2}", failedUpdate.getSrcRef(),
failedUpdate.getRemoteName(), failedUpdate.getStatus()));
+ }
+ return builder.toString();
+
+ }
+
private static PushOperation createPushOperation(RemoteConfig remoteConfig, Repository
repository, boolean force)
throws CoreException {
@@ -438,7 +457,8 @@
* @throws CoreException
* the core exception
*/
- private static PushOperationSpecification createPushSpec(Collection<URIish>
pushURIs, Collection<RefSpec> pushRefSpecs,
+ private static PushOperationSpecification createPushSpec(Collection<URIish>
pushURIs,
+ Collection<RefSpec> pushRefSpecs,
Repository repository) throws CoreException {
try {
PushOperationSpecification pushSpec = new PushOperationSpecification();
@@ -506,7 +526,34 @@
}
return newRefSpecs;
}
-
+
+ public static boolean hasFailedEntries(PushOperationResult pushOperationResult) {
+ return !getFailedUpdates(pushOperationResult).isEmpty();
+ }
+
+ public static Collection<RemoteRefUpdate> getFailedUpdates(PushOperationResult
pushOperationResult) {
+ List<RemoteRefUpdate> allFailedRefUpdates = new
ArrayList<RemoteRefUpdate>();
+ for (URIish uri : pushOperationResult.getURIs()) {
+ allFailedRefUpdates.addAll(getFailedUpdates(uri, pushOperationResult));
+ }
+ return allFailedRefUpdates;
+ }
+
+ public static Collection<RemoteRefUpdate> getFailedUpdates(URIish uri,
PushOperationResult pushOperationResult) {
+ return getFailedUpdates(pushOperationResult.getPushResult(uri));
+ }
+
+ private static Collection<RemoteRefUpdate> getFailedUpdates(PushResult pushResult)
{
+ List<RemoteRefUpdate> failedRefUpdates = new ArrayList<RemoteRefUpdate>();
+ for (RemoteRefUpdate update : pushResult.getRemoteUpdates()) {
+ if (org.eclipse.jgit.transport.RemoteRefUpdate.Status.OK
+ != update.getStatus()) {
+ failedRefUpdates.add(update);
+ }
+ }
+ return failedRefUpdates;
+ }
+
/**
* Gets the repository that is configured to the given project.
*
Modified:
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/EGitUtilsTest.java
===================================================================
---
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/EGitUtilsTest.java 2012-01-26
15:54:58 UTC (rev 38203)
+++
trunk/openshift/tests/org.jboss.tools.openshift.egit.test/src/org/jboss/tools/openshift/egit/internal/test/EGitUtilsTest.java 2012-01-26
16:23:14 UTC (rev 38204)
@@ -12,8 +12,8 @@
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.egit.core.Activator;
-import org.eclipse.egit.core.op.PushOperationResult;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
@@ -23,7 +23,6 @@
import org.jboss.tools.openshift.egit.internal.test.util.TestUtils;
import org.junit.After;
import org.junit.Before;
-import org.junit.Ignore;
import org.junit.Test;
public class EGitUtilsTest {
@@ -157,8 +156,7 @@
}
- @Ignore
- @Test
+ @Test(expected=CoreException.class)
public void pushFailsOnNonFastForward() throws Exception {
String fileName = "a.txt";
String fileContent = "adietish(a)redhat.com";
@@ -169,17 +167,7 @@
testRepository2.addAndCommit(file2, "adding a file");
testRepository.addRemoteTo(REPO2_REMOTE_NAME, testRepository2.getRepository());
- PushOperationResult result = EGitUtils.push(REPO2_REMOTE_NAME,
testRepository.getRepository(), null);
-
- // repo2 mustn't contain "b.txt"
- testUtils.assertRepositoryMisses(
- testRepository2.getRepository(),
- file2.getName());
- // repo2 must contain "a.txt"
- testUtils.assertRepositoryContainsFilesWithContent(
- testRepository2.getRepository(),
- fileName,
- fileContent);
+ EGitUtils.push(REPO2_REMOTE_NAME, testRepository.getRepository(), null);
}
@Test