private void testDeleteRemoteRef(String refSpec) throws Exception { Preconditions.checkArgument(refSpec.startsWith(":") && refSpec.length() > 1); String refName = refSpec.substring(1); Optional<Ref> ref = getRef(remoteRepo, refName); assertTrue(ref.isPresent()); PushOp push = pushOp(); push.addRefSpec(refSpec); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), ref, absent()); assertFalse(remoteRepo.command(RefParse.class).setName(refName).call().isPresent()); }
private void testDeleteRemoteRef(String refSpec) throws Exception { Preconditions.checkArgument(refSpec.startsWith(":") && refSpec.length() > 1); String refName = refSpec.substring(1); Optional<Ref> ref = getRef(remoteRepo, refName); assertTrue(ref.isPresent()); PushOp push = pushOp(); push.addRefSpec(refSpec); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), ref, absent()); assertFalse(remoteRepo.command(RefParse.class).setName(refName).call().isPresent()); }
TransferSummary dataPushed = push.call(); if (dataPushed.isEmpty()) { cli.getConsole().println("Nothing to push.");
@Test public void testPushTooManyRefArgs() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedBranch.addFirst(commit); // Push the commit PushOp push = pushOp(); push.addRefSpec("Branch1:master:HEAD"); exception.expect(IllegalArgumentException.class); push.call(); } }
@Test public void testPushTooManyRefArgs() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedBranch.addFirst(commit); // Push the commit PushOp push = pushOp(); push.addRefSpec("Branch1:master:HEAD"); exception.expect(IllegalArgumentException.class); push.call(); } }
final TransferSummary dataPushed = command.setAll(pushAll).setRemote(remoteName).call(); context.setResponseContent(new CommandResponse() { @Override
@Test public void testPushCommitsFromSparseClone() throws Exception { setupSparseClone(); // Add some commits to the local (sparse) repository List<Feature> features = Arrays.asList(city1, city1_modified, road3); LinkedList<RevCommit> expected = new LinkedList<RevCommit>(); Map<Feature, ObjectId> oids = new HashMap<Feature, ObjectId>(); for (Feature f : features) { ObjectId oId = insertAndAdd(localGeogig.geogig, f); oids.put(f, oId); final RevCommit commit = localGeogig.geogig.command(CommitOp.class) .setMessage(f.getIdentifier().toString()).call(); expected.addFirst(commit); Optional<RevObject> childObject = localGeogig.geogig.command(RevObjectParse.class) .setObjectId(oId).call(); assertTrue(childObject.isPresent()); } PushOp push = pushOp(); push.setAll(true).call(); List<RevCommit> logged = newArrayList(remoteGeogig.geogig.command(LogOp.class).call()); assertEquals("Roads.3", logged.get(0).getMessage()); assertFalse(expected.get(0).getId().equals(logged.get(0).getId())); assertEquals("Cities.1", logged.get(1).getMessage()); assertFalse(expected.get(1).getId().equals(logged.get(1).getId())); assertEquals("Cities.1", logged.get(2).getMessage()); assertFalse(expected.get(2).getId().equals(logged.get(2).getId())); assertExists(remoteGeogig, oids.get(city1), oids.get(city1_modified), oids.get(road3)); }
@Test public void testPushCommitsFromSparseClone() throws Exception { setupSparseClone(); // Add some commits to the local (sparse) repository List<Feature> features = Arrays.asList(city1, city1_modified, road3); LinkedList<RevCommit> expected = new LinkedList<RevCommit>(); Map<Feature, ObjectId> oids = new HashMap<Feature, ObjectId>(); for (Feature f : features) { ObjectId oId = insertAndAdd(localGeogig.geogig, f); oids.put(f, oId); final RevCommit commit = localGeogig.geogig.command(CommitOp.class) .setMessage(f.getIdentifier().toString()).call(); expected.addFirst(commit); Optional<RevObject> childObject = localGeogig.geogig.command(RevObjectParse.class) .setObjectId(oId).call(); assertTrue(childObject.isPresent()); } PushOp push = pushOp(); push.setAll(true).call(); List<RevCommit> logged = newArrayList(remoteGeogig.geogig.command(LogOp.class).call()); assertEquals("Roads.3", logged.get(0).getMessage()); assertFalse(expected.get(0).getId().equals(logged.get(0).getId())); assertEquals("Cities.1", logged.get(1).getMessage()); assertFalse(expected.get(1).getId().equals(logged.get(1).getId())); assertEquals("Cities.1", logged.get(2).getMessage()); assertFalse(expected.get(2).getId().equals(logged.get(2).getId())); assertExists(remoteGeogig, oids.get(city1), oids.get(city1_modified), oids.get(road3)); }
@Test public void testPushWithDefaultRefSpec() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedMaster.addFirst(commit); Optional<Ref> oldBranch = getRef(remoteRepo, "master"); // Push the commit PushOp push = pushOp(); push.addRefSpec(":"); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), oldBranch, getRef(localRepo, "master")); // verify that the remote got the commit List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedMaster, logged); }
@Test public void testPushWithDefaultRefSpec() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedMaster.addFirst(commit); Optional<Ref> oldBranch = getRef(remoteRepo, "master"); // Push the commit PushOp push = pushOp(); push.addRefSpec(":"); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), oldBranch, getRef(localRepo, "master")); // verify that the remote got the commit List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedMaster, logged); }
@Test public void testPushToRemote() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedMaster.addFirst(commit); Optional<Ref> oldBranch = getRef(remoteRepo, "master"); // Push the commit PushOp push = pushOp(); TransferSummary summary = push.setRemote("origin").call(); assertSummary(summary, remote.getPushURL(), oldBranch, getRef(localRepo, "master")); // verify that the remote got the commit List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedMaster, logged); // verify that the local reference of the remote master is updated Optional<Ref> ref = localRepo.command(RefParse.class) .setName(Ref.append(Ref.REMOTES_PREFIX, "origin/master")).call(); assertTrue(ref.isPresent()); assertEquals(logged.get(0).getId(), ref.get().getObjectId()); }
@Test public void testPushToRemote() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedMaster.addFirst(commit); Optional<Ref> oldBranch = getRef(remoteRepo, "master"); // Push the commit PushOp push = pushOp(); TransferSummary summary = push.setRemote("origin").call(); assertSummary(summary, remote.getPushURL(), oldBranch, getRef(localRepo, "master")); // verify that the remote got the commit List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedMaster, logged); // verify that the local reference of the remote master is updated Optional<Ref> ref = localRepo.command(RefParse.class) .setName(Ref.append(Ref.REMOTES_PREFIX, "origin/master")).call(); assertTrue(ref.isPresent()); assertEquals(logged.get(0).getId(), ref.get().getObjectId()); }
@Test public void testPushToRemoteHEAD() throws Exception { insertAndAdd(localRepo, lines3); localRepo.command(CommitOp.class).call(); PushOp push = pushOp(); try { push.setRemote("origin").addRefSpec("HEAD").call(); fail(); } catch (SynchronizationException e) { assertEquals(SynchronizationException.StatusCode.CANNOT_PUSH_TO_SYMBOLIC_REF, e.statusCode); } }
@Test public void testPushToRemoteHEAD() throws Exception { insertAndAdd(localRepo, lines3); localRepo.command(CommitOp.class).call(); PushOp push = pushOp(); try { push.setRemote("origin").addRefSpec("HEAD").call(); fail(); } catch (SynchronizationException e) { assertEquals(SynchronizationException.StatusCode.CANNOT_PUSH_TO_SYMBOLIC_REF, e.statusCode); } }
@Test public void testPushNewBranch() throws Exception { localRepo.command(BranchCreateOp.class).setName("newbranch").call(); localRepo.command(CheckoutOp.class).setSource("newbranch").call(); // Add a commit to the local repository insertAndAdd(localRepo, lines3); insertAndAdd(localRepo, points1_modified); localRepo.command(CommitOp.class).call(); final Ref branch1 = getRef(localRepo, "newbranch").get(); // Push the commit PushOp push = pushOp(); push.addRefSpec("newbranch"); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), absent(), Optional.of(new Ref("refs/heads/newbranch", branch1.getObjectId()))); TestSupport.verifyRepositoryContents(remoteRepo); }
@Test public void testPushWithMultipleRefSpecs() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedMaster.addFirst(commit); final Ref master = getRef(localRepo, "master").get(); final Ref branch1 = getRef(localRepo, "Branch1").get(); // Push the commit PushOp push = pushOp(); push.addRefSpec("master:NewRemoteBranch"); push.addRefSpec("Branch1:NewRemoteBranch2"); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), absent(), Optional.of(new Ref("refs/heads/NewRemoteBranch", master.getObjectId()))); assertSummary(summary, remote.getPushURL(), absent(), Optional.of(new Ref("refs/heads/NewRemoteBranch2", branch1.getObjectId()))); assertTrue( remoteRepo.command(RefParse.class).setName("NewRemoteBranch").call().isPresent()); assertTrue( remoteRepo.command(RefParse.class).setName("NewRemoteBranch2").call().isPresent()); // verify that the remote got the commit remoteRepo.command(CheckoutOp.class).setSource("NewRemoteBranch").call(); List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedMaster, logged); remoteRepo.command(CheckoutOp.class).setSource("NewRemoteBranch2").call(); logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedBranch, logged); TestSupport.verifyRepositoryContents(remoteRepo); }
@Test public void testPushNewBranch() throws Exception { localRepo.command(BranchCreateOp.class).setName("newbranch").call(); localRepo.command(CheckoutOp.class).setSource("newbranch").call(); // Add a commit to the local repository insertAndAdd(localRepo, lines3); insertAndAdd(localRepo, points1_modified); localRepo.command(CommitOp.class).call(); final Ref branch1 = getRef(localRepo, "newbranch").get(); // Push the commit PushOp push = pushOp(); push.addRefSpec("newbranch"); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), absent(), Optional.of(new Ref("refs/heads/newbranch", branch1.getObjectId()))); TestSupport.verifyRepositoryContents(remoteRepo); }
@Test public void testPushWithMultipleRefSpecs() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedMaster.addFirst(commit); final Ref master = getRef(localRepo, "master").get(); final Ref branch1 = getRef(localRepo, "Branch1").get(); // Push the commit PushOp push = pushOp(); push.addRefSpec("master:NewRemoteBranch"); push.addRefSpec("Branch1:NewRemoteBranch2"); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), absent(), Optional.of(new Ref("refs/heads/NewRemoteBranch", master.getObjectId()))); assertSummary(summary, remote.getPushURL(), absent(), Optional.of(new Ref("refs/heads/NewRemoteBranch2", branch1.getObjectId()))); assertTrue( remoteRepo.command(RefParse.class).setName("NewRemoteBranch").call().isPresent()); assertTrue( remoteRepo.command(RefParse.class).setName("NewRemoteBranch2").call().isPresent()); // verify that the remote got the commit remoteRepo.command(CheckoutOp.class).setSource("NewRemoteBranch").call(); List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedMaster, logged); remoteRepo.command(CheckoutOp.class).setSource("NewRemoteBranch2").call(); logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedBranch, logged); TestSupport.verifyRepositoryContents(remoteRepo); }
@Test public void testPushBranch() throws Exception { // Add a commit to the local repository localRepo.command(CheckoutOp.class).setSource("Branch1").call(); insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedBranch.addFirst(commit); localRepo.command(CheckoutOp.class).setSource("master").call(); Optional<Ref> oldBranch = getRef(remoteRepo, "Branch1"); // Push the commit PushOp push = pushOp(); push.addRefSpec("Branch1"); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), oldBranch, getRef(localRepo, "Branch1")); // verify that the remote got the commit Optional<Ref> remoteRef = remoteRepo.command(RefParse.class).setName("Branch1").call(); assertTrue(remoteRef.isPresent()); assertTrue(remoteRef.get().getName().startsWith(Ref.HEADS_PREFIX)); remoteRepo.command(CheckoutOp.class).setSource("Branch1").call(); List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedBranch, logged); }
@Test public void testPushBranch() throws Exception { // Add a commit to the local repository localRepo.command(CheckoutOp.class).setSource("Branch1").call(); insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedBranch.addFirst(commit); localRepo.command(CheckoutOp.class).setSource("master").call(); Optional<Ref> oldBranch = getRef(remoteRepo, "Branch1"); // Push the commit PushOp push = pushOp(); push.addRefSpec("Branch1"); TransferSummary summary = push.call(); assertSummary(summary, remote.getPushURL(), oldBranch, getRef(localRepo, "Branch1")); // verify that the remote got the commit Optional<Ref> remoteRef = remoteRepo.command(RefParse.class).setName("Branch1").call(); assertTrue(remoteRef.isPresent()); assertTrue(remoteRef.get().getName().startsWith(Ref.HEADS_PREFIX)); remoteRepo.command(CheckoutOp.class).setSource("Branch1").call(); List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedBranch, logged); }