command.addRefSpec(refSpec); final TransferSummary dataPushed = command.setAll(pushAll).setRemote(remoteName).call(); context.setResponseContent(new CommandResponse() { @Override
protected TransferSummary _call() throws SynchronizationException{ final String remoteName = this.remoteName == null ? "origin" : this.remoteName; final Remote remote = resolveRemote(remoteName); boolean isHttp = isHttp(remote);// don't call new fetch on http(s) remotes until it's boolean isShallow = repository().getDepth().isPresent() || isShallow(remote); boolean isSparse = RepositoryImpl.getFilter(repository()).isPresent(); if (!(isHttp || isShallow || isSparse)) { org.locationtech.geogig.remotes.pack.PushOp newFetch; newFetch = command(org.locationtech.geogig.remotes.pack.PushOp.class)// return newFetch.setProgressListener(getProgressListener())// .call(); final List<TransferableRef> refsToPush = resolveRefs(); SendPack sendPack = command(SendPack.class); sendPack.setRemote(remote); sendPack.setRefs(refsToPush); sendPack.setProgressListener(getProgressListener()); TransferSummary sendPackResult = sendPack.call(); return sendPackResult;
ImmutableSet<Ref> localRefs = getLocalRefs(); for (Ref ref : localRefs) { String localRef = ref.getName(); Ref currentBranch = resolveHeadTarget(); String localRef = currentBranch.getName(); String remoteRef = null; if (refs.length == 0) { refs = new String[2]; refs[0] = resolveHeadTarget().getName(); refs[1] = null; } else {
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()); }
@Test public void testPushWithRefSpec() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedMaster.addFirst(commit); // Push the commit PushOp push = pushOp(); push.addRefSpec("master:NewRemoteBranch"); TransferSummary summary = push.setProgressListener(SIMPLE_PROGRESS).call(); assertSummary(summary, remote.getPushURL(), null, new Ref("refs/heads/NewRemoteBranch", commit.getId())); assertTrue(getRef(remoteRepo, "NewRemoteBranch").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); // 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/NewRemoteBranch")).call(); assertTrue(ref.isPresent()); assertEquals(logged.get(0).getId(), ref.get().getObjectId()); TestSupport.verifyRepositoryContents(remoteRepo); }
@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 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 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 testPushAll() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedMaster.addFirst(commit); localRepo.command(CheckoutOp.class).setSource("Branch1").call(); insertAndAdd(localRepo, points1_modified); RevCommit commit2 = localRepo.command(CommitOp.class).call(); expectedBranch.addFirst(commit2); Optional<Ref> oldMaster = getRef(remoteRepo, "master"); Optional<Ref> oldBranch = getRef(remoteRepo, "Branch1"); // Push the commit PushOp push = pushOp(); TransferSummary summary = push.setAll(true).setProgressListener(SIMPLE_PROGRESS).call(); assertSummary(summary, remote.getPushURL(), oldMaster, getRef(localRepo, "master")); assertSummary(summary, remote.getPushURL(), oldBranch, getRef(localRepo, "Branch1")); // verify that the remote got the commit on both branches remoteRepo.command(CheckoutOp.class).setSource("master").call(); List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedMaster, logged); remoteRepo.command(CheckoutOp.class).setSource("Branch1").call(); logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedBranch, logged); }
@Test public void testPush() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedMaster.addFirst(commit); Optional<Ref> oldRef = getRef(remoteRepo, "master"); Optional<Ref> newRef = getRef(localRepo, "master"); // Push the commit PushOp push = pushOp(); TransferSummary summary = push.setProgressListener(SIMPLE_PROGRESS).call(); assertSummary(summary, remote.getPushURL(), oldRef, newRef); // 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()); }
private Remote resolveRemote(String remoteName) { Optional<Remote> pushRemote = command(RemoteResolve.class).setName(remoteName).call(); checkArgument(pushRemote.isPresent(), "Remote could not be resolved."); return pushRemote.get(); }
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()); }
@Test public void testPushWithRefSpec() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedMaster.addFirst(commit); // Push the commit PushOp push = pushOp(); push.addRefSpec("master:NewRemoteBranch"); TransferSummary summary = push.setProgressListener(SIMPLE_PROGRESS).call(); assertSummary(summary, remote.getPushURL(), null, new Ref("refs/heads/NewRemoteBranch", commit.getId())); assertTrue(getRef(remoteRepo, "NewRemoteBranch").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); // 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/NewRemoteBranch")).call(); assertTrue(ref.isPresent()); assertEquals(logged.get(0).getId(), ref.get().getObjectId()); TestSupport.verifyRepositoryContents(remoteRepo); }
@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 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 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 testPushAll() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedMaster.addFirst(commit); localRepo.command(CheckoutOp.class).setSource("Branch1").call(); insertAndAdd(localRepo, points1_modified); RevCommit commit2 = localRepo.command(CommitOp.class).call(); expectedBranch.addFirst(commit2); Optional<Ref> oldMaster = getRef(remoteRepo, "master"); Optional<Ref> oldBranch = getRef(remoteRepo, "Branch1"); // Push the commit PushOp push = pushOp(); TransferSummary summary = push.setAll(true).setProgressListener(SIMPLE_PROGRESS).call(); assertSummary(summary, remote.getPushURL(), oldMaster, getRef(localRepo, "master")); assertSummary(summary, remote.getPushURL(), oldBranch, getRef(localRepo, "Branch1")); // verify that the remote got the commit on both branches remoteRepo.command(CheckoutOp.class).setSource("master").call(); List<RevCommit> logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedMaster, logged); remoteRepo.command(CheckoutOp.class).setSource("Branch1").call(); logged = newArrayList(remoteRepo.command(LogOp.class).call()); assertEquals(expectedBranch, logged); }
@Test public void testPush() throws Exception { // Add a commit to the local repository insertAndAdd(localRepo, lines3); RevCommit commit = localRepo.command(CommitOp.class).call(); expectedMaster.addFirst(commit); Optional<Ref> oldRef = getRef(remoteRepo, "master"); Optional<Ref> newRef = getRef(localRepo, "master"); // Push the commit PushOp push = pushOp(); TransferSummary summary = push.setProgressListener(SIMPLE_PROGRESS).call(); assertSummary(summary, remote.getPushURL(), oldRef, newRef); // 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()); }
private Remote resolveRemote(String remoteName) { Optional<Remote> pushRemote = command(RemoteResolve.class).setName(remoteName).call(); checkArgument(pushRemote.isPresent(), "Remote could not be resolved."); return pushRemote.get(); }
push.setProgressListener(cli.getProgressListener()); push.setAll(all); push.setRemote(args.get(0)); push.addRefSpec(args.get(i)); TransferSummary dataPushed = push.call(); if (dataPushed.isEmpty()) { cli.getConsole().println("Nothing to push.");