aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst/org/eclipse/jgit/api
diff options
context:
space:
mode:
authorShawn Pearce <spearce@spearce.org>2017-02-08 22:27:03 -0500
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2017-02-08 22:27:06 -0500
commit8fce17a995efa1b1fd91578b47be854fed12b462 (patch)
tree00a82cad3856d6f55a73d0584ec5cd09a1ff23b5 /org.eclipse.jgit.test/tst/org/eclipse/jgit/api
parent6450d956bca2374696f5ad8a566db76546ec6573 (diff)
parent46d35a85025ff2e5184422a79451ce724a69a9ec (diff)
downloadjgit-8fce17a995efa1b1fd91578b47be854fed12b462.tar.gz
jgit-8fce17a995efa1b1fd91578b47be854fed12b462.zip
Merge "push: support per-ref force-with-lease"
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/api')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java54
1 files changed, 54 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
index 2a325405e8..eaf64b649f 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
@@ -66,8 +66,10 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.StoredConfig;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.transport.PushResult;
+import org.eclipse.jgit.transport.RefLeaseSpec;
import org.eclipse.jgit.transport.RefSpec;
import org.eclipse.jgit.transport.RemoteConfig;
+import org.eclipse.jgit.transport.RemoteRefUpdate;
import org.eclipse.jgit.transport.TrackingRefUpdate;
import org.eclipse.jgit.transport.URIish;
import org.eclipse.jgit.util.FS;
@@ -379,4 +381,56 @@ public class PushCommandTest extends RepositoryTestCase {
db2.resolve(commit3.getId().getName() + "^{commit}"));
}
}
+
+ @Test
+ public void testPushWithLease() throws JGitInternalException, IOException,
+ GitAPIException, URISyntaxException {
+
+ // create other repository
+ Repository db2 = createWorkRepository();
+
+ // setup the first repository
+ final StoredConfig config = db.getConfig();
+ RemoteConfig remoteConfig = new RemoteConfig(config, "test");
+ URIish uri = new URIish(db2.getDirectory().toURI().toURL());
+ remoteConfig.addURI(uri);
+ remoteConfig.update(config);
+ config.save();
+
+ try (Git git1 = new Git(db)) {
+ // create one commit and push it
+ RevCommit commit = git1.commit().setMessage("initial commit").call();
+ Ref branchRef = git1.branchCreate().setName("initial").call();
+
+ RefSpec spec = new RefSpec("refs/heads/master:refs/heads/x");
+ git1.push().setRemote("test").setRefSpecs(spec)
+ .call();
+
+ assertEquals(commit.getId(),
+ db2.resolve(commit.getId().getName() + "^{commit}"));
+ //now try to force-push a new commit, with a good lease
+
+ RevCommit commit2 = git1.commit().setMessage("second commit").call();
+ Iterable<PushResult> results =
+ git1.push().setRemote("test").setRefSpecs(spec)
+ .setRefLeaseSpecs(new RefLeaseSpec("refs/heads/x", "initial"))
+ .call();
+ for (PushResult result : results) {
+ RemoteRefUpdate update = result.getRemoteUpdate("refs/heads/x");
+ assertEquals(update.getStatus(), RemoteRefUpdate.Status.OK);
+ }
+
+ RevCommit commit3 = git1.commit().setMessage("third commit").call();
+ //now try to force-push a new commit, with a bad lease
+
+ results =
+ git1.push().setRemote("test").setRefSpecs(spec)
+ .setRefLeaseSpecs(new RefLeaseSpec("refs/heads/x", "initial"))
+ .call();
+ for (PushResult result : results) {
+ RemoteRefUpdate update = result.getRemoteUpdate("refs/heads/x");
+ assertEquals(update.getStatus(), RemoteRefUpdate.Status.REJECTED_REMOTE_CHANGED);
+ }
+ }
+ }
}