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

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

Introduction

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

Prototype

public RemoteRefUpdate(final Repository localDb, final String srcRef, final ObjectId srcId,
        final String remoteName, final boolean forceUpdate, final String localName,
        final ObjectId expectedOldObjectId) throws IOException 

Source Link

Document

Construct remote ref update request by providing an update specification.

Usage

From source file:jetbrains.buildServer.buildTriggers.vcs.git.GitLabelingSupport.java

License:Apache License

@NotNull
private String push(@NotNull String label, @NotNull String version, @NotNull GitVcsRoot gitRoot,
        @NotNull Repository r, @NotNull Ref tagRef, @NotNull RevisionsInfo revisionsInfo)
        throws VcsException, IOException {
    long pushStart = System.currentTimeMillis();
    final Transport tn = myTransportFactory.createTransport(r, gitRoot.getRepositoryPushURL(),
            gitRoot.getAuthSettings(), myConfig.getPushTimeoutSeconds());
    PushConnection c = null;/*w ww.  j  a va 2  s .c o m*/
    try {
        c = tn.openPush();
        RemoteRefUpdate ru = new RemoteRefUpdate(r, tagRef.getName(), tagRef.getObjectId(), tagRef.getName(),
                false, null, null);
        PreparePackFunction preparePack = null;
        if (c instanceof BasePackPushConnection) {
            final RevTag tagObject = getTagObject(r, tagRef);
            if (tagObject != null) {
                preparePack = new PreparePackFunction(tagObject, revisionsInfo);
                ((BasePackPushConnection) c).setPreparePack(preparePack);
            } else {
                LOG.debug("Cannot locate the " + tagRef.getName() + " tag object, don't use pack heuristic");
            }
        }
        c.push(NullProgressMonitor.INSTANCE, Collections.singletonMap(tagRef.getName(), ru));
        LOG.info("Tag  " + label + "=" + version + " was pushed with status " + ru.getStatus() + " for "
                + gitRoot.debugInfo() + " in " + (System.currentTimeMillis() - pushStart) + "ms"
                + (preparePack != null ? " (prepare pack " + preparePack.getPreparePackDurationMillis() + "ms)"
                        : ""));
        switch (ru.getStatus()) {
        case UP_TO_DATE:
        case OK:
            break;
        default:
            String msg = ru.getMessage();
            throw new VcsException("The remote '" + label + "' tag was not created" + ", status: "
                    + ru.getStatus() + (!isEmpty(msg) ? ", message: " + msg : ""));
        }
        return label;
    } finally {
        if (c != null)
            c.close();
        tn.close();
    }
}

From source file:jetbrains.buildServer.buildTriggers.vcs.git.GitMergeSupport.java

License:Apache License

@NotNull
private MergeResult doMerge(@NotNull OperationContext context, @NotNull GitVcsRoot gitRoot,
        @NotNull Repository db, @NotNull String srcRevision, @NotNull String dstBranch, @NotNull String message,
        @NotNull MergeOptions options) throws IOException, VcsException {
    RefSpec spec = new RefSpec().setSource(GitUtils.expandRef(dstBranch))
            .setDestination(GitUtils.expandRef(dstBranch)).setForceUpdate(true);
    myCommitLoader.fetch(db, gitRoot.getRepositoryFetchURL(), asList(spec),
            new FetchSettings(gitRoot.getAuthSettings()));
    RevCommit srcCommit = myCommitLoader.findCommit(db, srcRevision);
    if (srcCommit == null)
        srcCommit = myCommitLoader.loadCommit(context, gitRoot, srcRevision);

    Ref dstRef = db.getRef(dstBranch);
    RevCommit dstBranchLastCommit = myCommitLoader.loadCommit(context, gitRoot, dstRef.getObjectId().name());
    ObjectId commitId;/*  www.ja  v a 2s. co m*/
    try {
        commitId = mergeCommits(gitRoot, db, srcCommit, dstBranchLastCommit, message, options);
    } catch (MergeFailedException e) {
        LOG.debug("Merge error, root " + gitRoot + ", revision " + srcRevision + ", destination " + dstBranch,
                e);
        return MergeResult.createMergeError(e.getConflicts());
    }

    synchronized (myRepositoryManager.getWriteLock(gitRoot.getRepositoryDir())) {
        final Transport tn = myTransportFactory.createTransport(db, gitRoot.getRepositoryPushURL(),
                gitRoot.getAuthSettings(), myPluginConfig.getPushTimeoutSeconds());
        try {
            final PushConnection c = tn.openPush();
            try {
                RemoteRefUpdate ru = new RemoteRefUpdate(db, null, commitId, GitUtils.expandRef(dstBranch),
                        false, null, dstBranchLastCommit);
                c.push(NullProgressMonitor.INSTANCE,
                        Collections.singletonMap(GitUtils.expandRef(dstBranch), ru));
                switch (ru.getStatus()) {
                case UP_TO_DATE:
                case OK:
                    return MergeResult.createMergeSuccessResult();
                default:
                    return MergeResult.createMergeError("Push failed, " + ru.getMessage());
                }
            } finally {
                c.close();
            }
        } catch (IOException e) {
            LOG.debug("Error while pushing a merge commit, root " + gitRoot + ", revision " + srcRevision
                    + ", destination " + dstBranch, e);
            throw e;
        } finally {
            tn.close();
        }
    }
}