Example usage for org.eclipse.jgit.transport RemoteRefUpdate getExpectedOldObjectId

List of usage examples for org.eclipse.jgit.transport RemoteRefUpdate getExpectedOldObjectId

Introduction

In this page you can find the example usage for org.eclipse.jgit.transport RemoteRefUpdate getExpectedOldObjectId.

Prototype

public ObjectId getExpectedOldObjectId() 

Source Link

Document

Get expected old object id

Usage

From source file:org.eclipse.egit.core.op.PushOperationResult.java

License:Open Source License

/**
 * Derive push operation specification from this push operation result.
 * <p>//from  w  ww  .j a  v  a 2  s.com
 * Specification is created basing on URIs of remote repositories in this
 * result that completed without connection errors, and remote ref updates
 * from push results.
 * <p>
 * This method is targeted to provide support for 2-stage push, where first
 * operation is dry run for user confirmation and second one is a real
 * operation.
 *
 * @param requireUnchanged
 *            if true, newly created copies of remote ref updates have
 *            expected old object id set to previously advertised ref value
 *            (remote ref won't be updated if it change in the mean time),
 *            if false, newly create copies of remote ref updates have
 *            expected object id set up as in this result source
 *            specification.
 * @return derived specification for another push operation.
 * @throws IOException
 *             when some previously locally available source ref is not
 *             available anymore, or some error occurred during creation
 *             locally tracking ref update.
 *
 */
public PushOperationSpecification deriveSpecification(final boolean requireUnchanged) throws IOException {
    final PushOperationSpecification spec = new PushOperationSpecification();
    for (final URIish uri : getURIs()) {
        final PushResult pr = getPushResult(uri);
        if (pr == null)
            continue;

        final Collection<RemoteRefUpdate> oldUpdates = pr.getRemoteUpdates();
        final ArrayList<RemoteRefUpdate> newUpdates = new ArrayList<RemoteRefUpdate>(oldUpdates.size());
        for (final RemoteRefUpdate rru : oldUpdates) {
            final ObjectId expectedOldObjectId;
            if (requireUnchanged) {
                final Ref advertisedRef = getPushResult(uri).getAdvertisedRef(rru.getRemoteName());
                if (advertisedRef == null)
                    expectedOldObjectId = ObjectId.zeroId();
                else
                    expectedOldObjectId = advertisedRef.getObjectId();
            } else
                expectedOldObjectId = rru.getExpectedOldObjectId();
            final RemoteRefUpdate newRru = new RemoteRefUpdate(rru, expectedOldObjectId);
            newUpdates.add(newRru);
        }
        spec.addURIRefUpdates(uri, newUpdates);
    }
    return spec;
}

From source file:org.exist.git.xquery.Push.java

License:Open Source License

@Override
public Sequence eval(Sequence[] args, Sequence contextSequence) throws XPathException {

    try {//w  ww  .j a  v  a2  s.  c o  m
        String localPath = args[0].getStringValue();
        if (!(localPath.endsWith("/")))
            localPath += File.separator;

        Git git = Git.open(new Resource(localPath), FS);

        Iterable<PushResult> answer = git.push().setCredentialsProvider(
                new UsernamePasswordCredentialsProvider(args[1].getStringValue(), args[2].getStringValue()))
                .call();

        MemTreeBuilder builder = getContext().getDocumentBuilder();

        int nodeNr = builder.startElement(PUSH, null);

        for (PushResult push : answer) {

            builder.startElement(RESULT, null);

            for (TrackingRefUpdate tracking : push.getTrackingRefUpdates()) {

                builder.startElement(TRACKING_REF_UPDATE, null);

                builder.addAttribute(REMOTE_NAME, tracking.getRemoteName());
                builder.addAttribute(LOCAL_NAME, tracking.getLocalName());

                //builder.addAttribute(FORCE_UPDATE, Boolean.toString(tracking.forceUpdate));

                builder.addAttribute(OLD_OBJECTID, tracking.getOldObjectId().name());
                builder.addAttribute(NEW_OBJECTID, tracking.getNewObjectId().name());
            }

            for (RemoteRefUpdate remote : push.getRemoteUpdates()) {

                builder.startElement(REMOTE_REF_UPDATE, null);

                builder.addAttribute(REMOTE_NAME, remote.getRemoteName());
                builder.addAttribute(STATUS, remote.getStatus().name());

                if (remote.isExpectingOldObjectId())
                    builder.addAttribute(EXPECTED_OLD_OBJECTID, remote.getExpectedOldObjectId().name());

                if (remote.getNewObjectId() != null)
                    builder.addAttribute(NEW_OBJECTID, remote.getNewObjectId().name());

                builder.addAttribute(FAST_FORWARD, Boolean.toString(remote.isFastForward()));
                builder.addAttribute(FORCE_UPDATE, Boolean.toString(remote.isForceUpdate()));

                if (remote.getMessage() != null)
                    builder.characters(remote.getMessage());

                builder.endElement();
            }
            builder.endElement();
        }

        builder.endElement();

        return builder.getDocument().getNode(nodeNr);
    } catch (Throwable e) {
        e.printStackTrace();
        throw new XPathException(this, Module.EXGIT001, e);
    }
}