Example usage for org.eclipse.jgit.transport PushConnection push

List of usage examples for org.eclipse.jgit.transport PushConnection push

Introduction

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

Prototype

void push(final ProgressMonitor monitor, final Map<String, RemoteRefUpdate> refUpdates)
        throws TransportException;

Source Link

Document

Pushes to the remote repository basing on provided 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;
    try {/*  w ww  . j ava2s.  co m*/
        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  . jav a 2  s  .  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();
        }
    }
}