summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorDavid Pursehouse <david.pursehouse@gmail.com>2018-04-13 17:43:12 -0400
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2018-04-13 17:43:12 -0400
commit5b0129641eb7627c63afd5a81e7fde0d2aed1355 (patch)
treef1bb5f2799fea6b4128d528dd480bcc1d448ff2c /org.eclipse.jgit.test
parent7cf29ba3e389554641b21d0ac19d9c63462ab888 (diff)
parent29fc7e87c6c961605825e3d15c69ad11d8f33e51 (diff)
downloadjgit-5b0129641eb7627c63afd5a81e7fde0d2aed1355.tar.gz
jgit-5b0129641eb7627c63afd5a81e7fde0d2aed1355.zip
Merge "Push: Ensure ref updates are processed in input order"
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java60
1 files changed, 59 insertions, 1 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java
index c16c1b2a93..63478f6f92 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java
@@ -51,12 +51,16 @@ import static org.junit.Assert.fail;
import java.io.IOException;
import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Collection;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import org.eclipse.jgit.errors.TransportException;
import org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription;
import org.eclipse.jgit.internal.storage.dfs.InMemoryRepository;
+import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
@@ -76,6 +80,7 @@ public class PushConnectionTest {
private Object ctx = new Object();
private InMemoryRepository server;
private InMemoryRepository client;
+ private List<String> processedRefs;
private ObjectId obj1;
private ObjectId obj2;
private ObjectId obj3;
@@ -85,6 +90,7 @@ public class PushConnectionTest {
public void setUp() throws Exception {
server = newRepo("server");
client = newRepo("client");
+ processedRefs = new ArrayList<>();
testProtocol = new TestProtocol<>(
null,
new ReceivePackFactory<Object>() {
@@ -92,7 +98,18 @@ public class PushConnectionTest {
public ReceivePack create(Object req, Repository db)
throws ServiceNotEnabledException,
ServiceNotAuthorizedException {
- return new ReceivePack(db);
+ ReceivePack rp = new ReceivePack(db);
+ rp.setPreReceiveHook(
+ new PreReceiveHook() {
+ @Override
+ public void onPreReceive(ReceivePack receivePack,
+ Collection<ReceiveCommand> cmds) {
+ for (ReceiveCommand cmd : cmds) {
+ processedRefs.add(cmd.getRefName());
+ }
+ }
+ });
+ return rp;
}
});
uri = testProtocol.register(ctx, server);
@@ -196,4 +213,45 @@ public class PushConnectionTest {
}
}
}
+
+ @Test
+ public void commandOrder() throws Exception {
+ TestRepository<?> tr = new TestRepository<>(client);
+ List<RemoteRefUpdate> updates = new ArrayList<>();
+ // Arbitrary non-sorted order.
+ for (int i = 9; i >= 0; i--) {
+ String name = "refs/heads/b" + i;
+ tr.branch(name).commit().create();
+ RemoteRefUpdate rru = new RemoteRefUpdate(client, name, name, false, null,
+ ObjectId.zeroId());
+ updates.add(rru);
+ }
+
+ PushResult result;
+ try (Transport tn = testProtocol.open(uri, client, "server")) {
+ result = tn.push(NullProgressMonitor.INSTANCE, updates);
+ }
+
+ for (RemoteRefUpdate remoteUpdate : result.getRemoteUpdates()) {
+ assertEquals(
+ "update should succeed on " + remoteUpdate.getRemoteName(),
+ RemoteRefUpdate.Status.OK, remoteUpdate.getStatus());
+ }
+
+ List<String> expected = remoteRefNames(updates);
+ assertEquals(
+ "ref names processed by ReceivePack should match input ref names in order",
+ expected, processedRefs);
+ assertEquals(
+ "remote ref names should match input ref names in order",
+ expected, remoteRefNames(result.getRemoteUpdates()));
+ }
+
+ private static List<String> remoteRefNames(Collection<RemoteRefUpdate> updates) {
+ List<String> result = new ArrayList<>();
+ for (RemoteRefUpdate u : updates) {
+ result.add(u.getRemoteName());
+ }
+ return result;
+ }
}