public FetchOp addRemote(final Remote remote) { return addRemote(Suppliers.ofInstance(Optional.of(remote))); }
/** * @param remoteName the name or URL of a remote repository to fetch from * @return {@code this} */ public FetchOp addRemote(final String remoteName) { checkNotNull(remoteName); return addRemote(command(RemoteResolve.class).setName(remoteName)); }
/** * @param remoteName the name or URL of a remote repository to fetch from * @return {@code this} */ public FetchOp addRemote(final String remoteName) { checkNotNull(remoteName); return addRemote(command(RemoteResolve.class).setName(remoteName)); }
private Collection<RefDiff> fetchRemoteData(final Repository clone, final Remote remote, final int depth) { // Fetch remote data final TransferSummary fetchResults; final String remoteName = remote.getName(); final ProgressListener progress = getProgressListener(); fetchResults = clone.command(FetchOp.class)// .addRemote(remoteName)// .setDepth(depth)// .setProgressListener(progress)// .call(); Map<String, Collection<RefDiff>> changedRefs = fetchResults.getRefDiffs(); String fetchURL = remote.getFetchURL(); Collection<RefDiff> refs = changedRefs.get(fetchURL); if (refs == null) { refs = ImmutableList.of(); } return refs; }
private Collection<RefDiff> fetchRemoteData(final Repository clone, Remote remote, final int depth, final boolean cloneIndexes) { // Fetch remote data final TransferSummary fetchResults; final ProgressListener progress = getProgressListener(); fetchResults = clone.command(FetchOp.class)// .addRemote(remote)// .setDepth(depth)// .setAutofetchTags(true)// .setFetchIndexes(cloneIndexes)// .setProgressListener(progress)// .call(); Map<String, Collection<RefDiff>> changedRefs = fetchResults.getRefDiffs(); String fetchURL = remote.getFetchURL(); Collection<RefDiff> refs = changedRefs.get(fetchURL); if (refs == null) { refs = ImmutableList.of(); } return refs; }
@Test public void testFetchSpecificRemote() throws Exception { // fetch from the remote FetchOp fetch = fetchOp(); TransferSummary summary = fetch.addRemote("upstream").call(); assertEquals(1, summary.getRefDiffs().size()); assertTrue(summary.getRefDiffs().containsKey(upstream.getFetchURL())); assertSummary(summary, upstream.getFetchURL(), absent(), upstreamMaster); assertSummary(summary, upstream.getFetchURL(), absent(), upstreamTag); assertSummary(summary, upstream.getFetchURL(), absent(), upstreamBranch1); TestSupport.verifySameContents(upstreamRepo, localRepo); }
@Test public void testFetchSpecificRemote() throws Exception { // fetch from the remote FetchOp fetch = fetchOp(); TransferSummary summary = fetch.addRemote("upstream").call(); assertEquals(1, summary.getRefDiffs().size()); assertTrue(summary.getRefDiffs().containsKey(upstream.getFetchURL())); assertSummary(summary, upstream.getFetchURL(), absent(), upstreamMaster); assertSummary(summary, upstream.getFetchURL(), absent(), upstreamTag); assertSummary(summary, upstream.getFetchURL(), absent(), upstreamBranch1); TestSupport.verifySameContents(upstreamRepo, localRepo); }
fetch.addRemote(repo);
command.addRemote(remote);
@Test public void testFetchSpecificRemoteAndAll() throws Exception { // fetch from the remote FetchOp fetch = fetchOp(); TransferSummary summary = fetch.addRemote("upstream").setAllRemotes(true).call(); assertEquals(2, summary.getRefDiffs().size()); assertTrue(summary.getRefDiffs().containsKey(origin.getFetchURL())); assertTrue(summary.getRefDiffs().containsKey(upstream.getFetchURL())); assertSummary(summary, origin.getFetchURL(), localOriginMaster, originMaster); assertSummary(summary, origin.getFetchURL(), absent(), originBranch1); assertSummary(summary, origin.getFetchURL(), absent(), originTag); assertSummary(summary, upstream.getFetchURL(), absent(), upstreamMaster); assertSummary(summary, upstream.getFetchURL(), absent(), upstreamBranch1); verifyFetch(); }
@Test public void testFetchSpecificRemoteAndAll() throws Exception { // fetch from the remote FetchOp fetch = fetchOp(); TransferSummary summary = fetch.addRemote("upstream").setAll(true).call(); assertEquals(2, summary.getRefDiffs().size()); assertTrue(summary.getRefDiffs().containsKey(origin.getFetchURL())); assertTrue(summary.getRefDiffs().containsKey(upstream.getFetchURL())); assertSummary(summary, origin.getFetchURL(), localOriginMaster, originMaster); assertSummary(summary, origin.getFetchURL(), absent(), originBranch1); assertSummary(summary, origin.getFetchURL(), absent(), originTag); assertSummary(summary, upstream.getFetchURL(), absent(), upstreamMaster); assertSummary(summary, upstream.getFetchURL(), absent(), upstreamBranch1); verifyFetch(); }
@Test public void testFetchNoChanges() throws Exception { // fetch from the remote FetchOp fetch = fetchOp(); TransferSummary summary = fetch.addRemote("origin").call(); assertEquals(1, summary.getRefDiffs().size()); assertTrue(summary.getRefDiffs().containsKey(origin.getFetchURL())); assertSummary(summary, origin.getFetchURL(), localOriginMaster, originMaster); assertSummary(summary, origin.getFetchURL(), absent(), originBranch1); assertSummary(summary, origin.getFetchURL(), absent(), originTag); verifyFetch(); // fetch again summary = fetch.call(); assertTrue(summary.toString(), summary.isEmpty()); }
@Test public void testFetchNoChanges() throws Exception { // fetch from the remote FetchOp fetch = fetchOp(); TransferSummary summary = fetch.addRemote("origin").call(); assertEquals(1, summary.getRefDiffs().size()); assertTrue(summary.getRefDiffs().containsKey(origin.getFetchURL())); assertSummary(summary, origin.getFetchURL(), localOriginMaster, originMaster); assertSummary(summary, origin.getFetchURL(), absent(), originBranch1); assertSummary(summary, origin.getFetchURL(), absent(), originTag); verifyFetch(); // fetch again summary = fetch.call(); assertTrue(summary.toString(), summary.isEmpty()); }
@Test public void testFetchWithPrune() throws Exception { // fetch from the remote FetchOp fetch = fetchOp(); fetch.addRemote("origin").setAllRemotes(true).call(); verifyFetch(); Optional<Ref> localOriginBranch1 = getRef(localRepo, "refs/remotes/origin/Branch1"); assertTrue(localOriginBranch1.isPresent()); // Remove a branch from the remote remoteGeogig.geogig.command(BranchDeleteOp.class).setName("Branch1").call(); // fetch again fetch = fetchOp(); TransferSummary summary = fetch.setPrune(true).call(); assertSummary(summary, origin.getFetchURL(), localOriginBranch1, absent()); verifyPrune(); }
@Test public void testFetchWithPrune() throws Exception { // fetch from the remote FetchOp fetch = fetchOp(); fetch.addRemote("origin").setAll(true).call(); verifyFetch(); Optional<Ref> localOriginBranch1 = getRef(localRepo, "refs/remotes/origin/Branch1"); assertTrue(localOriginBranch1.isPresent()); // Remove a branch from the remote remoteGeogig.geogig.command(BranchDeleteOp.class).setName("Branch1").call(); // fetch again fetch = fetchOp(); TransferSummary summary = fetch.setPrune(true).call(); assertSummary(summary, origin.getFetchURL(), localOriginBranch1, absent()); verifyPrune(); }
@Test public void testFetchSingleRef() throws Exception { final Repository remote = this.originRepo; final Repository local = this.localRepo; remote.command(BranchCreateOp.class).setName("branch2").setAutoCheckout(true).call(); insertAndAdd(remote, lines1_modified, lines2_modified, lines3_modified); RevCommit branch2Tip = commit(remote, "modified lines on branch2"); checkout(remote, "master"); remote.command(BranchCreateOp.class).setName("branch3").setAutoCheckout(true).call(); insertAndAdd(remote, points1_modified, points2_modified, points3_modified); RevCommit branch3Tip = commit(remote, "modified points on branch3"); checkout(remote, "master"); Optional<Ref> originBranch2 = Optional .of(toRemote(origin, getRef(remote, "branch2").get())); // fetch from the remote FetchOp fetch = fetchOp().setAutofetchTags(false); Remote singleRefOrigin = origin.fetch("refs/heads/branch2"); TransferSummary summary = fetch.addRemote(singleRefOrigin).call(); assertFalse(getRef(local, "refs/heads/branch2").isPresent()); assertTrue(getRef(local, "refs/remotes/origin/branch2").isPresent()); assertFalse(getRef(local, "branch3").isPresent()); assertEquals(branch2Tip.getId(), getRef(local, "refs/remotes/origin/branch2").get().getObjectId()); assertEquals(1, summary.getRefDiffs().size()); assertTrue(summary.getRefDiffs().containsKey(origin.getFetchURL())); assertEquals(1, summary.getRefDiffs().get(origin.getFetchURL()).size()); assertSummary(summary, origin.getFetchURL(), absent(), originBranch2); TestSupport.verifyRepositoryContents(local, "refs/remotes/origin/branch2"); }
private void fakeUpToDate() { Remote remote = request.buildRemote(); GeogigTransaction tx = request.getTransaction(origin.getRepo().context()); tx.command(FetchOp.class).setFetchIndexes(true).addRemote(remote).call(); Ref remoteBranchState = clone.getRef(request.getRemoteBranch()); Ref localRemoteBranchState = tx.command(RefParse.class).setName(request.getOriginRef()) .call().get(); assertEquals(remoteBranchState.getObjectId(), localRemoteBranchState.getObjectId()); } }
public @Test void testFetchRespectsTargeRef() throws Exception { final Repository remote = this.originRepo; final Repository local = this.localRepo; remote.command(BranchCreateOp.class).setName("branch2").setAutoCheckout(true).call(); insertAndAdd(remote, lines1_modified, lines2_modified, lines3_modified); RevCommit branch2Tip = commit(remote, "modified lines on branch2"); checkout(remote, "master"); remote.command(BranchCreateOp.class).setName("branch3").setAutoCheckout(true).call(); insertAndAdd(remote, points1_modified, points2_modified, points3_modified); RevCommit branch3Tip = commit(remote, "modified points on branch3"); checkout(remote, "master"); // fetch from the remote, fetching remote's branch2 to local's refs/custom/branch2 and // branch3 to refs/custom/branch3 explicitly FetchOp fetch = fetchOp().setAutofetchTags(false); final String refSpec = "refs/heads/branch2:refs/custom/branch2;refs/heads/branch3:refs/custom/branch3;"; Remote singleRefOrigin = origin.fetch(refSpec); TransferSummary summary = fetch.addRemote(singleRefOrigin).call(); assertFalse(getRef(local, "refs/heads/branch2").isPresent()); assertFalse(getRef(local, "refs/heads/branch3").isPresent()); assertFalse(getRef(local, "refs/remotes/origin/branch2").isPresent()); assertFalse(getRef(local, "refs/remotes/origin/branch3").isPresent()); assertTrue(getRef(local, "refs/custom/branch2").isPresent()); assertTrue(getRef(local, "refs/custom/branch2").isPresent()); assertEquals(branch2Tip.getId(), getRef(local, "refs/custom/branch2").get().getObjectId()); assertEquals(branch3Tip.getId(), getRef(local, "refs/custom/branch3").get().getObjectId()); assertEquals(1, summary.getRefDiffs().size()); assertTrue(summary.getRefDiffs().containsKey(origin.getFetchURL())); assertEquals(2, summary.getRefDiffs().get(origin.getFetchURL()).size()); TestSupport.verifyRepositoryContents(local, "refs/custom/branch2", "refs/custom/branch3"); }
fetch.addRemote("origin").setAllRemotes(true).call();
fetch.addRemote("origin").setAll(true).call();