private static final StringBuilder formatFetchResult(TransferSummary fr) { Map<String, Collection<RefDiff>> refs = fr.getRefDiffs(); StringBuilder sb = new StringBuilder(); if (refs.isEmpty()) { sb.append("already up to date"); } else { for (Iterator<Entry<String, Collection<RefDiff>>> it = refs.entrySet().iterator(); it.hasNext(); ) { Entry<String, Collection<RefDiff>> entry = it.next(); String remoteUrl = entry.getKey(); Collection<RefDiff> changedRefs = entry.getValue(); sb.append(" From ").append(remoteUrl).append(": ["); print(changedRefs, sb); sb.append("]"); } } return sb; }
@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()); }
private TransferSummary callInternal(IRemoteRepo remoteRepo) { final Remote remote = this.remote; @Nullable String localRefSpec; @Nullable String remoteRefSpec; boolean force; TransferSummary result = new TransferSummary(); for (TransferableRef ref : this.refsToPush) { localRefSpec = ref.getLocalRef(); remoteRefSpec = ref.getRemoteRef(); force = ref.isForceUpdate(); if (ref.isDelete()) { Optional<Ref> deleted = remoteRepo.deleteRef(remoteRefSpec); if (deleted.isPresent()) { RefDiff deleteResult = RefDiff.added(deleted.get()); result.add(remote.getPushURL(), deleteResult); } } else { Optional<Ref> localRef = refParse(localRefSpec); checkState(localRef.isPresent(), "RefSpec %s does not exist", localRefSpec); Optional<Ref> newRef = push(remoteRepo, remote, localRef.get(), remoteRefSpec); if (newRef.isPresent()) { RefDiff deleteResult = new RefDiff(localRef.get(), newRef.get()); result.add(remote.getPushURL(), deleteResult); } } } return result; }
@Override public void write(ResponseWriter out) throws Exception { out.start(); out.writeElement("Push", "Success"); out.writeElement("dataPushed", String.valueOf(!dataPushed.isEmpty())); out.finish(); } });
protected @Override TransferSummary _call() { final Remote remote = resolveRemote(); final Repository localRepo = repository(); final ProgressListener progress = getProgressListener(); final TransferSummary summary = new TransferSummary(); try (IRemoteRepo remoteRepo = openRemote(remote)) { final Set<Ref> remoteRefs = getRemoteRefs(remoteRepo); final List<PushReq> pushRequests = parseRequests(remoteRefs); final PackRequest request = prepareRequest(pushRequests, remoteRefs); List<RefDiff> dataTransferResults = localRepo.command(SendPackOp.class)// .setRequest(request)// .setTarget(remoteRepo)// .setProgressListener(progress)// .call(); // the remote has all the objects needed for the refs to be updated to the objectids // they point to List<RefDiff> updateResults = updateRemoteRefs(pushRequests, remoteRefs, remoteRepo); summary.addAll(remote.getPushURL(), updateResults); } return summary; }
if (dataPushed.isEmpty()) { cli.getConsole().println("Nothing to push.");
protected @Override TransferSummary _call() { final Remote remote = resolveRemote(); final Repository localRepo = repository(); final ProgressListener progress = getProgressListener(); final TransferSummary summary = new TransferSummary(); try (IRemoteRepo remoteRepo = openRemote(remote)) { final Set<Ref> remoteRefs = getRemoteRefs(remoteRepo); final List<PushReq> pushRequests = parseRequests(remoteRefs); final PackRequest request = prepareRequest(pushRequests, remoteRefs); request.syncIndexes(pushIndexes); List<RefDiff> dataTransferResults = localRepo.command(SendPackOp.class)// .setRequest(request)// .setTarget(remoteRepo)// .setProgressListener(progress)// .call(); // the remote has all the objects needed for the refs to be updated to the objectids // they point to List<RefDiff> updateResults = updateRemoteRefs(pushRequests, remoteRefs, remoteRepo); summary.addAll(remote.getPushURL(), updateResults); } return summary; }
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; }
@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()); }
if (dataPushed.isEmpty()) { cli.getConsole().println("Nothing to push.");
TransferSummary result = new TransferSummary(); if (!needUpdate.isEmpty()) { String fetchURL = remote.getFetchURL(); result.addAll(fetchURL, needUpdate);
private TransferSummary callInternal(IRemoteRepo remoteRepo) { final Remote remote = this.remote; @Nullable String localRefSpec; @Nullable String remoteRefSpec; boolean force; TransferSummary sendPackResult = new TransferSummary(); for (TransferableRef ref : this.refsToPush) { localRefSpec = ref.getLocalRef(); remoteRefSpec = ref.getRemoteRef(); force = ref.isForceUpdate(); if (ref.isDelete()) { Optional<Ref> deleted = remoteRepo.deleteRef(remoteRefSpec); if (deleted.isPresent()) { RefDiff deleteResult = RefDiff.added(deleted.get()); sendPackResult.add(remote.getPushURL(), deleteResult); } } else { Optional<Ref> localRef = refParse(localRefSpec); checkState(localRef.isPresent(), "RefSpec %s does not exist", localRefSpec); Optional<Ref> newRef = push(remoteRepo, remote, localRef.get(), remoteRefSpec); if (newRef.isPresent()) { RefDiff deleteResult = new RefDiff(localRef.get(), newRef.get()); sendPackResult.add(remote.getPushURL(), deleteResult); } } } return sendPackResult; }
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; }
if (dataPushed.isEmpty()) { cli.getConsole().println("Nothing to push.");
progress.started(); TransferSummary result = new TransferSummary(); result.addAll(remote.getFetchURL(), Lists.newArrayList(remoteRemoteRefs));
private void verifyFetchedIndexes(AbstractGeoGigOp<?> command, TransferSummary ts) { Set<String> remotes = ts.getRefDiffs().keySet(); for (String remoteURI : remotes) { FetchOp op = (FetchOp) command; Remote remoteObj = op.getRemotes().stream() .filter(r -> remoteURI.equals(r.getFetchURL())).findFirst().get(); String fetchURL = remoteObj.getFetchURL(); Repository remote = (Repository) command.getClientData().get(fetchURL); Collection<RefDiff> collection = ts.getRefDiffs().get(remoteURI); for (RefDiff rd : collection) { if (rd.isDelete()) { continue; } Ref newRef = rd.getNewRef(); Repository local = command.context().repository(); String localRef = newRef.getName(); String remoteBranch = remoteObj.mapToRemote(localRef).orElse(null); verifyClonedIndexes(local, remote, Optional.of(localRef), Optional.of(remoteBranch)); } } }
@Test public void testNothingToPush() throws Exception { Optional<Ref> master = getRef(remoteRepo, "master"); Optional<Ref> branch = getRef(remoteRepo, "Branch1"); // Push the commit PushOp push = pushOp(); TransferSummary summary = push.setProgressListener(SIMPLE_PROGRESS).call(); assertTrue(summary.isEmpty()); assertEquals(master, getRef(remoteRepo, "master")); assertEquals(branch, getRef(remoteRepo, "Branch1")); }
TransferSummary transferSummary = new TransferSummary(); if (!needUpdate.isEmpty()) { String fetchURL = remote.getFetchURL(); transferSummary.addAll(fetchURL, needUpdate);
protected void assertSummary(TransferSummary result, String remoteURL, Optional<Ref> before, Optional<Ref> after) { assertNotNull(result); Collection<RefDiff> diffs = result.getRefDiffs().get(remoteURL); assertNotNull(diffs); String name = before.or(after).get().getName(); RefDiff diff = Maps.uniqueIndex(diffs, (d) -> d.oldRef().or(d.newRef()).get().getName()) .get(name); assertNotNull(diff); assertEquals(before, diff.oldRef()); assertEquals(after, diff.newRef()); }
@Test public void testNothingToPush() throws Exception { Optional<Ref> master = getRef(remoteRepo, "master"); Optional<Ref> branch = getRef(remoteRepo, "Branch1"); // Push the commit PushOp push = pushOp(); TransferSummary summary = push.setProgressListener(SIMPLE_PROGRESS).call(); assertTrue(summary.isEmpty()); assertEquals(master, getRef(remoteRepo, "master")); assertEquals(branch, getRef(remoteRepo, "Branch1")); }