Search in sources :

Example 1 with TransferableRef

use of org.locationtech.geogig.api.plumbing.SendPack.TransferableRef in project GeoGig by boundlessgeo.

the class PushOp method resolveRefs.

private List<TransferableRef> resolveRefs() {
    List<TransferableRef> refsToPush = new ArrayList<>();
    List<String> refSpecsArg = this.refSpecs;
    if (refSpecsArg.isEmpty()) {
        if (all) {
            ImmutableSet<Ref> localRefs = getLocalRefs();
            for (Ref ref : localRefs) {
                String localRef = ref.getName();
                String remoteRef = null;
                boolean forceUpdate = false;
                boolean delete = false;
                refsToPush.add(new TransferableRef(localRef, remoteRef, forceUpdate, delete));
            }
        } else {
            // push current branch
            Ref currentBranch = resolveHeadTarget();
            String localRef = currentBranch.getName();
            String remoteRef = null;
            boolean forceUpdate = false;
            boolean delete = false;
            refsToPush.add(new TransferableRef(localRef, remoteRef, forceUpdate, delete));
        }
    } else {
        for (String refspec : refSpecsArg) {
            String[] refs = refspec.split(":");
            if (refs.length == 0) {
                refs = new String[2];
                refs[0] = resolveHeadTarget().getName();
                refs[1] = null;
            } else {
                if (refs[0].startsWith("+")) {
                    refs[0] = refs[0].substring(1);
                }
                for (int i = 0; i < refs.length; i++) {
                    if (refs[i].trim().isEmpty()) {
                        refs[i] = null;
                    }
                }
            }
            checkArgument(refs.length < 3, "Invalid refspec, please use [+][<localref>][:][<remoteref>].");
            boolean force = refspec.startsWith("+");
            String localrefspec = refs[0];
            boolean delete = localrefspec == null;
            String remoterefspec = refs[refs.length == 2 ? 1 : 0];
            refsToPush.add(new TransferableRef(localrefspec, remoterefspec, force, delete));
        }
    }
    return refsToPush;
}
Also used : Ref(org.locationtech.geogig.api.Ref) SymRef(org.locationtech.geogig.api.SymRef) ForEachRef(org.locationtech.geogig.api.plumbing.ForEachRef) TransferableRef(org.locationtech.geogig.api.plumbing.SendPack.TransferableRef) TransferableRef(org.locationtech.geogig.api.plumbing.SendPack.TransferableRef) ArrayList(java.util.ArrayList)

Example 2 with TransferableRef

use of org.locationtech.geogig.api.plumbing.SendPack.TransferableRef in project GeoGig by boundlessgeo.

the class PushOp method _call.

/**
     * Executes the push operation.
     * 
     * @return {@code null}
     * @see org.locationtech.geogig.api.AbstractGeoGigOp#call()
     */
@Override
protected TransferSummary _call() {
    final String remoteName = this.remoteName == null ? "origin" : this.remoteName;
    final Remote remote = resolveRemote(remoteName);
    final List<TransferableRef> refsToPush = resolveRefs();
    SendPack sendPack = command(SendPack.class);
    sendPack.setRemote(remote);
    sendPack.setRefs(refsToPush);
    sendPack.setProgressListener(getProgressListener());
    TransferSummary result = sendPack.call();
    return result;
}
Also used : SendPack(org.locationtech.geogig.api.plumbing.SendPack) TransferableRef(org.locationtech.geogig.api.plumbing.SendPack.TransferableRef) Remote(org.locationtech.geogig.api.Remote)

Aggregations

TransferableRef (org.locationtech.geogig.api.plumbing.SendPack.TransferableRef)2 ArrayList (java.util.ArrayList)1 Ref (org.locationtech.geogig.api.Ref)1 Remote (org.locationtech.geogig.api.Remote)1 SymRef (org.locationtech.geogig.api.SymRef)1 ForEachRef (org.locationtech.geogig.api.plumbing.ForEachRef)1 SendPack (org.locationtech.geogig.api.plumbing.SendPack)1