aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiotr Janik2011-06-14 07:26:47 (EDT)
committerSzymon Brandys2011-06-14 07:26:47 (EDT)
commitf65ec49bb222d42451fef478a1be5c10f656e527 (patch)
treec4a0a5e7e6279dfe119f48db3a1e296857f76e4d
parente972f59a375322f4de65b12fd457bd0a498dc4e1 (diff)
downloadorg.eclipse.orion.server-f65ec49bb222d42451fef478a1be5c10f656e527.zip
org.eclipse.orion.server-f65ec49bb222d42451fef478a1be5c10f656e527.tar.gz
org.eclipse.orion.server-f65ec49bb222d42451fef478a1be5c10f656e527.tar.bz2
bug 343646 - [server] Git Push for tags returns wrong result
https://bugs.eclipse.org/bugs/show_bug.cgi?id=343646
-rw-r--r--bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/PushJob.java25
-rw-r--r--tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitPushTest.java3
2 files changed, 21 insertions, 7 deletions
diff --git a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/PushJob.java b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/PushJob.java
index b82744c..6f8aa21 100644
--- a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/PushJob.java
+++ b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/PushJob.java
@@ -13,6 +13,8 @@ package org.eclipse.orion.server.git.servlets;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
+import java.util.HashSet;
+import java.util.Set;
import org.eclipse.core.runtime.*;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.PushCommand;
@@ -80,17 +82,28 @@ public class PushJob extends GitJob {
pushCommand.setPushTags();
Iterable<PushResult> resultIterable = pushCommand.call();
PushResult pushResult = resultIterable.iterator().next();
+ // this set will contain only OK status or UP_TO_DATE status
+ Set<RemoteRefUpdate.Status> statusSet = new HashSet<RemoteRefUpdate.Status>();
for (final RemoteRefUpdate rru : pushResult.getRemoteUpdates()) {
final String rm = rru.getRemoteName();
// final String sr = rru.isDelete() ? null : rru.getSrcRef();
- if (p.segment(1).equals(Repository.shortenRefName(rm))) {
- if (rru.getStatus() != org.eclipse.jgit.transport.RemoteRefUpdate.Status.OK)
- return new Status(IStatus.WARNING, GitActivator.PI_GIT, rru.getStatus().name());
- break;
+ // check status only for branch given in the URL or tags
+ if (p.segment(1).equals(Repository.shortenRefName(rm)) || rm.startsWith(Constants.R_TAGS)) {
+ RemoteRefUpdate.Status status = rru.getStatus();
+ // any status different from UP_TO_DATE and OK should generate warning
+ if (status != RemoteRefUpdate.Status.OK && status != RemoteRefUpdate.Status.UP_TO_DATE)
+ return new Status(IStatus.WARNING, GitActivator.PI_GIT, status.name());
+ // add OK or UP_TO_DATE status to the set
+ statusSet.add(status);
}
// TODO: return results for all updated branches once push is available for remote, see bug 342727, comment 1
}
- return Status.OK_STATUS;
+ if (statusSet.contains(RemoteRefUpdate.Status.OK))
+ // if there is OK status in the set -> something was updated
+ return Status.OK_STATUS;
+ else
+ // if there is no OK status in the set -> only UP_TO_DATE status is possible
+ return new Status(IStatus.WARNING, GitActivator.PI_GIT, RemoteRefUpdate.Status.UP_TO_DATE.name());
}
public TaskInfo getTask() {
@@ -122,7 +135,7 @@ public class PushJob extends GitJob {
} catch (InvalidRemoteException e) {
result = new Status(IStatus.ERROR, GitActivator.PI_GIT, "Error pushing git remote", e); //$NON-NLS-1$
} catch (Exception e) {
- result = new Status(IStatus.ERROR, GitActivator.PI_GIT, "Error cloning git repository", e); //$NON-NLS-1$
+ result = new Status(IStatus.ERROR, GitActivator.PI_GIT, "Error pushing git repository", e); //$NON-NLS-1$
}
task.done(result);
task.setMessage(NLS.bind("Pushing {0} done", p.segment(0)));
diff --git a/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitPushTest.java b/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitPushTest.java
index 83c0e19..0a0df55 100644
--- a/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitPushTest.java
+++ b/tests/org.eclipse.orion.server.tests/src/org/eclipse/orion/server/tests/servlets/git/GitPushTest.java
@@ -551,7 +551,8 @@ public class GitPushTest extends GitTest {
// clone1: tag HEAD with 'tag'
tag(gitTagUri1, "tag", Constants.HEAD);
- push(gitRemoteUri1, 1, 0, Constants.MASTER, Constants.HEAD, true);
+ ServerStatus pushStatus = push(gitRemoteUri1, 1, 0, Constants.MASTER, Constants.HEAD, true);
+ assertEquals(true, pushStatus.isOK());
// clone2: list tags
JSONArray tags = listTags(gitTagUri2);